makepack 1.7.15 → 1.7.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +365 -365
- package/package.json +62 -62
- package/src/actions/build/bundler.js +220 -132
- package/src/actions/build/index.js +79 -75
- package/src/actions/create/files/gitignore.js +9 -9
- package/src/actions/create/files/main.js +36 -36
- package/src/actions/create/files/package-json.js +49 -49
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +50 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +50 -50
- package/src/actions/create/files/readme.md.js +62 -62
- package/src/actions/create/files/tsconfig.js +33 -33
- package/src/actions/create/index.js +95 -95
- package/src/actions/create/makeFiles.js +65 -65
- package/src/actions/release/index.js +19 -19
- package/src/actions/start/index.js +215 -215
- package/src/actions/start/vite.js +72 -72
- package/src/helpers.js +120 -120
- package/src/index.js +39 -39
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "makepack",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
|
-
"categories": [
|
|
7
|
-
"Other"
|
|
8
|
-
],
|
|
9
|
-
"author": {
|
|
10
|
-
"name": "Devnax",
|
|
11
|
-
"email": "devnaxrul@gmail.com"
|
|
12
|
-
},
|
|
13
|
-
"bin": "./src/index.js",
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "https://github.com/devnax/makepack"
|
|
17
|
-
},
|
|
18
|
-
"bugs": {
|
|
19
|
-
"url": "https://github.com/devnax/makepack/issues"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/devnax/makepack#readme",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"start": "node ./src/index.js start",
|
|
24
|
-
"create": "node ./src/index.js create",
|
|
25
|
-
"build": "node ./src/index.js build"
|
|
26
|
-
},
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"@rollup/plugin-commonjs": "^28.0.5",
|
|
29
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
30
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
33
|
-
"@types/fs-extra": "^11.0.4",
|
|
34
|
-
"chokidar": "^4.0.3",
|
|
35
|
-
"commander": "^12.1.0",
|
|
36
|
-
"esbuild": "^0.25.5",
|
|
37
|
-
"express": "^4.21.1",
|
|
38
|
-
"fs-extra": "^11.2.0",
|
|
39
|
-
"inquirer": "^12.1.0",
|
|
40
|
-
"lodash.debounce": "^4.0.8",
|
|
41
|
-
"madge": "^8.0.0",
|
|
42
|
-
"ora": "^8.1.1",
|
|
43
|
-
"react": "^19.1.0",
|
|
44
|
-
"react-dom": "^19.0.0",
|
|
45
|
-
"rollup": "^4.43.0",
|
|
46
|
-
"rollup-plugin-dts": "^6.2.1",
|
|
47
|
-
"tslib": "^2.8.1",
|
|
48
|
-
"vite": "^6.0.2"
|
|
49
|
-
},
|
|
50
|
-
"keywords": [
|
|
51
|
-
"CLI",
|
|
52
|
-
"npm",
|
|
53
|
-
"library",
|
|
54
|
-
"JavaScript",
|
|
55
|
-
"TypeScript",
|
|
56
|
-
"React",
|
|
57
|
-
"npm-package"
|
|
58
|
-
],
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"@types/react": "^19.1.8",
|
|
61
|
-
"typescript": "^5.8.3"
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "makepack",
|
|
3
|
+
"version": "1.7.17",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
|
+
"categories": [
|
|
7
|
+
"Other"
|
|
8
|
+
],
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "Devnax",
|
|
11
|
+
"email": "devnaxrul@gmail.com"
|
|
12
|
+
},
|
|
13
|
+
"bin": "./src/index.js",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/devnax/makepack"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/devnax/makepack/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/devnax/makepack#readme",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "node ./src/index.js start",
|
|
24
|
+
"create": "node ./src/index.js create",
|
|
25
|
+
"build": "node ./src/index.js build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@rollup/plugin-commonjs": "^28.0.5",
|
|
29
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
30
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
33
|
+
"@types/fs-extra": "^11.0.4",
|
|
34
|
+
"chokidar": "^4.0.3",
|
|
35
|
+
"commander": "^12.1.0",
|
|
36
|
+
"esbuild": "^0.25.5",
|
|
37
|
+
"express": "^4.21.1",
|
|
38
|
+
"fs-extra": "^11.2.0",
|
|
39
|
+
"inquirer": "^12.1.0",
|
|
40
|
+
"lodash.debounce": "^4.0.8",
|
|
41
|
+
"madge": "^8.0.0",
|
|
42
|
+
"ora": "^8.1.1",
|
|
43
|
+
"react": "^19.1.0",
|
|
44
|
+
"react-dom": "^19.0.0",
|
|
45
|
+
"rollup": "^4.43.0",
|
|
46
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
47
|
+
"tslib": "^2.8.1",
|
|
48
|
+
"vite": "^6.0.2"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"CLI",
|
|
52
|
+
"npm",
|
|
53
|
+
"library",
|
|
54
|
+
"JavaScript",
|
|
55
|
+
"TypeScript",
|
|
56
|
+
"React",
|
|
57
|
+
"npm-package"
|
|
58
|
+
],
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/react": "^19.1.8",
|
|
61
|
+
"typescript": "^5.8.3"
|
|
62
|
+
}
|
|
63
63
|
}
|
|
@@ -1,132 +1,220 @@
|
|
|
1
|
-
import { rollup } from "rollup";
|
|
2
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
-
import typescript from "@rollup/plugin-typescript";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
import { rollup } from "rollup";
|
|
2
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
+
import typescript from "@rollup/plugin-typescript";
|
|
5
|
+
import json from "@rollup/plugin-json";
|
|
6
|
+
import terser from "@rollup/plugin-terser";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import fs from "fs/promises";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
|
|
11
|
+
|
|
12
|
+
const MAX_DIR_CONCURRENCY = 16;
|
|
13
|
+
const MAX_FILE_COPY_CONCURRENCY = 32;
|
|
14
|
+
|
|
15
|
+
// --------------------- Batched multi-entry collector ---------------------
|
|
16
|
+
async function getEntriesBatch(root) {
|
|
17
|
+
const entries = {};
|
|
18
|
+
const dirs = [root];
|
|
19
|
+
|
|
20
|
+
async function worker() {
|
|
21
|
+
while (dirs.length) {
|
|
22
|
+
const dir = dirs.shift();
|
|
23
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
24
|
+
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
const full = path.join(dir, item.name);
|
|
27
|
+
if (item.isDirectory()) dirs.push(full);
|
|
28
|
+
else if (/\.(ts|tsx|js|jsx)$/.test(item.name)) {
|
|
29
|
+
const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
30
|
+
entries[name] = full;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const workers = Array.from({ length: MAX_DIR_CONCURRENCY }, () => worker());
|
|
37
|
+
await Promise.all(workers);
|
|
38
|
+
|
|
39
|
+
return entries;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --------------------- Batched parallel asset copy ---------------------
|
|
43
|
+
function isCodeFile(filename) {
|
|
44
|
+
return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isSkippedDir(name) {
|
|
48
|
+
return name === "node_modules" || name === ".git" || name === ".next";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function copyAssetsBatched(rootdir, outdir) {
|
|
52
|
+
const queue = [];
|
|
53
|
+
|
|
54
|
+
async function walk(dir) {
|
|
55
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
56
|
+
for (const item of items) {
|
|
57
|
+
const full = path.join(dir, item.name);
|
|
58
|
+
const rel = path.relative(rootdir, full);
|
|
59
|
+
if (rel.split(path.sep).some(p => isSkippedDir(p))) continue;
|
|
60
|
+
|
|
61
|
+
if (item.isDirectory()) await walk(full);
|
|
62
|
+
else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await walk(rootdir);
|
|
67
|
+
|
|
68
|
+
async function worker() {
|
|
69
|
+
while (queue.length) {
|
|
70
|
+
const { src, rel } = queue.shift();
|
|
71
|
+
const dest = path.join(outdir, rel);
|
|
72
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
73
|
+
await fs.copyFile(src, dest);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const workers = Array.from({ length: MAX_FILE_COPY_CONCURRENCY }, () => worker());
|
|
78
|
+
await Promise.all(workers);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// --------------------- Generate .d.ts using TS Compiler API ---------------------
|
|
82
|
+
async function generateDeclarations(rootDir, outDir) {
|
|
83
|
+
const tsFiles = [];
|
|
84
|
+
|
|
85
|
+
async function walk(dir) {
|
|
86
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
87
|
+
for (const item of items) {
|
|
88
|
+
const full = path.join(dir, item.name);
|
|
89
|
+
if (item.isDirectory()) await walk(full);
|
|
90
|
+
else if (/\.(ts|tsx)$/.test(item.name)) tsFiles.push(full);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await walk(rootDir);
|
|
95
|
+
|
|
96
|
+
if (!tsFiles.length) return;
|
|
97
|
+
|
|
98
|
+
const options = {
|
|
99
|
+
declaration: true,
|
|
100
|
+
emitDeclarationOnly: true,
|
|
101
|
+
outDir: outDir,
|
|
102
|
+
rootDir: rootDir,
|
|
103
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
104
|
+
target: ts.ScriptTarget.ES2017,
|
|
105
|
+
module: ts.ModuleKind.ESNext,
|
|
106
|
+
esModuleInterop: true,
|
|
107
|
+
skipLibCheck: true,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const program = ts.createProgram(tsFiles, options);
|
|
111
|
+
program.emit();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// --------------------- Main Bundler ---------------------
|
|
115
|
+
async function bundler(args, spinner) {
|
|
116
|
+
const rootdir = args.rootdir;
|
|
117
|
+
const outdir = args.outdir;
|
|
118
|
+
|
|
119
|
+
const entries = await getEntriesBatch(rootdir);
|
|
120
|
+
const isTs = Object.values(entries).some(f => f.endsWith(".ts") || f.endsWith(".tsx"));
|
|
121
|
+
|
|
122
|
+
const viteConfig = await loadViteConfig();
|
|
123
|
+
const rollupConfig = await loadRollupConfig();
|
|
124
|
+
const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
|
|
125
|
+
Object.assign(rollupConfig || {}, viteRollupConfig);
|
|
126
|
+
|
|
127
|
+
const config = {
|
|
128
|
+
...rollupConfig,
|
|
129
|
+
input: { ...entries },
|
|
130
|
+
external: id => {
|
|
131
|
+
if (rollupConfig && typeof rollupConfig.external === "function") {
|
|
132
|
+
if (rollupConfig.external(id)) return true;
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(rollupConfig && rollupConfig.external)) {
|
|
135
|
+
if (rollupConfig.external.includes(id)) return true;
|
|
136
|
+
}
|
|
137
|
+
return !id.startsWith(".") && !id.startsWith("/") && !/^[A-Za-z]:\\/.test(id);
|
|
138
|
+
},
|
|
139
|
+
plugins: [
|
|
140
|
+
json(),
|
|
141
|
+
resolve({ extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".mjs", ".cjs"] }),
|
|
142
|
+
commonjs(),
|
|
143
|
+
typescript({
|
|
144
|
+
tsconfig: false,
|
|
145
|
+
target: "ES2017",
|
|
146
|
+
module: "ESNext",
|
|
147
|
+
jsx: "react-jsx",
|
|
148
|
+
moduleResolution: "node",
|
|
149
|
+
esModuleInterop: true,
|
|
150
|
+
strict: true,
|
|
151
|
+
importHelpers: true,
|
|
152
|
+
skipLibCheck: true,
|
|
153
|
+
forceConsistentCasingInFileNames: true,
|
|
154
|
+
declaration: false,
|
|
155
|
+
emitDeclarationOnly: false,
|
|
156
|
+
rootDir: path.resolve(process.cwd(), rootdir)
|
|
157
|
+
}),
|
|
158
|
+
args.minify ? terser() : null,
|
|
159
|
+
...(rollupConfig?.plugins || [])
|
|
160
|
+
]
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const bundle = await rollup(config);
|
|
164
|
+
|
|
165
|
+
// --------------------- Determine output formats ---------------------
|
|
166
|
+
const outputs = [];
|
|
167
|
+
|
|
168
|
+
if (!args.format || args.format === "both") {
|
|
169
|
+
outputs.push({
|
|
170
|
+
dir: outdir,
|
|
171
|
+
format: "esm",
|
|
172
|
+
sourcemap: args.sourcemap,
|
|
173
|
+
preserveModules: true,
|
|
174
|
+
preserveModulesRoot: rootdir,
|
|
175
|
+
entryFileNames: "[name].mjs"
|
|
176
|
+
});
|
|
177
|
+
outputs.push({
|
|
178
|
+
dir: outdir,
|
|
179
|
+
format: "cjs",
|
|
180
|
+
sourcemap: args.sourcemap,
|
|
181
|
+
preserveModules: true,
|
|
182
|
+
preserveModulesRoot: rootdir,
|
|
183
|
+
entryFileNames: "[name].cjs"
|
|
184
|
+
});
|
|
185
|
+
} else if (args.format === "esm" || args.format === "cjs") {
|
|
186
|
+
outputs.push({
|
|
187
|
+
dir: outdir,
|
|
188
|
+
format: args.format,
|
|
189
|
+
sourcemap: args.sourcemap,
|
|
190
|
+
preserveModules: true,
|
|
191
|
+
preserveModulesRoot: rootdir,
|
|
192
|
+
entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs"
|
|
193
|
+
});
|
|
194
|
+
} else if (args.format === "iife" || args.format === "umd") {
|
|
195
|
+
outputs.push({
|
|
196
|
+
dir: outdir,
|
|
197
|
+
format: args.format,
|
|
198
|
+
name: args.name || "Bundle",
|
|
199
|
+
sourcemap: args.sourcemap,
|
|
200
|
+
entryFileNames: "[name].js"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
for (const output of outputs) {
|
|
205
|
+
await bundle.write(output);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
await bundle.close();
|
|
209
|
+
|
|
210
|
+
// --------------------- Copy assets ---------------------
|
|
211
|
+
await copyAssetsBatched(rootdir, outdir);
|
|
212
|
+
|
|
213
|
+
// --------------------- Generate TypeScript declarations ---------------------
|
|
214
|
+
if (isTs && args.declaration) {
|
|
215
|
+
spinner.text = "📄 Generating TypeScript declarations programmatically...";
|
|
216
|
+
await generateDeclarations(rootdir, outdir);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export default bundler;
|
|
@@ -1,75 +1,79 @@
|
|
|
1
|
-
import fs from 'fs-extra'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import ora from 'ora'
|
|
4
|
-
import { concolor, logger } from '../../helpers.js'
|
|
5
|
-
import bundler from './bundler.js'
|
|
6
|
-
|
|
7
|
-
const build = async (args) => {
|
|
8
|
-
/*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
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
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import { concolor, logger } from '../../helpers.js';
|
|
5
|
+
import bundler from './bundler.js';
|
|
6
|
+
|
|
7
|
+
const build = async (args) => {
|
|
8
|
+
/*
|
|
9
|
+
args options:
|
|
10
|
+
--format=both
|
|
11
|
+
--bundle=true
|
|
12
|
+
--minify=false
|
|
13
|
+
--sourcemap=true
|
|
14
|
+
--declaration=true
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Convert string "true"/"false" to boolean
|
|
18
|
+
const beBool = (f) =>
|
|
19
|
+
typeof args[f] === 'string' ? args[f].toLowerCase() === 'true' : !!args[f];
|
|
20
|
+
|
|
21
|
+
const outdir = path.join(process.cwd(), '.mpack');
|
|
22
|
+
const rootdir = path.join(process.cwd(), 'src');
|
|
23
|
+
|
|
24
|
+
args = {
|
|
25
|
+
format: args.format || 'both',
|
|
26
|
+
bundle: beBool('bundle'),
|
|
27
|
+
minify: beBool('minify'),
|
|
28
|
+
sourcemap: beBool('sourcemap'),
|
|
29
|
+
declaration: beBool('declaration'),
|
|
30
|
+
outdir,
|
|
31
|
+
rootdir,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const spinner = ora('✨ Building your package...\n').start();
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
// Remove old build folder
|
|
38
|
+
await fs.remove(outdir);
|
|
39
|
+
await fs.mkdirp(outdir);
|
|
40
|
+
|
|
41
|
+
// Run bundler
|
|
42
|
+
await bundler(args, spinner);
|
|
43
|
+
|
|
44
|
+
spinner.text = '📦 Copying package.json and readme.md files...';
|
|
45
|
+
|
|
46
|
+
// Copy package.json
|
|
47
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
48
|
+
if (await fs.pathExists(pkgPath)) {
|
|
49
|
+
const pkgjson = await fs.readJson(pkgPath);
|
|
50
|
+
delete pkgjson.scripts;
|
|
51
|
+
delete pkgjson.type;
|
|
52
|
+
await fs.writeJson(path.join(outdir, 'package.json'), pkgjson, { spaces: 2 });
|
|
53
|
+
} else {
|
|
54
|
+
spinner.fail(concolor.red('package.json not found!'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Copy readme.md if exists
|
|
59
|
+
const readmePath = path.join(process.cwd(), 'readme.md');
|
|
60
|
+
if (await fs.pathExists(readmePath)) {
|
|
61
|
+
await fs.copy(readmePath, path.join(outdir, 'readme.md'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
spinner.succeed(concolor.bold(concolor.green('Build successfully completed!\n')));
|
|
65
|
+
console.log(concolor.bold('To publish your package, run:'));
|
|
66
|
+
console.log(
|
|
67
|
+
`${concolor.yellow('`npm run release`')} or navigate to \`.mpack\` and run: ${concolor.yellow(
|
|
68
|
+
'`npm publish`\n'
|
|
69
|
+
)}`
|
|
70
|
+
);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
spinner.fail(concolor.red('Build failed!'));
|
|
73
|
+
logger.error(err);
|
|
74
|
+
} finally {
|
|
75
|
+
spinner.stop();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default build;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export default async () => {
|
|
3
|
-
return {
|
|
4
|
-
content: `
|
|
5
|
-
node_modules
|
|
6
|
-
.mpack
|
|
7
|
-
`,
|
|
8
|
-
filename: ".gitignore"
|
|
9
|
-
}
|
|
1
|
+
|
|
2
|
+
export default async () => {
|
|
3
|
+
return {
|
|
4
|
+
content: `
|
|
5
|
+
node_modules
|
|
6
|
+
.mpack
|
|
7
|
+
`,
|
|
8
|
+
filename: ".gitignore"
|
|
9
|
+
}
|
|
10
10
|
}
|