create-pkgbld 1.7.3 → 1.8.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.mjs CHANGED
@@ -8,7 +8,7 @@ import kleur from 'kleur';
8
8
  import { parseArgsStringToArgv } from 'string-argv';
9
9
  import childProcess from 'node:child_process';
10
10
  import util from 'node:util';
11
- import { isEqual } from 'lodash';
11
+ import isEqual from 'lodash/isEqual.js';
12
12
 
13
13
  async function getGitRoot() {
14
14
  const exec = util.promisify(childProcess.exec);
@@ -18,24 +18,26 @@ async function getGitRoot() {
18
18
 
19
19
  function isPackageJson(value) {
20
20
  return (input => {
21
- 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.repository || "object" === typeof input.repository && null !== input.repository && false === Array.isArray(input.repository) && $io3(input.repository)) && (undefined === input.bugs || "string" === typeof input.bugs) && (undefined === input.homepage || "string" === typeof input.homepage) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io4(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io4(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io4(input.peerDependencies));
21
+ 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.repository || "object" === typeof input.repository && null !== input.repository && false === Array.isArray(input.repository) && $io3(input.repository)) && (undefined === input.files || Array.isArray(input.files) && input.files.every(elem => "string" === typeof elem)) && (undefined === input.bugs || "string" === typeof input.bugs) && (undefined === input.homepage || "string" === typeof input.homepage) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io4(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io4(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io4(input.peerDependencies)) && (undefined === input.exports || "object" === typeof input.exports && null !== input.exports && false === Array.isArray(input.exports) && $io5(input.exports));
22
22
  const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
23
23
  const $io2 = input => Object.keys(input).every(key => {
24
24
  const value = input[key];
25
25
  if (undefined === value)
26
26
  return true;
27
- if (RegExp(/(.*)/).test(key))
28
- return "string" === typeof value;
29
- return true;
27
+ return "string" === typeof value;
30
28
  });
31
29
  const $io3 = input => (undefined === input.type || "string" === typeof input.type) && (undefined === input.url || "string" === typeof input.url);
32
30
  const $io4 = input => Object.keys(input).every(key => {
33
31
  const value = input[key];
34
32
  if (undefined === value)
35
33
  return true;
36
- if (RegExp(/(.*)/).test(key))
37
- return "string" === typeof value;
38
- return true;
34
+ return "string" === typeof value;
35
+ });
36
+ const $io5 = input => Object.keys(input).every(key => {
37
+ const value = input[key];
38
+ if (undefined === value)
39
+ return true;
40
+ return null !== value && undefined !== value && ("string" === typeof value || "object" === typeof value && null !== value && false === Array.isArray(value) && $io4(value));
39
41
  });
40
42
  return "object" === typeof input && null !== input && false === Array.isArray(input) && $io0(input);
41
43
  })(value);
@@ -151,14 +153,24 @@ const cliFlags = {
151
153
  type: Boolean,
152
154
  description: 'Format package.json',
153
155
  default: cliFlagsDefaults.formatPackageJson
154
- }
156
+ },
157
+ noPack: {
158
+ type: Boolean,
159
+ description: 'Do not pack',
160
+ default: false
161
+ },
162
+ noExports: {
163
+ type: Boolean,
164
+ description: 'Do not add exports field in package.json',
165
+ default: false
166
+ },
155
167
  };
156
168
  const packageJsonFieldsOrder = new Set([
157
169
  'private',
158
170
  'type',
159
171
  'version',
160
172
  'name',
161
- 'scope',
173
+ 'scope', // custom
162
174
  'description',
163
175
  'license',
164
176
  'author',
@@ -174,7 +186,7 @@ const packageJsonFieldsOrder = new Set([
174
186
  'imports',
175
187
  'types',
176
188
  'typings',
177
- 'typesVersions',
189
+ 'typesVersions', // non standard but required for typescript with resolution other than nodenext
178
190
  'files',
179
191
  'packageManager',
180
192
  'sideEffects',
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ import('./dist/index.mjs');
package/package.json CHANGED
@@ -1,37 +1,16 @@
1
1
  {
2
- "version": "1.7.3",
2
+ "version": "1.8.0",
3
3
  "name": "create-pkgbld",
4
4
  "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
6
- "bin": "./dist/index.cjs",
7
- "main": "./dist/index.cjs",
8
- "module": "./dist/index.mjs",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.cjs",
14
- "default": "./dist/index.mjs"
15
- },
16
- "./package.json": "./package.json"
17
- },
18
- "types": "./dist/index.d.ts",
19
- "typesVersions": {
20
- "*": {
21
- ".": [
22
- "dist/index.d.ts"
23
- ],
24
- "*": [
25
- "dist/index.d.ts",
26
- "dist/*"
27
- ]
28
- }
29
- },
6
+ "bin": "./index.js",
7
+ "main": "./dist/index.mjs",
8
+ "type": "module",
30
9
  "files": [
31
10
  "dist"
32
11
  ],
33
12
  "engines": {
34
- "node": ">=16"
13
+ "node": ">=20"
35
14
  },
36
15
  "repository": {
37
16
  "type": "git",
@@ -1 +0,0 @@
1
- export default function getGitRoot(): Promise<string>;
package/dist/index.cjs DELETED
@@ -1,672 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var prompts = require('prompts');
5
- var path = require('path');
6
- var fs = require('fs/promises');
7
- var userName = require('git-user-name');
8
- var gitConfig = require('parse-git-config');
9
- var cleye = require('cleye');
10
- var kleur = require('kleur');
11
- var stringArgv = require('string-argv');
12
- var childProcess = require('node:child_process');
13
- var util = require('node:util');
14
- var lodash = require('lodash');
15
-
16
- async function getGitRoot() {
17
- const exec = util.promisify(childProcess.exec);
18
- const { stdout } = await exec('git rev-parse --show-toplevel');
19
- return stdout.trim();
20
- }
21
-
22
- function isPackageJson(value) {
23
- return (input => {
24
- 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.repository || "object" === typeof input.repository && null !== input.repository && false === Array.isArray(input.repository) && $io3(input.repository)) && (undefined === input.bugs || "string" === typeof input.bugs) && (undefined === input.homepage || "string" === typeof input.homepage) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io4(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io4(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io4(input.peerDependencies));
25
- const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
26
- const $io2 = input => Object.keys(input).every(key => {
27
- const value = input[key];
28
- if (undefined === value)
29
- return true;
30
- if (RegExp(/(.*)/).test(key))
31
- return "string" === typeof value;
32
- return true;
33
- });
34
- const $io3 = input => (undefined === input.type || "string" === typeof input.type) && (undefined === input.url || "string" === typeof input.url);
35
- const $io4 = input => Object.keys(input).every(key => {
36
- const value = input[key];
37
- if (undefined === value)
38
- return true;
39
- if (RegExp(/(.*)/).test(key))
40
- return "string" === typeof value;
41
- return true;
42
- });
43
- return "object" === typeof input && null !== input && false === Array.isArray(input) && $io0(input);
44
- })(value);
45
- }
46
- function CommaSeparatedString(value) {
47
- return value.split(',').map((arg) => arg.trim());
48
- }
49
- function CommaSeparatedStringOrBoolean(value) {
50
- if (typeof value === 'boolean') {
51
- return value;
52
- }
53
- // TODO check how we get array here
54
- if (Array.isArray(value) && value.length === 0) {
55
- return true;
56
- }
57
- return CommaSeparatedString(value);
58
- }
59
- const cliFlagsDefaults = {
60
- formats: ['es', 'cjs'],
61
- umd: [],
62
- compress: ['umd'],
63
- sourcemaps: ['umd'],
64
- preprocess: [],
65
- dest: 'dist',
66
- src: 'src',
67
- bin: undefined,
68
- includeExternals: false,
69
- eject: false,
70
- noTsConfig: false,
71
- noUpdatePackageJson: false,
72
- commonjsPattern: '[name].cjs',
73
- esmPattern: '[name].mjs',
74
- umdPattern: '[name].umd.js',
75
- formatPackageJson: false
76
- };
77
- const cliFlags = {
78
- umd: {
79
- type: CommaSeparatedString,
80
- description: 'Package subpath exports in UMD format',
81
- default: cliFlagsDefaults.umd
82
- },
83
- compress: {
84
- type: CommaSeparatedString,
85
- description: 'Compress formats using terser',
86
- default: cliFlagsDefaults.compress
87
- },
88
- sourcemaps: {
89
- type: CommaSeparatedString,
90
- description: 'Emit sourcemaps for the specified formats',
91
- default: cliFlagsDefaults.sourcemaps
92
- },
93
- formats: {
94
- type: CommaSeparatedString,
95
- description: 'Formats to emit',
96
- default: cliFlagsDefaults.formats
97
- },
98
- preprocess: {
99
- type: CommaSeparatedString,
100
- description: 'Preprocess entry points / subpath exports',
101
- default: cliFlagsDefaults.preprocess
102
- },
103
- dest: {
104
- type: String,
105
- description: 'Output directory',
106
- default: cliFlagsDefaults.dest
107
- },
108
- src: {
109
- type: String,
110
- description: 'Source directory',
111
- default: cliFlagsDefaults.src
112
- },
113
- bin: {
114
- type: CommaSeparatedString,
115
- description: 'Executable files',
116
- default: cliFlagsDefaults.bin
117
- },
118
- includeExternals: {
119
- type: CommaSeparatedStringOrBoolean,
120
- description: 'Include all/specified externals into result bundle(s)',
121
- default: cliFlagsDefaults.includeExternals
122
- },
123
- eject: {
124
- type: Boolean,
125
- description: 'Eject config',
126
- default: cliFlagsDefaults.eject
127
- },
128
- noTsConfig: {
129
- type: Boolean,
130
- description: 'Do not create / update tsconfig.json',
131
- default: cliFlagsDefaults.noTsConfig
132
- },
133
- noUpdatePackageJson: {
134
- type: Boolean,
135
- description: 'Do not create / update package.json',
136
- default: cliFlagsDefaults.noUpdatePackageJson
137
- },
138
- commonjsPattern: {
139
- type: String,
140
- description: 'CommonJS output file name pattern',
141
- default: cliFlagsDefaults.commonjsPattern
142
- },
143
- esmPattern: {
144
- type: String,
145
- description: 'ES output file name pattern',
146
- default: cliFlagsDefaults.esmPattern
147
- },
148
- umdPattern: {
149
- type: String,
150
- description: 'UMD output file name pattern',
151
- default: cliFlagsDefaults.umdPattern
152
- },
153
- formatPackageJson: {
154
- type: Boolean,
155
- description: 'Format package.json',
156
- default: cliFlagsDefaults.formatPackageJson
157
- }
158
- };
159
- const packageJsonFieldsOrder = new Set([
160
- 'private',
161
- 'type',
162
- 'version',
163
- 'name',
164
- 'scope',
165
- 'description',
166
- 'license',
167
- 'author',
168
- 'contributors',
169
- 'funding',
170
- 'bin',
171
- 'main',
172
- 'browser',
173
- 'unpkg',
174
- 'module',
175
- 'svelte',
176
- 'exports',
177
- 'imports',
178
- 'types',
179
- 'typings',
180
- 'typesVersions',
181
- 'files',
182
- 'packageManager',
183
- 'sideEffects',
184
- 'engines',
185
- 'os',
186
- 'cpu',
187
- 'man',
188
- 'directories',
189
- 'repository',
190
- 'bugs',
191
- 'homepage',
192
- 'readme',
193
- 'keywords',
194
- 'scripts',
195
- 'config',
196
- 'dependencies',
197
- 'devDependencies',
198
- 'peerDependencies',
199
- 'peerDependenciesMeta',
200
- 'bundleDependencies',
201
- 'bundledDependencies',
202
- 'optionalDependencies',
203
- 'overrides',
204
- 'publishConfig',
205
- 'workspaces'
206
- ]);
207
- function processPackageJson(pkg, needTreatment, treatKey) {
208
- const newPkg = {};
209
- for (const key of packageJsonFieldsOrder) {
210
- if (needTreatment(key)) {
211
- newPkg[key] = treatKey(key);
212
- }
213
- }
214
- for (const key in pkg) {
215
- if (!packageJsonFieldsOrder.has(key)) {
216
- newPkg[key] = pkg[key];
217
- }
218
- }
219
- return newPkg;
220
- }
221
- function toFormattedJson(json) {
222
- return JSON.stringify(json, null, 2) + '\n';
223
- }
224
-
225
- const done = Symbol('done');
226
- const formats = ['amd', 'cjs', 'es', 'iife', 'system', 'umd'];
227
- const pkgbldBinaries = ['pkgbld', 'pkgbld-internal', 'node ../pkgbld/dist/index.js'];
228
- async function execute() {
229
- const version = await reportVersion();
230
- const args = cleye.cli({
231
- name: 'create-pkgbld',
232
- version,
233
- parameters: [
234
- '[package name]'
235
- ],
236
- flags: {
237
- quiet: {
238
- type: Boolean,
239
- description: 'Quiet mode',
240
- default: false
241
- }
242
- }
243
- });
244
- !args.flags.quiet && args.showVersion();
245
- const targetDir = path.join(process.cwd(), args._.packageName ?? '.');
246
- !args.flags.quiet && console.log(kleur.grey(pad16plus('Target Directory', 0)) + kleur.white(targetDir));
247
- const pkg = await readPackage(targetDir);
248
- !args.flags.quiet && console.log(kleur.grey(pad16plus('Mode', 0)) + kleur.white(pkg.mode));
249
- const packageName = path.basename(targetDir);
250
- let cancelled = false;
251
- const options = getBasicOptions(packageName, pkg);
252
- options.push(...await getGitOptions(targetDir, pkg.pkg));
253
- options.push(...getPkgbldOptions(pkg.pkg));
254
- const state = getOptionsValue(options);
255
- if (!args.flags.quiet) {
256
- for (;;) {
257
- const topLevelAction = await prompts({
258
- type: 'select',
259
- name: 'value',
260
- message: 'Select an option to change, Done to execute, Escape to cancel',
261
- choices: [
262
- { title: kleur.green('Done'), description: `${pkg.mode === 'update' ? 'Update' : 'Create'} package`, value: done },
263
- ...options.map(mapOption(state))
264
- ],
265
- initial: 0
266
- }, { onCancel });
267
- if (cancelled) {
268
- process.exit(-1);
269
- }
270
- if (topLevelAction.value === done) {
271
- break;
272
- }
273
- let option = options.find(item => item.field === topLevelAction.value);
274
- let mutateObject = state;
275
- while ('items' in option) {
276
- const nextLevelAction = await prompts([{
277
- type: 'select',
278
- name: 'value',
279
- message: option.title,
280
- choices: option.items.map(mapOption(option.mutateInnerObject ? state[option.field] : state))
281
- }], { onCancel });
282
- if (cancelled) {
283
- process.exit(-1);
284
- }
285
- if (option.mutateInnerObject) {
286
- mutateObject = state[option.field];
287
- }
288
- option = option.items.find(item => item.field === nextLevelAction.value);
289
- }
290
- const action = await prompts(getPromptOption(option, mutateObject), { onCancel });
291
- if (cancelled) {
292
- process.exit(-1);
293
- }
294
- mutateObject[option.field] = action[option.field];
295
- }
296
- if (cancelled) {
297
- process.exit(-1);
298
- }
299
- }
300
- updatePackage(pkg, state);
301
- pkg.readme ??= `# ${state.name}`;
302
- await writePackage(targetDir, pkg);
303
- function onCancel() {
304
- cancelled = true;
305
- }
306
- }
307
- execute();
308
- function updatePackage(pkg, options) {
309
- pkg.pkg = processPackageJson(pkg.pkg, (key) => (key in options || key in pkg.pkg), treatKey);
310
- function treatKey(key) {
311
- if (key === 'scripts') {
312
- ({ ...pkg.pkg.scripts });
313
- getScriptValue(options.pkgbld);
314
- }
315
- return options[key] ?? pkg.pkg[key];
316
- }
317
- }
318
- function getScriptValue(pkgbld) {
319
- const binary = pkgbld.pkgbldBinary;
320
- const extraArgs = pkgbld.extraParameters;
321
- const pkgBldCopy = { ...pkgbld };
322
- delete pkgBldCopy['pkgbldBinary'];
323
- delete pkgBldCopy['extraParameters'];
324
- return `${binary} ${asCommandLineArgs(pkgBldCopy, cliFlagsDefaults)} ${extraArgs}`.trimEnd();
325
- }
326
- function getPromptOption(option, mutateObject) {
327
- const value = mutateObject[option.field];
328
- const type = option.type ?? 'text';
329
- const promptOption = {
330
- type,
331
- name: option.field,
332
- message: option.title,
333
- initial: (Array.isArray(value) ? value.join(',') : value) ?? ''
334
- };
335
- if (type === 'multiselect') {
336
- promptOption.choices = 'list' in option ? option.list.map(item => ({
337
- title: item,
338
- value: item,
339
- selected: value.includes(item)
340
- })) : [];
341
- }
342
- if (type === 'select') {
343
- promptOption.choices = 'list' in option ? option.list.map(item => ({
344
- title: item,
345
- value: item
346
- })) : [];
347
- promptOption.initial = promptOption.choices.findIndex(item => item.value === promptOption.initial);
348
- }
349
- return promptOption;
350
- }
351
- function mapOption(state) {
352
- return (option) => {
353
- const fieldValue = state[option.field];
354
- return {
355
- title: pad16plus(option.title) + kleur.grey('items' in option ? getPrintString(option, (option.mutateInnerObject ? fieldValue : state)) : fieldValue ?? ''),
356
- value: option.field
357
- };
358
- };
359
- }
360
- function getPrintString(option, json) {
361
- if (option.render) {
362
- return option.render(option, json);
363
- }
364
- return option.items
365
- .filter(item => item.field in json && json[item.field] && (Array.isArray(json[item.field]) ? json[item.field].length > 0 : true))
366
- .map(item => kleur.grey(item.title) + ' ' + (kleur.white('items' in item ?
367
- `[${getPrintString(item, (item.mutateInnerObject ? json[item.field] :
368
- json))}]` : json[item.field])))
369
- .join(', ');
370
- }
371
- function getOptionsValue(options) {
372
- const result = {};
373
- for (const item of options) {
374
- if ('items' in item) {
375
- const value = getOptionsValue(item.items);
376
- if (item.mutateInnerObject) {
377
- result[item.field] = value;
378
- }
379
- else {
380
- Object.assign(result, value);
381
- }
382
- }
383
- else {
384
- result[item.field] = item.initialValue;
385
- }
386
- }
387
- return result;
388
- }
389
- async function reportVersion() {
390
- const createPkgBldPackage = await readPackage(path.resolve(__dirname, '..'));
391
- const version = createPkgBldPackage.pkg.version ?? '<unknown>';
392
- return version;
393
- }
394
- async function getGitOptions(targetDir, packageJson) {
395
- try {
396
- const gitCfg = await gitConfig();
397
- if (gitCfg) {
398
- const url = gitCfg['remote "origin"'].url;
399
- const root = await getGitRoot();
400
- const directory = path.relative(root, targetDir);
401
- return [{
402
- title: 'Git',
403
- field: 'git',
404
- mutateInnerObject: false,
405
- render: (_option, value) => lodash.isEqual(removeEmpty({
406
- repository: value.repository,
407
- bugs: value.bugs,
408
- homepage: value.homepage
409
- }), removeEmpty({
410
- repository: packageJson.repository,
411
- bugs: packageJson.bugs,
412
- homepage: packageJson.homepage
413
- })) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
414
- items: [{
415
- title: 'Homepage',
416
- field: 'homepage',
417
- initialValue: url.replace('.git', `/blob/main${directory ? '/' + directory : ''}/README.md`)
418
- }, {
419
- title: 'Repository',
420
- field: 'repository',
421
- items: [{
422
- title: 'Type',
423
- field: 'type',
424
- initialValue: 'git'
425
- }, {
426
- title: 'Url',
427
- field: 'url',
428
- initialValue: `git+${url}`
429
- }, {
430
- title: 'Directory',
431
- field: 'directory',
432
- initialValue: directory || undefined
433
- }],
434
- mutateInnerObject: true
435
- }, {
436
- title: 'Bugs',
437
- field: 'bugs',
438
- initialValue: url.replace('.git', '/issues')
439
- }]
440
- }];
441
- }
442
- }
443
- catch (e) {
444
- /* ignore */
445
- }
446
- return [];
447
- }
448
- function getPkgbldOptions(pkg) {
449
- let args = cliFlagsDefaults;
450
- const cmd = pkg.scripts?.build ?? '';
451
- let binary = 'pkgbld';
452
- if (cmd) {
453
- if (cmd.startsWith('pkgbld-internal')) {
454
- binary = 'pkgbld-internal';
455
- }
456
- else if (cmd.startsWith('node ../pkgbld/dist/index.js')) {
457
- binary = 'node ../pkgbld/dist/index.js';
458
- }
459
- else if (!cmd.startsWith('pkgbld')) {
460
- const naiveArgs = cmd.split(' ');
461
- if (naiveArgs.length > 1 && naiveArgs[0] === 'node') {
462
- binary = naiveArgs[0] + ' ' + naiveArgs[1];
463
- }
464
- else if (naiveArgs.length > 0) {
465
- binary = naiveArgs[0]; // ?????
466
- }
467
- }
468
- const parsedArgs = cleye.cli({
469
- help: false,
470
- flags: cliFlags
471
- }, undefined, stringArgv.parseArgsStringToArgv(cmd));
472
- args = parsedArgs.flags;
473
- args.extraParameters = asCommandLineArgs(parsedArgs.unknownFlags);
474
- }
475
- return [{
476
- title: 'pkgbld',
477
- field: 'pkgbld',
478
- mutateInnerObject: true,
479
- render: (_option, value) => cmd === getScriptValue(value) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
480
- items: [{
481
- title: 'Destination folder',
482
- field: 'dest',
483
- initialValue: args.dest
484
- }, {
485
- title: 'Source folder',
486
- field: 'src',
487
- initialValue: args.src
488
- }, {
489
- title: 'UMD exports',
490
- field: 'umd',
491
- initialValue: args.umd,
492
- type: 'list'
493
- }, {
494
- title: 'Compress formats',
495
- field: 'compress',
496
- initialValue: args.compress,
497
- type: 'multiselect',
498
- list: formats
499
- }, {
500
- title: 'Sorcemaps formats',
501
- field: 'sourcemaps',
502
- initialValue: args.sourcemaps,
503
- type: 'multiselect',
504
- list: formats
505
- }, {
506
- title: 'Formats',
507
- field: 'formats',
508
- initialValue: args.formats,
509
- type: 'multiselect',
510
- list: formats
511
- }, {
512
- title: 'Preprocess formats',
513
- field: 'preprocess',
514
- initialValue: args.preprocess,
515
- type: 'multiselect',
516
- list: formats
517
- }, {
518
- title: 'Binaries',
519
- field: 'bin',
520
- initialValue: args.bin,
521
- type: 'list'
522
- }, {
523
- title: 'Include externals',
524
- field: 'includeExternals',
525
- type: 'toggle',
526
- initialValue: args.includeExternals
527
- }, {
528
- title: 'Eject config',
529
- field: 'eject',
530
- type: 'toggle',
531
- initialValue: args.eject
532
- }, {
533
- title: 'Do not create tsconfig',
534
- field: 'noTsConfig',
535
- type: 'toggle',
536
- initialValue: args.noTsConfig
537
- }, {
538
- title: 'Do not update package.json',
539
- field: 'noUpdatePackageJson',
540
- type: 'toggle',
541
- initialValue: args.noUpdatePackageJson
542
- }, {
543
- title: 'Extra parameters',
544
- field: 'extraParameters',
545
- type: 'text',
546
- initialValue: args.extraParameters
547
- }, {
548
- title: 'Pkgbld Binary',
549
- field: 'pkgbldBinary',
550
- type: 'select',
551
- list: pkgbldBinaries.includes(binary) ? pkgbldBinaries : [...pkgbldBinaries, binary],
552
- initialValue: binary
553
- }]
554
- }];
555
- }
556
- function asCommandLineArgs(parsedArgs, defaultArgs = {}) {
557
- return Object.entries(parsedArgs)
558
- .filter(([key, value]) => !lodash.isEqual(value, defaultArgs[key]))
559
- .map(([key, value]) => `--${kebabize(key)}${typeof value === 'string' || Array.isArray(value) ? `=${asArray(value).join(',')}` : ''}`)
560
- .filter(Boolean)
561
- .join(' ');
562
- }
563
- function asArray(value) {
564
- return Array.isArray(value) ? value : [value];
565
- }
566
- function getBasicOptions(packageName, pkg) {
567
- return [{
568
- title: 'General',
569
- field: 'general',
570
- render: (_option, value) => lodash.isEqual(removeEmpty({
571
- name: value.name,
572
- version: value.version,
573
- description: value.description,
574
- license: value.license,
575
- author: value.author,
576
- readme: value.readme
577
- }), removeEmpty({
578
- name: pkg.pkg.name,
579
- version: pkg.pkg.version,
580
- description: pkg.pkg.description,
581
- license: pkg.pkg.license,
582
- author: pkg.pkg.author,
583
- readme: pkg.pkg.readme
584
- })) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
585
- items: [{
586
- title: 'Package Name',
587
- field: 'name',
588
- initialValue: chooseValue(pkg.pkg.name, packageName)
589
- }, {
590
- title: 'Version',
591
- field: 'version',
592
- initialValue: chooseValue(pkg.pkg.version, '0.0.1')
593
- }, {
594
- title: 'Description',
595
- field: 'description',
596
- initialValue: chooseValue(pkg.pkg.description, '')
597
- }, {
598
- title: 'License',
599
- field: 'license',
600
- initialValue: chooseValue(pkg.pkg.license, 'MIT')
601
- }, {
602
- title: 'Author',
603
- field: 'author',
604
- initialValue: chooseValue(toAuthorString(pkg.pkg.author), userName() ?? '')
605
- }, {
606
- title: 'Readme',
607
- field: 'readme',
608
- initialValue: chooseValue(pkg.pkg.readme, 'README.md')
609
- }],
610
- mutateInnerObject: false
611
- }];
612
- function chooseValue(pkgValue, defaultValue) {
613
- return pkg.mode === 'update' ? pkgValue : defaultValue;
614
- }
615
- function toAuthorString(author) {
616
- if (typeof author === 'string' || !author) {
617
- return author;
618
- }
619
- const name = author.name ?? '';
620
- const email = author.email ?? '';
621
- const url = author.url ?? '';
622
- return `${name}${email ? ` <${email}>` : ''}${url ? ` (${url})` : ''}`;
623
- }
624
- }
625
- function pad16plus(value, indent = 4, offset = 3) {
626
- return value + ''.padEnd(offset - Math.floor((value.length + indent) / 8), '\t');
627
- }
628
- async function readPackage(dir) {
629
- const packageFileName = path.resolve(dir, 'package.json');
630
- const readmeFileName = path.resolve(dir, 'README.md');
631
- const defaultPkg = {};
632
- try {
633
- const pkgFile = await fs.readFile(packageFileName);
634
- const readmeFile = await fs.readFile(readmeFileName);
635
- const pkg = JSON.parse(pkgFile.toString());
636
- const isValidPackageJson = isPackageJson(pkg);
637
- if (!isValidPackageJson) {
638
- console.error('Invalid package.json');
639
- throw new Error('Invalid package.json');
640
- }
641
- return {
642
- pkg,
643
- readme: readmeFile.toString(),
644
- mode: 'update'
645
- };
646
- }
647
- catch (e) { /**/ }
648
- return {
649
- pkg: defaultPkg,
650
- readme: '',
651
- mode: 'create'
652
- };
653
- }
654
- async function writePackage(dir, pkg) {
655
- const packageFileName = path.resolve(dir, 'package.json');
656
- const readmeFileName = path.resolve(dir, 'README.md');
657
- try {
658
- await fs.mkdir(dir, { recursive: true });
659
- await fs.writeFile(packageFileName, toFormattedJson(pkg.pkg));
660
- await fs.writeFile(readmeFileName, pkg.readme);
661
- }
662
- catch (e) {
663
- console.error(e);
664
- process.exit(-1);
665
- }
666
- }
667
- function removeEmpty(data) {
668
- return JSON.parse(JSON.stringify(data));
669
- }
670
- function kebabize(value) {
671
- return value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
672
- }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/types.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { PackageJson } from 'options';
2
- export type Option = ({
3
- title: string;
4
- field: string;
5
- type?: undefined | 'toggle' | 'list';
6
- } | {
7
- title: string;
8
- field: string;
9
- type: 'multiselect';
10
- list: string[];
11
- } | {
12
- title: string;
13
- field: string;
14
- type: 'select';
15
- list: string[];
16
- }) & ({
17
- initialValue?: string;
18
- } | {
19
- items: Option[];
20
- mutateInnerObject: boolean;
21
- render?: (option: Option, value: OptionsValue) => string;
22
- });
23
- export type PkgInfo = {
24
- readme: string;
25
- pkg: PackageJson;
26
- mode: 'create' | 'update';
27
- };
28
- export type OptionsValue = {
29
- [key: string]: undefined | null | number | boolean | string | OptionsValue;
30
- };