-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
105 lines (87 loc) · 2.5 KB
/
build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { execSync } from "child_process";
import {
readFileSync,
writeFileSync,
} from "fs";
execSync("rm -rf boring-avatars", { stdio: "inherit" });
execSync("git clone https://github.com/boringdesigners/boring-avatars", {
stdio: "inherit",
});
{
const packageJson = JSON.parse(readFileSync("boring-avatars/package.json"));
packageJson.name = "boring-avatars-esm";
packageJson.repository = "https://github.com/lu-zen/boring-avatars-esm";
packageJson.type = "module";
delete packageJson.main;
packageJson.devDependencies["vite"] = "^4.3.2";
packageJson.devDependencies["@vitejs/plugin-react"] = "^4.0.0";
packageJson.devDependencies["esbuild"] = "^0.17.19";
packageJson.scripts["build"] = "vite build";
delete packageJson.exports;
packageJson.files = ["dist/*", "index.d.ts"];
packageJson.exports = {
".": {
import: "./dist/boring-avatars-esm.js",
require: "./dist/boring-avatars-esm.cjs",
types: "./index.d.ts",
},
};
console.log("package.json", packageJson);
writeFileSync(
"boring-avatars/package.json",
JSON.stringify(packageJson, undefined, "\t"),
);
}
{
const viteConfigContent = `
import { resolve } from 'path'
import { defineConfig } from 'vite'
export default defineConfig({
build: {
copyPublicDir: false,
sourcemap: true,
minify: true,
emptyOutDir: true,
lib: {
entry: resolve(__dirname, 'src/lib/components/avatar.js'),
formats: ['es', 'cjs'],
},
rollupOptions: {
external: ['react', 'react-dom'],
},
},
esbuild: {
loader: "jsx",
include: /src\\/.*\\.jsx?$/,
exclude: [],
},
optimizeDeps: {
esbuildOptions: {
plugins: [
{
name: "load-js-files-as-jsx",
setup(build) {
build.onLoad({ filter: /src\\/.*\\.js$/ }, async (args) => ({
loader: { ".js": "jsx" },
contents: await fs.readFile(args.path, "utf8"),
}));
},
},
],
},
},
})
`;
writeFileSync("boring-avatars/vite.config.js", viteConfigContent, {
encoding: "utf-8",
});
}
{
const typing = readFileSync("boring-avatars/index.d.ts", "utf-8").replace(
'module "boring-avatars"',
'module "boring-avatars-esm"',
);
writeFileSync("boring-avatars/index.d.ts", typing);
}
execSync("npm install", { cwd: "boring-avatars", stdio: "inherit" });
execSync("npm run build", { cwd: "boring-avatars", stdio: "inherit" });