create-pkgbld 1.4.6 → 1.6.0
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/dist/index.cjs +194 -133
- package/dist/index.mjs +194 -133
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,6 @@ var userName = require('git-user-name');
|
|
|
8
8
|
var gitConfig = require('parse-git-config');
|
|
9
9
|
var cleye = require('cleye');
|
|
10
10
|
var kleur = require('kleur');
|
|
11
|
-
require('typia');
|
|
12
11
|
var stringArgv = require('string-argv');
|
|
13
12
|
var childProcess = require('node:child_process');
|
|
14
13
|
var util = require('node:util');
|
|
@@ -19,6 +18,196 @@ async function getGitRoot() {
|
|
|
19
18
|
return stdout.trim();
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
function isPackageJson(value) {
|
|
22
|
+
return (input => {
|
|
23
|
+
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io3(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io3(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io3(input.peerDependencies));
|
|
24
|
+
const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
|
|
25
|
+
const $io2 = input => Object.keys(input).every(key => {
|
|
26
|
+
const value = input[key];
|
|
27
|
+
if (undefined === value)
|
|
28
|
+
return true;
|
|
29
|
+
if (RegExp(/(.*)/).test(key))
|
|
30
|
+
return "string" === typeof value;
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
const $io3 = input => Object.keys(input).every(key => {
|
|
34
|
+
const value = input[key];
|
|
35
|
+
if (undefined === value)
|
|
36
|
+
return true;
|
|
37
|
+
if (RegExp(/(.*)/).test(key))
|
|
38
|
+
return "string" === typeof value;
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
return "object" === typeof input && null !== input && false === Array.isArray(input) && $io0(input);
|
|
42
|
+
})(value);
|
|
43
|
+
}
|
|
44
|
+
function CommaSeparatedString(value) {
|
|
45
|
+
return value.split(',').map((arg) => arg.trim());
|
|
46
|
+
}
|
|
47
|
+
function CommaSeparatedStringOrBoolean(value) {
|
|
48
|
+
if (typeof value === 'boolean') {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return CommaSeparatedString(value);
|
|
55
|
+
}
|
|
56
|
+
const cliFlagsDefaults = {
|
|
57
|
+
formats: ['es', 'cjs'],
|
|
58
|
+
umdInputs: [],
|
|
59
|
+
compressFormats: ['umd'],
|
|
60
|
+
sourcemapFormats: ['umd'],
|
|
61
|
+
preprocess: [],
|
|
62
|
+
dir: 'dist',
|
|
63
|
+
sourceDir: 'src',
|
|
64
|
+
includeExternals: false,
|
|
65
|
+
eject: false,
|
|
66
|
+
noTsConfig: false,
|
|
67
|
+
noUpdatePackageJson: false,
|
|
68
|
+
commonjsPattern: '[name].cjs',
|
|
69
|
+
esPattern: '[name].mjs',
|
|
70
|
+
umdPattern: '[name].umd.js'
|
|
71
|
+
};
|
|
72
|
+
const cliFlags = {
|
|
73
|
+
umd: {
|
|
74
|
+
type: CommaSeparatedString,
|
|
75
|
+
description: 'Package subpath exports in UMD format',
|
|
76
|
+
default: cliFlagsDefaults.umdInputs
|
|
77
|
+
},
|
|
78
|
+
compress: {
|
|
79
|
+
type: CommaSeparatedString,
|
|
80
|
+
description: 'Compress formats using terser',
|
|
81
|
+
default: cliFlagsDefaults.compressFormats
|
|
82
|
+
},
|
|
83
|
+
sourcemaps: {
|
|
84
|
+
type: CommaSeparatedString,
|
|
85
|
+
description: 'Emit sourcemaps for the specified formats',
|
|
86
|
+
default: cliFlagsDefaults.sourcemapFormats
|
|
87
|
+
},
|
|
88
|
+
formats: {
|
|
89
|
+
type: CommaSeparatedString,
|
|
90
|
+
description: 'Formats to emit',
|
|
91
|
+
default: cliFlagsDefaults.formats
|
|
92
|
+
},
|
|
93
|
+
preprocess: {
|
|
94
|
+
type: CommaSeparatedString,
|
|
95
|
+
description: 'Preprocess entry points / subpath exports',
|
|
96
|
+
default: cliFlagsDefaults.preprocess
|
|
97
|
+
},
|
|
98
|
+
dir: {
|
|
99
|
+
type: String,
|
|
100
|
+
description: 'Output directory',
|
|
101
|
+
default: cliFlagsDefaults.dir
|
|
102
|
+
},
|
|
103
|
+
sourceDir: {
|
|
104
|
+
type: String,
|
|
105
|
+
description: 'Source directory',
|
|
106
|
+
default: cliFlagsDefaults.sourceDir
|
|
107
|
+
},
|
|
108
|
+
bin: {
|
|
109
|
+
type: CommaSeparatedString,
|
|
110
|
+
description: 'Executable files'
|
|
111
|
+
},
|
|
112
|
+
includeExternals: {
|
|
113
|
+
type: CommaSeparatedStringOrBoolean,
|
|
114
|
+
description: 'Include all/specified externals into result bundle(s)',
|
|
115
|
+
default: cliFlagsDefaults.includeExternals
|
|
116
|
+
},
|
|
117
|
+
eject: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
description: 'Eject config',
|
|
120
|
+
default: cliFlagsDefaults.eject
|
|
121
|
+
},
|
|
122
|
+
noTsConfig: {
|
|
123
|
+
type: Boolean,
|
|
124
|
+
description: 'Do not create / update tsconfig.json',
|
|
125
|
+
default: cliFlagsDefaults.noTsConfig
|
|
126
|
+
},
|
|
127
|
+
noUpdatePackageJson: {
|
|
128
|
+
type: Boolean,
|
|
129
|
+
description: 'Do not create / update package.json',
|
|
130
|
+
default: cliFlagsDefaults.noUpdatePackageJson
|
|
131
|
+
},
|
|
132
|
+
commonjsPattern: {
|
|
133
|
+
type: String,
|
|
134
|
+
description: 'CommonJS output file name pattern',
|
|
135
|
+
default: cliFlagsDefaults.commonjsPattern
|
|
136
|
+
},
|
|
137
|
+
esmPattern: {
|
|
138
|
+
type: String,
|
|
139
|
+
description: 'ES output file name pattern',
|
|
140
|
+
default: cliFlagsDefaults.esPattern
|
|
141
|
+
},
|
|
142
|
+
umdPattern: {
|
|
143
|
+
type: String,
|
|
144
|
+
description: 'UMD output file name pattern',
|
|
145
|
+
default: cliFlagsDefaults.umdPattern
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const packageJsonFieldsOrder = new Set([
|
|
149
|
+
'private',
|
|
150
|
+
'type',
|
|
151
|
+
'version',
|
|
152
|
+
'name',
|
|
153
|
+
'description',
|
|
154
|
+
'license',
|
|
155
|
+
'author',
|
|
156
|
+
'contributors',
|
|
157
|
+
'funding',
|
|
158
|
+
'bin',
|
|
159
|
+
'main',
|
|
160
|
+
'browser',
|
|
161
|
+
'unpkg',
|
|
162
|
+
'module',
|
|
163
|
+
'exports',
|
|
164
|
+
'imports',
|
|
165
|
+
'types',
|
|
166
|
+
'typings',
|
|
167
|
+
'files',
|
|
168
|
+
'packageManager',
|
|
169
|
+
'sideEffects',
|
|
170
|
+
'engines',
|
|
171
|
+
'os',
|
|
172
|
+
'cpu',
|
|
173
|
+
'man',
|
|
174
|
+
'directories',
|
|
175
|
+
'repository',
|
|
176
|
+
'bugs',
|
|
177
|
+
'homepage',
|
|
178
|
+
'readme',
|
|
179
|
+
'keywords',
|
|
180
|
+
'scripts',
|
|
181
|
+
'config',
|
|
182
|
+
'dependencies',
|
|
183
|
+
'devDependencies',
|
|
184
|
+
'peerDependencies',
|
|
185
|
+
'peerDependenciesMeta',
|
|
186
|
+
'bundleDependencies',
|
|
187
|
+
'bundledDependencies',
|
|
188
|
+
'optionalDependencies',
|
|
189
|
+
'overrides',
|
|
190
|
+
'publishConfig',
|
|
191
|
+
'workspaces'
|
|
192
|
+
]);
|
|
193
|
+
function processPackageJson(pkg, needTreatment, treatKey) {
|
|
194
|
+
const newPkg = {};
|
|
195
|
+
for (const key of packageJsonFieldsOrder) {
|
|
196
|
+
if (needTreatment(key)) {
|
|
197
|
+
newPkg[key] = treatKey(key);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const key in pkg) {
|
|
201
|
+
if (!packageJsonFieldsOrder.has(key)) {
|
|
202
|
+
newPkg[key] = pkg[key];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return newPkg;
|
|
206
|
+
}
|
|
207
|
+
function toFormattedJson(json) {
|
|
208
|
+
return JSON.stringify(json, null, 2) + '\n';
|
|
209
|
+
}
|
|
210
|
+
|
|
22
211
|
const done = Symbol('done');
|
|
23
212
|
const formats = ['amd', 'cjs', 'es', 'iife', 'system', 'umd'];
|
|
24
213
|
const pkgbldBinaries = ['pkgbld', 'pkgbld-internal', 'node ../pkgbld/dist/index.js'];
|
|
@@ -103,63 +292,7 @@ async function execute() {
|
|
|
103
292
|
}
|
|
104
293
|
execute();
|
|
105
294
|
function updatePackage(pkg, options) {
|
|
106
|
-
|
|
107
|
-
'private',
|
|
108
|
-
'type',
|
|
109
|
-
'version',
|
|
110
|
-
'name',
|
|
111
|
-
'description',
|
|
112
|
-
'license',
|
|
113
|
-
'author',
|
|
114
|
-
'contributors',
|
|
115
|
-
'funding',
|
|
116
|
-
'bin',
|
|
117
|
-
'main',
|
|
118
|
-
'browser',
|
|
119
|
-
'unpkg',
|
|
120
|
-
'module',
|
|
121
|
-
'exports',
|
|
122
|
-
'imports',
|
|
123
|
-
'types',
|
|
124
|
-
'typings',
|
|
125
|
-
'files',
|
|
126
|
-
'packageManager',
|
|
127
|
-
'sideEffects',
|
|
128
|
-
'engines',
|
|
129
|
-
'os',
|
|
130
|
-
'cpu',
|
|
131
|
-
'man',
|
|
132
|
-
'directories',
|
|
133
|
-
'repository',
|
|
134
|
-
'bugs',
|
|
135
|
-
'homepage',
|
|
136
|
-
'readme',
|
|
137
|
-
'keywords',
|
|
138
|
-
'scripts',
|
|
139
|
-
'config',
|
|
140
|
-
'dependencies',
|
|
141
|
-
'devDependencies',
|
|
142
|
-
'peerDependencies',
|
|
143
|
-
'peerDependenciesMeta',
|
|
144
|
-
'bundleDependencies',
|
|
145
|
-
'bundledDependencies',
|
|
146
|
-
'optionalDependencies',
|
|
147
|
-
'overrides',
|
|
148
|
-
'publishConfig',
|
|
149
|
-
'workspaces'
|
|
150
|
-
]);
|
|
151
|
-
const newPkg = {};
|
|
152
|
-
for (const key of order) {
|
|
153
|
-
if (key in options || key in pkg.pkg) {
|
|
154
|
-
newPkg[key] = treatKey(key);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (const key in pkg.pkg) {
|
|
158
|
-
if (!order.has(key)) {
|
|
159
|
-
newPkg[key] = pkg.pkg[key];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
pkg.pkg = newPkg;
|
|
295
|
+
pkg.pkg = processPackageJson(pkg.pkg, (key) => (key in options || key in pkg.pkg), treatKey);
|
|
163
296
|
function treatKey(key) {
|
|
164
297
|
if (key === 'scripts') {
|
|
165
298
|
({ ...pkg.pkg.scripts });
|
|
@@ -301,9 +434,6 @@ function getPkgbldOptions(pkg) {
|
|
|
301
434
|
noTsConfig: false,
|
|
302
435
|
noUpdatePackageJson: false
|
|
303
436
|
};
|
|
304
|
-
function CommaSeparatedString(value) {
|
|
305
|
-
return value.split(',').map((arg) => arg.trim());
|
|
306
|
-
}
|
|
307
437
|
const cmd = pkg.scripts?.build ?? '';
|
|
308
438
|
let binary = 'pkgbld';
|
|
309
439
|
if (cmd) {
|
|
@@ -324,56 +454,7 @@ function getPkgbldOptions(pkg) {
|
|
|
324
454
|
}
|
|
325
455
|
const parsedArgs = cleye.cli({
|
|
326
456
|
help: false,
|
|
327
|
-
flags:
|
|
328
|
-
umd: {
|
|
329
|
-
type: CommaSeparatedString,
|
|
330
|
-
default: args.umd
|
|
331
|
-
},
|
|
332
|
-
compress: {
|
|
333
|
-
type: CommaSeparatedString,
|
|
334
|
-
default: args.compress
|
|
335
|
-
},
|
|
336
|
-
sourcemaps: {
|
|
337
|
-
type: CommaSeparatedString,
|
|
338
|
-
default: args.sourcemaps
|
|
339
|
-
},
|
|
340
|
-
formats: {
|
|
341
|
-
type: CommaSeparatedString,
|
|
342
|
-
default: args.formats
|
|
343
|
-
},
|
|
344
|
-
preprocess: {
|
|
345
|
-
type: CommaSeparatedString,
|
|
346
|
-
default: args.preprocess
|
|
347
|
-
},
|
|
348
|
-
dir: {
|
|
349
|
-
type: String,
|
|
350
|
-
default: args.dir
|
|
351
|
-
},
|
|
352
|
-
sourceDir: {
|
|
353
|
-
type: String,
|
|
354
|
-
default: args.sourceDir
|
|
355
|
-
},
|
|
356
|
-
bin: {
|
|
357
|
-
type: CommaSeparatedString,
|
|
358
|
-
default: args.bin
|
|
359
|
-
},
|
|
360
|
-
includeExternals: {
|
|
361
|
-
type: Boolean,
|
|
362
|
-
default: args.includeExternals
|
|
363
|
-
},
|
|
364
|
-
eject: {
|
|
365
|
-
type: Boolean,
|
|
366
|
-
default: args.eject
|
|
367
|
-
},
|
|
368
|
-
noTsConfig: {
|
|
369
|
-
type: Boolean,
|
|
370
|
-
default: args.noTsConfig
|
|
371
|
-
},
|
|
372
|
-
noUpdatePackageJson: {
|
|
373
|
-
type: Boolean,
|
|
374
|
-
default: args.noUpdatePackageJson
|
|
375
|
-
}
|
|
376
|
-
}
|
|
457
|
+
flags: cliFlags
|
|
377
458
|
}, undefined, stringArgv.parseArgsStringToArgv(cmd));
|
|
378
459
|
args = parsedArgs.flags;
|
|
379
460
|
args.extraParameters = asCommandLineArgs(parsedArgs.unknownFlags);
|
|
@@ -522,27 +603,7 @@ async function readPackage(dir) {
|
|
|
522
603
|
const pkgFile = await fs.readFile(packageFileName);
|
|
523
604
|
const readmeFile = await fs.readFile(readmeFileName);
|
|
524
605
|
const pkg = JSON.parse(pkgFile.toString());
|
|
525
|
-
const isValidPackageJson = (
|
|
526
|
-
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io3(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io3(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io3(input.peerDependencies));
|
|
527
|
-
const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
|
|
528
|
-
const $io2 = input => Object.keys(input).every(key => {
|
|
529
|
-
const value = input[key];
|
|
530
|
-
if (undefined === value)
|
|
531
|
-
return true;
|
|
532
|
-
if (RegExp(/(.*)/).test(key))
|
|
533
|
-
return "string" === typeof value;
|
|
534
|
-
return true;
|
|
535
|
-
});
|
|
536
|
-
const $io3 = input => Object.keys(input).every(key => {
|
|
537
|
-
const value = input[key];
|
|
538
|
-
if (undefined === value)
|
|
539
|
-
return true;
|
|
540
|
-
if (RegExp(/(.*)/).test(key))
|
|
541
|
-
return "string" === typeof value;
|
|
542
|
-
return true;
|
|
543
|
-
});
|
|
544
|
-
return "object" === typeof input && null !== input && false === Array.isArray(input) && $io0(input);
|
|
545
|
-
})(pkg);
|
|
606
|
+
const isValidPackageJson = isPackageJson(pkg);
|
|
546
607
|
if (!isValidPackageJson) {
|
|
547
608
|
console.error('Invalid package.json');
|
|
548
609
|
throw new Error('Invalid package.json');
|
|
@@ -565,7 +626,7 @@ async function writePackage(dir, pkg) {
|
|
|
565
626
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
566
627
|
try {
|
|
567
628
|
await fs.mkdir(dir, { recursive: true });
|
|
568
|
-
await fs.writeFile(packageFileName,
|
|
629
|
+
await fs.writeFile(packageFileName, toFormattedJson(pkg.pkg));
|
|
569
630
|
await fs.writeFile(readmeFileName, pkg.readme);
|
|
570
631
|
}
|
|
571
632
|
catch (e) {
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import userName from 'git-user-name';
|
|
|
5
5
|
import gitConfig from 'parse-git-config';
|
|
6
6
|
import { cli } from 'cleye';
|
|
7
7
|
import kleur from 'kleur';
|
|
8
|
-
import 'typia';
|
|
9
8
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
10
9
|
import childProcess from 'node:child_process';
|
|
11
10
|
import util from 'node:util';
|
|
@@ -16,6 +15,196 @@ async function getGitRoot() {
|
|
|
16
15
|
return stdout.trim();
|
|
17
16
|
}
|
|
18
17
|
|
|
18
|
+
function isPackageJson(value) {
|
|
19
|
+
return (input => {
|
|
20
|
+
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io3(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io3(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io3(input.peerDependencies));
|
|
21
|
+
const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
|
|
22
|
+
const $io2 = input => Object.keys(input).every(key => {
|
|
23
|
+
const value = input[key];
|
|
24
|
+
if (undefined === value)
|
|
25
|
+
return true;
|
|
26
|
+
if (RegExp(/(.*)/).test(key))
|
|
27
|
+
return "string" === typeof value;
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
const $io3 = input => Object.keys(input).every(key => {
|
|
31
|
+
const value = input[key];
|
|
32
|
+
if (undefined === value)
|
|
33
|
+
return true;
|
|
34
|
+
if (RegExp(/(.*)/).test(key))
|
|
35
|
+
return "string" === typeof value;
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
return "object" === typeof input && null !== input && false === Array.isArray(input) && $io0(input);
|
|
39
|
+
})(value);
|
|
40
|
+
}
|
|
41
|
+
function CommaSeparatedString(value) {
|
|
42
|
+
return value.split(',').map((arg) => arg.trim());
|
|
43
|
+
}
|
|
44
|
+
function CommaSeparatedStringOrBoolean(value) {
|
|
45
|
+
if (typeof value === 'boolean') {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return CommaSeparatedString(value);
|
|
52
|
+
}
|
|
53
|
+
const cliFlagsDefaults = {
|
|
54
|
+
formats: ['es', 'cjs'],
|
|
55
|
+
umdInputs: [],
|
|
56
|
+
compressFormats: ['umd'],
|
|
57
|
+
sourcemapFormats: ['umd'],
|
|
58
|
+
preprocess: [],
|
|
59
|
+
dir: 'dist',
|
|
60
|
+
sourceDir: 'src',
|
|
61
|
+
includeExternals: false,
|
|
62
|
+
eject: false,
|
|
63
|
+
noTsConfig: false,
|
|
64
|
+
noUpdatePackageJson: false,
|
|
65
|
+
commonjsPattern: '[name].cjs',
|
|
66
|
+
esPattern: '[name].mjs',
|
|
67
|
+
umdPattern: '[name].umd.js'
|
|
68
|
+
};
|
|
69
|
+
const cliFlags = {
|
|
70
|
+
umd: {
|
|
71
|
+
type: CommaSeparatedString,
|
|
72
|
+
description: 'Package subpath exports in UMD format',
|
|
73
|
+
default: cliFlagsDefaults.umdInputs
|
|
74
|
+
},
|
|
75
|
+
compress: {
|
|
76
|
+
type: CommaSeparatedString,
|
|
77
|
+
description: 'Compress formats using terser',
|
|
78
|
+
default: cliFlagsDefaults.compressFormats
|
|
79
|
+
},
|
|
80
|
+
sourcemaps: {
|
|
81
|
+
type: CommaSeparatedString,
|
|
82
|
+
description: 'Emit sourcemaps for the specified formats',
|
|
83
|
+
default: cliFlagsDefaults.sourcemapFormats
|
|
84
|
+
},
|
|
85
|
+
formats: {
|
|
86
|
+
type: CommaSeparatedString,
|
|
87
|
+
description: 'Formats to emit',
|
|
88
|
+
default: cliFlagsDefaults.formats
|
|
89
|
+
},
|
|
90
|
+
preprocess: {
|
|
91
|
+
type: CommaSeparatedString,
|
|
92
|
+
description: 'Preprocess entry points / subpath exports',
|
|
93
|
+
default: cliFlagsDefaults.preprocess
|
|
94
|
+
},
|
|
95
|
+
dir: {
|
|
96
|
+
type: String,
|
|
97
|
+
description: 'Output directory',
|
|
98
|
+
default: cliFlagsDefaults.dir
|
|
99
|
+
},
|
|
100
|
+
sourceDir: {
|
|
101
|
+
type: String,
|
|
102
|
+
description: 'Source directory',
|
|
103
|
+
default: cliFlagsDefaults.sourceDir
|
|
104
|
+
},
|
|
105
|
+
bin: {
|
|
106
|
+
type: CommaSeparatedString,
|
|
107
|
+
description: 'Executable files'
|
|
108
|
+
},
|
|
109
|
+
includeExternals: {
|
|
110
|
+
type: CommaSeparatedStringOrBoolean,
|
|
111
|
+
description: 'Include all/specified externals into result bundle(s)',
|
|
112
|
+
default: cliFlagsDefaults.includeExternals
|
|
113
|
+
},
|
|
114
|
+
eject: {
|
|
115
|
+
type: Boolean,
|
|
116
|
+
description: 'Eject config',
|
|
117
|
+
default: cliFlagsDefaults.eject
|
|
118
|
+
},
|
|
119
|
+
noTsConfig: {
|
|
120
|
+
type: Boolean,
|
|
121
|
+
description: 'Do not create / update tsconfig.json',
|
|
122
|
+
default: cliFlagsDefaults.noTsConfig
|
|
123
|
+
},
|
|
124
|
+
noUpdatePackageJson: {
|
|
125
|
+
type: Boolean,
|
|
126
|
+
description: 'Do not create / update package.json',
|
|
127
|
+
default: cliFlagsDefaults.noUpdatePackageJson
|
|
128
|
+
},
|
|
129
|
+
commonjsPattern: {
|
|
130
|
+
type: String,
|
|
131
|
+
description: 'CommonJS output file name pattern',
|
|
132
|
+
default: cliFlagsDefaults.commonjsPattern
|
|
133
|
+
},
|
|
134
|
+
esmPattern: {
|
|
135
|
+
type: String,
|
|
136
|
+
description: 'ES output file name pattern',
|
|
137
|
+
default: cliFlagsDefaults.esPattern
|
|
138
|
+
},
|
|
139
|
+
umdPattern: {
|
|
140
|
+
type: String,
|
|
141
|
+
description: 'UMD output file name pattern',
|
|
142
|
+
default: cliFlagsDefaults.umdPattern
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const packageJsonFieldsOrder = new Set([
|
|
146
|
+
'private',
|
|
147
|
+
'type',
|
|
148
|
+
'version',
|
|
149
|
+
'name',
|
|
150
|
+
'description',
|
|
151
|
+
'license',
|
|
152
|
+
'author',
|
|
153
|
+
'contributors',
|
|
154
|
+
'funding',
|
|
155
|
+
'bin',
|
|
156
|
+
'main',
|
|
157
|
+
'browser',
|
|
158
|
+
'unpkg',
|
|
159
|
+
'module',
|
|
160
|
+
'exports',
|
|
161
|
+
'imports',
|
|
162
|
+
'types',
|
|
163
|
+
'typings',
|
|
164
|
+
'files',
|
|
165
|
+
'packageManager',
|
|
166
|
+
'sideEffects',
|
|
167
|
+
'engines',
|
|
168
|
+
'os',
|
|
169
|
+
'cpu',
|
|
170
|
+
'man',
|
|
171
|
+
'directories',
|
|
172
|
+
'repository',
|
|
173
|
+
'bugs',
|
|
174
|
+
'homepage',
|
|
175
|
+
'readme',
|
|
176
|
+
'keywords',
|
|
177
|
+
'scripts',
|
|
178
|
+
'config',
|
|
179
|
+
'dependencies',
|
|
180
|
+
'devDependencies',
|
|
181
|
+
'peerDependencies',
|
|
182
|
+
'peerDependenciesMeta',
|
|
183
|
+
'bundleDependencies',
|
|
184
|
+
'bundledDependencies',
|
|
185
|
+
'optionalDependencies',
|
|
186
|
+
'overrides',
|
|
187
|
+
'publishConfig',
|
|
188
|
+
'workspaces'
|
|
189
|
+
]);
|
|
190
|
+
function processPackageJson(pkg, needTreatment, treatKey) {
|
|
191
|
+
const newPkg = {};
|
|
192
|
+
for (const key of packageJsonFieldsOrder) {
|
|
193
|
+
if (needTreatment(key)) {
|
|
194
|
+
newPkg[key] = treatKey(key);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const key in pkg) {
|
|
198
|
+
if (!packageJsonFieldsOrder.has(key)) {
|
|
199
|
+
newPkg[key] = pkg[key];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return newPkg;
|
|
203
|
+
}
|
|
204
|
+
function toFormattedJson(json) {
|
|
205
|
+
return JSON.stringify(json, null, 2) + '\n';
|
|
206
|
+
}
|
|
207
|
+
|
|
19
208
|
const done = Symbol('done');
|
|
20
209
|
const formats = ['amd', 'cjs', 'es', 'iife', 'system', 'umd'];
|
|
21
210
|
const pkgbldBinaries = ['pkgbld', 'pkgbld-internal', 'node ../pkgbld/dist/index.js'];
|
|
@@ -100,63 +289,7 @@ async function execute() {
|
|
|
100
289
|
}
|
|
101
290
|
execute();
|
|
102
291
|
function updatePackage(pkg, options) {
|
|
103
|
-
|
|
104
|
-
'private',
|
|
105
|
-
'type',
|
|
106
|
-
'version',
|
|
107
|
-
'name',
|
|
108
|
-
'description',
|
|
109
|
-
'license',
|
|
110
|
-
'author',
|
|
111
|
-
'contributors',
|
|
112
|
-
'funding',
|
|
113
|
-
'bin',
|
|
114
|
-
'main',
|
|
115
|
-
'browser',
|
|
116
|
-
'unpkg',
|
|
117
|
-
'module',
|
|
118
|
-
'exports',
|
|
119
|
-
'imports',
|
|
120
|
-
'types',
|
|
121
|
-
'typings',
|
|
122
|
-
'files',
|
|
123
|
-
'packageManager',
|
|
124
|
-
'sideEffects',
|
|
125
|
-
'engines',
|
|
126
|
-
'os',
|
|
127
|
-
'cpu',
|
|
128
|
-
'man',
|
|
129
|
-
'directories',
|
|
130
|
-
'repository',
|
|
131
|
-
'bugs',
|
|
132
|
-
'homepage',
|
|
133
|
-
'readme',
|
|
134
|
-
'keywords',
|
|
135
|
-
'scripts',
|
|
136
|
-
'config',
|
|
137
|
-
'dependencies',
|
|
138
|
-
'devDependencies',
|
|
139
|
-
'peerDependencies',
|
|
140
|
-
'peerDependenciesMeta',
|
|
141
|
-
'bundleDependencies',
|
|
142
|
-
'bundledDependencies',
|
|
143
|
-
'optionalDependencies',
|
|
144
|
-
'overrides',
|
|
145
|
-
'publishConfig',
|
|
146
|
-
'workspaces'
|
|
147
|
-
]);
|
|
148
|
-
const newPkg = {};
|
|
149
|
-
for (const key of order) {
|
|
150
|
-
if (key in options || key in pkg.pkg) {
|
|
151
|
-
newPkg[key] = treatKey(key);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
for (const key in pkg.pkg) {
|
|
155
|
-
if (!order.has(key)) {
|
|
156
|
-
newPkg[key] = pkg.pkg[key];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
pkg.pkg = newPkg;
|
|
292
|
+
pkg.pkg = processPackageJson(pkg.pkg, (key) => (key in options || key in pkg.pkg), treatKey);
|
|
160
293
|
function treatKey(key) {
|
|
161
294
|
if (key === 'scripts') {
|
|
162
295
|
({ ...pkg.pkg.scripts });
|
|
@@ -298,9 +431,6 @@ function getPkgbldOptions(pkg) {
|
|
|
298
431
|
noTsConfig: false,
|
|
299
432
|
noUpdatePackageJson: false
|
|
300
433
|
};
|
|
301
|
-
function CommaSeparatedString(value) {
|
|
302
|
-
return value.split(',').map((arg) => arg.trim());
|
|
303
|
-
}
|
|
304
434
|
const cmd = pkg.scripts?.build ?? '';
|
|
305
435
|
let binary = 'pkgbld';
|
|
306
436
|
if (cmd) {
|
|
@@ -321,56 +451,7 @@ function getPkgbldOptions(pkg) {
|
|
|
321
451
|
}
|
|
322
452
|
const parsedArgs = cli({
|
|
323
453
|
help: false,
|
|
324
|
-
flags:
|
|
325
|
-
umd: {
|
|
326
|
-
type: CommaSeparatedString,
|
|
327
|
-
default: args.umd
|
|
328
|
-
},
|
|
329
|
-
compress: {
|
|
330
|
-
type: CommaSeparatedString,
|
|
331
|
-
default: args.compress
|
|
332
|
-
},
|
|
333
|
-
sourcemaps: {
|
|
334
|
-
type: CommaSeparatedString,
|
|
335
|
-
default: args.sourcemaps
|
|
336
|
-
},
|
|
337
|
-
formats: {
|
|
338
|
-
type: CommaSeparatedString,
|
|
339
|
-
default: args.formats
|
|
340
|
-
},
|
|
341
|
-
preprocess: {
|
|
342
|
-
type: CommaSeparatedString,
|
|
343
|
-
default: args.preprocess
|
|
344
|
-
},
|
|
345
|
-
dir: {
|
|
346
|
-
type: String,
|
|
347
|
-
default: args.dir
|
|
348
|
-
},
|
|
349
|
-
sourceDir: {
|
|
350
|
-
type: String,
|
|
351
|
-
default: args.sourceDir
|
|
352
|
-
},
|
|
353
|
-
bin: {
|
|
354
|
-
type: CommaSeparatedString,
|
|
355
|
-
default: args.bin
|
|
356
|
-
},
|
|
357
|
-
includeExternals: {
|
|
358
|
-
type: Boolean,
|
|
359
|
-
default: args.includeExternals
|
|
360
|
-
},
|
|
361
|
-
eject: {
|
|
362
|
-
type: Boolean,
|
|
363
|
-
default: args.eject
|
|
364
|
-
},
|
|
365
|
-
noTsConfig: {
|
|
366
|
-
type: Boolean,
|
|
367
|
-
default: args.noTsConfig
|
|
368
|
-
},
|
|
369
|
-
noUpdatePackageJson: {
|
|
370
|
-
type: Boolean,
|
|
371
|
-
default: args.noUpdatePackageJson
|
|
372
|
-
}
|
|
373
|
-
}
|
|
454
|
+
flags: cliFlags
|
|
374
455
|
}, undefined, parseArgsStringToArgv(cmd));
|
|
375
456
|
args = parsedArgs.flags;
|
|
376
457
|
args.extraParameters = asCommandLineArgs(parsedArgs.unknownFlags);
|
|
@@ -519,27 +600,7 @@ async function readPackage(dir) {
|
|
|
519
600
|
const pkgFile = await fs.readFile(packageFileName);
|
|
520
601
|
const readmeFile = await fs.readFile(readmeFileName);
|
|
521
602
|
const pkg = JSON.parse(pkgFile.toString());
|
|
522
|
-
const isValidPackageJson = (
|
|
523
|
-
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io3(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io3(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io3(input.peerDependencies));
|
|
524
|
-
const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
|
|
525
|
-
const $io2 = input => Object.keys(input).every(key => {
|
|
526
|
-
const value = input[key];
|
|
527
|
-
if (undefined === value)
|
|
528
|
-
return true;
|
|
529
|
-
if (RegExp(/(.*)/).test(key))
|
|
530
|
-
return "string" === typeof value;
|
|
531
|
-
return true;
|
|
532
|
-
});
|
|
533
|
-
const $io3 = input => Object.keys(input).every(key => {
|
|
534
|
-
const value = input[key];
|
|
535
|
-
if (undefined === value)
|
|
536
|
-
return true;
|
|
537
|
-
if (RegExp(/(.*)/).test(key))
|
|
538
|
-
return "string" === typeof value;
|
|
539
|
-
return true;
|
|
540
|
-
});
|
|
541
|
-
return "object" === typeof input && null !== input && false === Array.isArray(input) && $io0(input);
|
|
542
|
-
})(pkg);
|
|
603
|
+
const isValidPackageJson = isPackageJson(pkg);
|
|
543
604
|
if (!isValidPackageJson) {
|
|
544
605
|
console.error('Invalid package.json');
|
|
545
606
|
throw new Error('Invalid package.json');
|
|
@@ -562,7 +623,7 @@ async function writePackage(dir, pkg) {
|
|
|
562
623
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
563
624
|
try {
|
|
564
625
|
await fs.mkdir(dir, { recursive: true });
|
|
565
|
-
await fs.writeFile(packageFileName,
|
|
626
|
+
await fs.writeFile(packageFileName, toFormattedJson(pkg.pkg));
|
|
566
627
|
await fs.writeFile(readmeFileName, pkg.readme);
|
|
567
628
|
}
|
|
568
629
|
catch (e) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.6.0",
|
|
3
3
|
"name": "create-pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"init"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"typia": "^5.0.1",
|
|
38
37
|
"string-argv": "^0.3.2",
|
|
39
38
|
"git-user-name": "2.0.0",
|
|
40
39
|
"cleye": "^1.3.2",
|
|
@@ -44,13 +43,14 @@
|
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@types/git-user-name": "2.0.1",
|
|
47
|
-
"@types/parse-git-config": "3.0.
|
|
48
|
-
"@types/prompts": "2.4.
|
|
46
|
+
"@types/parse-git-config": "3.0.2",
|
|
47
|
+
"@types/prompts": "2.4.5",
|
|
49
48
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
50
|
-
"pkgbld": "1.
|
|
49
|
+
"pkgbld": "1.20.0",
|
|
50
|
+
"options": "0.0.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "node ../pkgbld/dist/index.js",
|
|
53
|
+
"build": "node ../pkgbld/dist/index.js --include-externals=options",
|
|
54
54
|
"lint": "eslint ./src"
|
|
55
55
|
}
|
|
56
56
|
}
|