@form8ion/javascript 6.0.9 → 6.1.0-alpha.1

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/lib/index.js CHANGED
@@ -27,6 +27,7 @@ var path = require('path');
27
27
  var filedirname = require('filedirname');
28
28
  var huskyPlugin = require('@form8ion/husky');
29
29
  var configFile = require('@form8ion/config-file');
30
+ var prettier = require('@form8ion/prettier');
30
31
  var eslint = require('@form8ion/eslint');
31
32
 
32
33
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -63,47 +64,6 @@ var touch__default = /*#__PURE__*/_interopDefaultLegacy(touch);
63
64
  var filedirname__default = /*#__PURE__*/_interopDefaultLegacy(filedirname);
64
65
  var huskyPlugin__namespace = /*#__PURE__*/_interopNamespace(huskyPlugin);
65
66
 
66
- function ownKeys(object, enumerableOnly) {
67
- var keys = Object.keys(object);
68
-
69
- if (Object.getOwnPropertySymbols) {
70
- var symbols = Object.getOwnPropertySymbols(object);
71
- enumerableOnly && (symbols = symbols.filter(function (sym) {
72
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
73
- })), keys.push.apply(keys, symbols);
74
- }
75
-
76
- return keys;
77
- }
78
-
79
- function _objectSpread2(target) {
80
- for (var i = 1; i < arguments.length; i++) {
81
- var source = null != arguments[i] ? arguments[i] : {};
82
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
83
- _defineProperty(target, key, source[key]);
84
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
85
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
86
- });
87
- }
88
-
89
- return target;
90
- }
91
-
92
- function _defineProperty(obj, key, value) {
93
- if (key in obj) {
94
- Object.defineProperty(obj, key, {
95
- value: value,
96
- enumerable: true,
97
- configurable: true,
98
- writable: true
99
- });
100
- } else {
101
- obj[key] = value;
102
- }
103
-
104
- return obj;
105
- }
106
-
107
67
  const questionNames$1 = {
108
68
  UNIT_TEST_FRAMEWORK: 'unitTestFramework',
109
69
  NODE_VERSION_CATEGORY: 'nodeVersionCategory',
@@ -121,113 +81,74 @@ const questionNames$1 = {
121
81
  DIALECT: 'dialect'
122
82
  };
123
83
 
124
- async function scaffoldC8 ({
125
- projectRoot
126
- }) {
127
- await fs.promises.writeFile(`${projectRoot}/.c8rc.json`, JSON.stringify({
128
- reporter: ['lcov', 'text-summary', 'html'],
129
- exclude: ['src/**/*-test.js', 'test/', 'thirdparty-wrappers/', 'vendor/']
130
- }));
84
+ async function scaffoldC8 ({projectRoot}) {
85
+ await fs.promises.writeFile(
86
+ `${projectRoot}/.c8rc.json`,
87
+ JSON.stringify({
88
+ reporter: ['lcov', 'text-summary', 'html'],
89
+ exclude: ['src/**/*-test.js', 'test/', 'thirdparty-wrappers/', 'vendor/']
90
+ })
91
+ );
92
+
131
93
  return {
132
94
  devDependencies: ['cross-env', 'c8'],
133
- vcsIgnore: {
134
- files: [],
135
- directories: ['/coverage/']
136
- },
137
- eslint: {
138
- ignore: {
139
- directories: ['/coverage/']
140
- }
141
- }
95
+ vcsIgnore: {files: [], directories: ['/coverage/']},
96
+ eslint: {ignore: {directories: ['/coverage/']}}
142
97
  };
143
98
  }
144
99
 
145
- async function scaffoldCoverage ({
146
- projectRoot,
147
- vcs,
148
- visibility,
149
- pathWithinParent
150
- }) {
151
- return deepmerge__default["default"](await scaffoldC8({
152
- projectRoot
153
- }), await codecov.scaffold({
154
- vcs,
155
- visibility,
156
- pathWithinParent
157
- }));
100
+ async function scaffoldCoverage ({projectRoot, vcs, visibility, pathWithinParent}) {
101
+ return deepmerge__default["default"](await scaffoldC8({projectRoot}), await codecov.scaffold({vcs, visibility, pathWithinParent}));
158
102
  }
159
103
 
160
- function nycIsConfigured ({
161
- projectRoot
162
- }) {
104
+ function nycIsConfigured ({projectRoot}) {
163
105
  return core.fileExists(`${projectRoot}/.nycrc`);
164
106
  }
165
107
 
166
- async function removeDependencies ({
167
- packageManager,
168
- dependencies
169
- }) {
108
+ async function removeDependencies ({packageManager, dependencies}) {
170
109
  await execa__default["default"](packageManager, ['remove', ...dependencies]);
171
110
  }
172
111
 
173
- async function removeNyc ({
174
- projectRoot,
175
- packageManager
176
- }) {
177
- await Promise.all([fs.promises.unlink(`${projectRoot}/.nycrc`), fs.promises.rm(`${projectRoot}/.nyc_output`, {
178
- recursive: true,
179
- force: true
180
- }), removeDependencies({
181
- packageManager,
182
- dependencies: ['nyc', '@istanbuljs/nyc-config-babel', 'babel-plugin-istanbul']
183
- })]);
184
- }
185
-
186
- async function lift$2({
187
- projectRoot,
188
- packageManager
189
- }) {
190
- const codecovResults = await codecov.lift({
191
- projectRoot,
192
- packageManager
193
- });
194
-
195
- if (await nycIsConfigured({
196
- projectRoot
197
- })) {
198
- const [c8Results] = await Promise.all([scaffoldC8({
199
- projectRoot
200
- }), removeNyc({
201
- projectRoot,
202
- packageManager
203
- })]);
204
- return deepmerge__default["default"].all([c8Results, codecovResults, {
205
- scripts: {
206
- 'test:unit': 'cross-env NODE_ENV=test c8 run-s test:unit:base'
207
- },
208
- nextSteps: [{
209
- summary: 'Remove use of `@istanbuljs/nyc-config-babel` from your babel config, if present,' + ' after the migration away from `nyc`'
210
- }]
211
- }]);
112
+ async function removeNyc ({projectRoot, packageManager}) {
113
+ await Promise.all([
114
+ fs.promises.unlink(`${projectRoot}/.nycrc`),
115
+ fs.promises.rm(`${projectRoot}/.nyc_output`, {recursive: true, force: true}),
116
+ removeDependencies({packageManager, dependencies: ['nyc', '@istanbuljs/nyc-config-babel', 'babel-plugin-istanbul']})
117
+ ]);
118
+ }
119
+
120
+ async function lift$2({projectRoot, packageManager}) {
121
+ const codecovResults = await codecov.lift({projectRoot, packageManager});
122
+
123
+ if (await nycIsConfigured({projectRoot})) {
124
+ const [c8Results] = await Promise.all([
125
+ scaffoldC8({projectRoot}),
126
+ removeNyc({projectRoot, packageManager})
127
+ ]);
128
+
129
+ return deepmerge__default["default"].all([
130
+ c8Results,
131
+ codecovResults,
132
+ {
133
+ scripts: {'test:unit': 'cross-env NODE_ENV=test c8 run-s test:unit:base'},
134
+ nextSteps: [{
135
+ summary: 'Remove use of `@istanbuljs/nyc-config-babel` from your babel config, if present,'
136
+ + ' after the migration away from `nyc`'
137
+ }]
138
+ }
139
+ ]);
212
140
  }
213
141
 
214
142
  return {};
215
143
  }
216
144
 
217
- function c8IsConfigured ({
218
- projectRoot
219
- }) {
145
+ function c8IsConfigured ({projectRoot}) {
220
146
  return core.fileExists(`${projectRoot}/.c8rc.json`);
221
147
  }
222
148
 
223
- async function tester ({
224
- projectRoot
225
- }) {
226
- const [c8Exists, nycExists] = await Promise.all([c8IsConfigured({
227
- projectRoot
228
- }), nycIsConfigured({
229
- projectRoot
230
- })]);
149
+ async function tester ({projectRoot}) {
150
+ const [c8Exists, nycExists] = await Promise.all([c8IsConfigured({projectRoot}), nycIsConfigured({projectRoot})]);
151
+
231
152
  return c8Exists || nycExists;
232
153
  }
233
154
 
@@ -242,76 +163,47 @@ const unitTestFrameworksSchema = joi__default["default"].object().required().pat
242
163
  scaffolder: joi__default["default"].func().arity(1).required()
243
164
  }));
244
165
 
245
- async function chooseFramework ({
246
- frameworks,
247
- decisions
248
- }) {
166
+ async function chooseFramework ({frameworks, decisions}) {
249
167
  if (!Object.keys(frameworks).length) return 'Other';
168
+
250
169
  const answers = await overridablePrompts.prompt([{
251
170
  name: questionNames$1.UNIT_TEST_FRAMEWORK,
252
171
  type: 'list',
253
172
  message: 'Which type of unit testing framework should be used?',
254
173
  choices: [...Object.keys(frameworks), new overridablePrompts.Separator(), 'Other']
255
174
  }], decisions);
175
+
256
176
  return answers[questionNames$1.UNIT_TEST_FRAMEWORK];
257
177
  }
258
178
 
259
- async function scaffoldUnitTesting ({
260
- projectRoot,
261
- frameworks,
262
- decisions,
263
- visibility,
264
- vcs,
265
- pathWithinParent,
266
- dialect
267
- }) {
179
+ async function scaffoldUnitTesting ({projectRoot, frameworks, decisions, visibility, vcs, pathWithinParent, dialect}) {
268
180
  const validatedFrameworks = javascriptCore.validateOptions(unitTestFrameworksSchema, frameworks);
269
- const [framework, coverage] = await Promise.all([chooseFramework({
270
- frameworks: validatedFrameworks,
271
- decisions
272
- }).then(chosenFramework => javascriptCore.scaffoldChoice(validatedFrameworks, chosenFramework, {
273
- projectRoot,
274
- dialect
275
- })), scaffoldCoverage({
276
- projectRoot,
277
- vcs,
278
- visibility,
279
- pathWithinParent
280
- })]);
281
- return deepmerge__default["default"].all([{
282
- scripts: {
283
- 'test:unit': 'cross-env NODE_ENV=test c8 run-s test:unit:base'
284
- }
285
- }, framework, coverage]);
181
+ const [framework, coverage] = await Promise.all([
182
+ chooseFramework({frameworks: validatedFrameworks, decisions})
183
+ .then(chosenFramework => javascriptCore.scaffoldChoice(validatedFrameworks, chosenFramework, {projectRoot, dialect})),
184
+ scaffoldCoverage({projectRoot, vcs, visibility, pathWithinParent})
185
+ ]);
186
+
187
+ return deepmerge__default["default"].all([
188
+ {scripts: {'test:unit': 'cross-env NODE_ENV=test c8 run-s test:unit:base'}},
189
+ framework,
190
+ coverage
191
+ ]);
286
192
  }
287
193
 
288
- async function test$1({
289
- projectRoot
290
- }) {
291
- const {
292
- engines
293
- } = JSON.parse(await fs.promises.readFile(`${projectRoot}/package.json`, 'utf8'));
294
- return !!(engines !== null && engines !== void 0 && engines.node);
194
+ async function test$1({projectRoot}) {
195
+ const {engines} = JSON.parse(await fs.promises.readFile(`${projectRoot}/package.json`, 'utf8'));
196
+
197
+ return !!engines?.node;
295
198
  }
296
- async function lift$1({
297
- projectRoot
298
- }) {
299
- const {
300
- name
301
- } = JSON.parse(await fs.promises.readFile(`${projectRoot}/package.json`, 'utf8'));
199
+
200
+ async function lift$1({projectRoot}) {
201
+ const {name} = JSON.parse(await fs.promises.readFile(`${projectRoot}/package.json`, 'utf8'));
202
+
302
203
  return {
303
204
  devDependencies: ['ls-engines'],
304
- scripts: {
305
- 'lint:engines': 'ls-engines'
306
- },
307
- badges: {
308
- consumer: {
309
- node: {
310
- img: `https://img.shields.io/node/v/${name}?logo=node.js`,
311
- text: 'node'
312
- }
313
- }
314
- }
205
+ scripts: {'lint:engines': 'ls-engines'},
206
+ badges: {consumer: {node: {img: `https://img.shields.io/node/v/${name}?logo=node.js`, text: 'node'}}}
315
207
  };
316
208
  }
317
209
 
@@ -334,27 +226,33 @@ function projectShouldBeBuiltForVerification(scripts) {
334
226
  }
335
227
 
336
228
  function updateTestScript (scripts) {
337
- return _objectSpread2(_objectSpread2({}, scripts), {}, {
338
- test: `npm-run-all --print-label${projectShouldBeBuiltForVerification(scripts) ? ' build' : ''} --parallel lint:*${projectWillBeTested(scripts) ? ' --parallel test:*' : ''}`
339
- });
229
+ return {
230
+ ...scripts,
231
+ test: `npm-run-all --print-label${
232
+ projectShouldBeBuiltForVerification(scripts) ? ' build' : ''
233
+ } --parallel lint:*${
234
+ projectWillBeTested(scripts) ? ' --parallel test:*' : ''
235
+ }`
236
+ };
340
237
  }
341
238
 
342
- function liftScripts ({
343
- existingScripts,
344
- scripts
345
- }) {
346
- return updateTestScript(_objectSpread2(_objectSpread2({}, existingScripts), scripts));
239
+ function liftScripts ({existingScripts, scripts}) {
240
+ return updateTestScript({...existingScripts, ...scripts});
347
241
  }
348
242
 
349
243
  function defineVcsHostDetails(vcs, packageType, packageName, pathWithinParent) {
350
244
  return vcs && 'github' === vcs.host && {
351
- repository: pathWithinParent ? {
352
- type: 'git',
353
- url: `https://github.com/${vcs.owner}/${vcs.name}.git`,
354
- directory: pathWithinParent
355
- } : `${vcs.owner}/${vcs.name}`,
245
+ repository: pathWithinParent
246
+ ? {
247
+ type: 'git',
248
+ url: `https://github.com/${vcs.owner}/${vcs.name}.git`,
249
+ directory: pathWithinParent
250
+ }
251
+ : `${vcs.owner}/${vcs.name}`,
356
252
  bugs: `https://github.com/${vcs.owner}/${vcs.name}/issues`,
357
- homepage: javascriptCore.projectTypes.PACKAGE === packageType ? `https://npm.im/${packageName}` : `https://github.com/${vcs.owner}/${vcs.name}#readme`
253
+ homepage: (javascriptCore.projectTypes.PACKAGE === packageType)
254
+ ? `https://npm.im/${packageName}`
255
+ : `https://github.com/${vcs.owner}/${vcs.name}#readme`
358
256
  };
359
257
  }
360
258
 
@@ -368,15 +266,15 @@ function buildPackageDetails ({
368
266
  description,
369
267
  pathWithinParent
370
268
  }) {
371
- return _objectSpread2(_objectSpread2({
269
+ return {
372
270
  name: packageName,
373
271
  description,
374
272
  license,
375
- type: javascriptCore.dialects.ESM === dialect ? 'module' : 'commonjs'
376
- }, defineVcsHostDetails(vcs, projectType, packageName, pathWithinParent)), {}, {
273
+ type: javascriptCore.dialects.ESM === dialect ? 'module' : 'commonjs',
274
+ ...defineVcsHostDetails(vcs, projectType, packageName, pathWithinParent),
377
275
  author: `${author.name}${author.email ? ` <${author.email}>` : ''}${author.url ? ` (${author.url})` : ''}`,
378
276
  scripts: scaffoldScripts()
379
- });
277
+ };
380
278
  }
381
279
 
382
280
  async function scaffoldPackage ({
@@ -391,6 +289,7 @@ async function scaffoldPackage ({
391
289
  pathWithinParent
392
290
  }) {
393
291
  cliMessages.info('Configuring package.json');
292
+
394
293
  const packageData = await buildPackageDetails({
395
294
  packageName,
396
295
  projectType,
@@ -401,13 +300,10 @@ async function scaffoldPackage ({
401
300
  description,
402
301
  pathWithinParent
403
302
  });
404
- await javascriptCore.writePackageJson({
405
- projectRoot,
406
- config: packageData
407
- });
408
- return {
409
- homepage: packageData.homepage
410
- };
303
+
304
+ await javascriptCore.writePackageJson({projectRoot, config: packageData});
305
+
306
+ return {homepage: packageData.homepage};
411
307
  }
412
308
 
413
309
  async function liftPackage ({
@@ -419,21 +315,21 @@ async function liftPackage ({
419
315
  packageManager
420
316
  }) {
421
317
  if (scripts || tags) {
422
- cliMessages.info('Updating `package.json`', {
423
- level: 'secondary'
424
- });
318
+ cliMessages.info('Updating `package.json`', {level: 'secondary'});
319
+
425
320
  const pathToPackageJson = `${projectRoot}/package.json`;
321
+
426
322
  const existingPackageJsonContents = JSON.parse(await fs.promises.readFile(pathToPackageJson, 'utf8'));
323
+
427
324
  await javascriptCore.writePackageJson({
428
325
  projectRoot,
429
- config: _objectSpread2(_objectSpread2({}, existingPackageJsonContents), {}, {
430
- scripts: liftScripts({
431
- existingScripts: existingPackageJsonContents.scripts,
432
- scripts
433
- })
434
- }, tags && {
435
- keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags
436
- })
326
+ config: {
327
+ ...existingPackageJsonContents,
328
+ scripts: liftScripts({existingScripts: existingPackageJsonContents.scripts, scripts}),
329
+ ...tags && {
330
+ keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags
331
+ }
332
+ }
437
333
  });
438
334
  }
439
335
 
@@ -441,16 +337,13 @@ async function liftPackage ({
441
337
 
442
338
  try {
443
339
  await javascriptCore.installDependencies(dependencies || [], javascriptCore.PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
444
- await javascriptCore.installDependencies([...(devDependencies || [])], javascriptCore.DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
340
+ await javascriptCore.installDependencies([...devDependencies || []], javascriptCore.DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
445
341
  } catch (e) {
446
342
  cliMessages.error('Failed to install dependencies');
447
343
  }
448
344
  }
449
345
 
450
- async function resolvePackageManager ({
451
- projectRoot,
452
- packageManager
453
- }) {
346
+ async function resolvePackageManager ({projectRoot, packageManager}) {
454
347
  if (packageManager) return packageManager;
455
348
 
456
349
  if (await core.fileExists(`${projectRoot}/package-lock.json`)) {
@@ -464,46 +357,28 @@ async function resolvePackageManager ({
464
357
  throw new Error('Package-manager could not be determined');
465
358
  }
466
359
 
467
- async function lift ({
468
- projectRoot,
469
- vcs,
470
- results
471
- }) {
360
+ async function lift ({projectRoot, vcs, results}) {
472
361
  cliMessages.info('Lifting JavaScript-specific details');
473
- const {
474
- scripts,
475
- tags,
476
- eslintConfigs,
477
- eslint: eslint$1,
478
- dependencies,
479
- devDependencies,
480
- packageManager: manager
481
- } = results;
482
- const packageManager = await resolvePackageManager({
483
- projectRoot,
484
- packageManager: manager
485
- });
486
- const eslintResults = await eslint.lift({
487
- projectRoot,
488
- configs: [...(eslintConfigs || []), ...((eslint$1 === null || eslint$1 === void 0 ? void 0 : eslint$1.configs) || [])]
489
- });
362
+
363
+ const {scripts, tags, eslintConfigs, eslint: eslint$1, dependencies, devDependencies, packageManager: manager} = results;
364
+
365
+ const packageManager = await resolvePackageManager({projectRoot, packageManager: manager});
366
+
367
+ const eslintResults = await eslint.lift({projectRoot, configs: [...eslintConfigs || [], ...eslint$1?.configs || []]});
490
368
  const enhancerResults = await core.applyEnhancers({
491
369
  results,
492
370
  enhancers: [huskyPlugin__namespace, enginesEnhancer, coveragePlugin, commitConventionPlugin__namespace],
493
- options: {
494
- packageManager,
495
- projectRoot,
496
- vcs
497
- }
371
+ options: {packageManager, projectRoot, vcs}
498
372
  });
499
- await liftPackage(deepmerge__default["default"].all([{
500
- projectRoot,
501
- scripts,
502
- tags,
503
- dependencies,
504
- devDependencies,
505
- packageManager
506
- }, enhancerResults, eslintResults]));
373
+
374
+ await liftPackage(
375
+ deepmerge__default["default"].all([
376
+ {projectRoot, scripts, tags, dependencies, devDependencies, packageManager},
377
+ enhancerResults,
378
+ eslintResults
379
+ ])
380
+ );
381
+
507
382
  return enhancerResults;
508
383
  }
509
384
 
@@ -512,106 +387,93 @@ const packageBundlersSchema = joi__default["default"].object().pattern(/^/, joi_
512
387
  })).default({});
513
388
 
514
389
  function validate(options) {
515
- const schema = joi__default["default"].object().required().keys({
516
- projectRoot: joi__default["default"].string().required(),
517
- projectName: joi__default["default"].string().regex(/^@\w*\//, {
518
- invert: true
519
- }).required(),
520
- visibility: joi__default["default"].string().valid('Public', 'Private').required(),
521
- license: joi__default["default"].string().required(),
522
- description: joi__default["default"].string(),
523
- pathWithinParent: joi__default["default"].string()
524
- }).keys({
525
- vcs: joi__default["default"].object({
526
- host: joi__default["default"].string().required(),
527
- owner: joi__default["default"].string().required(),
528
- name: joi__default["default"].string().required()
390
+ const schema = joi__default["default"].object().required()
391
+ .keys({
392
+ projectRoot: joi__default["default"].string().required(),
393
+ projectName: joi__default["default"].string().regex(/^@\w*\//, {invert: true}).required(),
394
+ visibility: joi__default["default"].string().valid('Public', 'Private').required(),
395
+ license: joi__default["default"].string().required(),
396
+ description: joi__default["default"].string(),
397
+ pathWithinParent: joi__default["default"].string()
529
398
  })
530
- }).keys({
531
- configs: joi__default["default"].object({
532
- eslint: joi__default["default"].object({
533
- scope: joi__default["default"].string().regex(/^@[a-z0-9-]+$/i, 'scope').required()
534
- }),
535
- typescript: joi__default["default"].object({
536
- scope: joi__default["default"].string().regex(/^@[a-z0-9-]+$/i, 'scope').required()
537
- }),
538
- commitlint: joi__default["default"].object({
539
- packageName: joi__default["default"].string().required(),
540
- name: joi__default["default"].string().required()
541
- }),
542
- babelPreset: joi__default["default"].object({
543
- packageName: joi__default["default"].string().required(),
399
+ .keys({
400
+ vcs: joi__default["default"].object({
401
+ host: joi__default["default"].string().required(),
402
+ owner: joi__default["default"].string().required(),
544
403
  name: joi__default["default"].string().required()
545
- }),
546
- remark: joi__default["default"].string()
547
- }).default({})
548
- }).keys({
549
- overrides: joi__default["default"].object({
550
- npmAccount: joi__default["default"].string(),
551
- author: joi__default["default"].object({
552
- name: joi__default["default"].string().required(),
553
- email: joi__default["default"].string().email(),
554
- url: joi__default["default"].string().uri()
555
404
  })
556
- }).default({})
557
- }).keys({
558
- ciServices: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
559
- scaffolder: joi__default["default"].func().arity(1).required(),
560
- public: joi__default["default"].boolean(),
561
- private: joi__default["default"].boolean()
562
- })).default({})
563
- }).keys({
564
- hosts: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
565
- scaffolder: joi__default["default"].func().arity(1).required(),
566
- projectTypes: joi__default["default"].array().items(joi__default["default"].string().valid('static', 'node')).default([])
567
- })).default({})
568
- }).keys({
569
- applicationTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
570
- scaffolder: joi__default["default"].func().arity(1).required()
571
- })).default({}),
572
- packageTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
573
- scaffolder: joi__default["default"].func().arity(1).required()
574
- })).default({}),
575
- monorepoTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
576
- scaffolder: joi__default["default"].func().arity(1).required()
577
- }))
578
- }).keys({
579
- unitTestFrameworks: unitTestFrameworksSchema,
580
- packageBundlers: packageBundlersSchema
581
- }).keys({
582
- decisions: joi__default["default"].object()
583
- }).keys({
584
- registries: joi__default["default"].object().pattern(joi__default["default"].string(), joi__default["default"].string().uri()).default({})
585
- });
586
- const {
587
- error,
588
- value
589
- } = schema.validate(options);
405
+ })
406
+ .keys({
407
+ configs: joi__default["default"].object({
408
+ eslint: joi__default["default"].object({scope: joi__default["default"].string().regex(/^@[a-z0-9-]+$/i, 'scope').required()}),
409
+ typescript: joi__default["default"].object({scope: joi__default["default"].string().regex(/^@[a-z0-9-]+$/i, 'scope').required()}),
410
+ commitlint: joi__default["default"].object({
411
+ packageName: joi__default["default"].string().required(),
412
+ name: joi__default["default"].string().required()
413
+ }),
414
+ babelPreset: joi__default["default"].object({
415
+ packageName: joi__default["default"].string().required(),
416
+ name: joi__default["default"].string().required()
417
+ }),
418
+ remark: joi__default["default"].string()
419
+ }).default({})
420
+ })
421
+ .keys({
422
+ overrides: joi__default["default"].object({
423
+ npmAccount: joi__default["default"].string(),
424
+ author: joi__default["default"].object({
425
+ name: joi__default["default"].string().required(),
426
+ email: joi__default["default"].string().email(),
427
+ url: joi__default["default"].string().uri()
428
+ })
429
+ }).default({})
430
+ })
431
+ .keys({
432
+ ciServices: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
433
+ scaffolder: joi__default["default"].func().arity(1).required(),
434
+ public: joi__default["default"].boolean(),
435
+ private: joi__default["default"].boolean()
436
+ })).default({})
437
+ })
438
+ .keys({
439
+ hosts: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
440
+ scaffolder: joi__default["default"].func().arity(1).required(),
441
+ projectTypes: joi__default["default"].array().items(joi__default["default"].string().valid('static', 'node')).default([])
442
+ })).default({})
443
+ })
444
+ .keys({
445
+ applicationTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
446
+ scaffolder: joi__default["default"].func().arity(1).required()
447
+ })).default({}),
448
+ packageTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
449
+ scaffolder: joi__default["default"].func().arity(1).required()
450
+ })).default({}),
451
+ monorepoTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
452
+ scaffolder: joi__default["default"].func().arity(1).required()
453
+ }))
454
+ })
455
+ .keys({
456
+ unitTestFrameworks: unitTestFrameworksSchema,
457
+ packageBundlers: packageBundlersSchema
458
+ })
459
+ .keys({
460
+ decisions: joi__default["default"].object()
461
+ })
462
+ .keys({registries: joi__default["default"].object().pattern(joi__default["default"].string(), joi__default["default"].string().uri()).default({})});
463
+ const {error, value} = schema.validate(options);
464
+
590
465
  hoek__default["default"].assert(!error, error);
466
+
591
467
  return value;
592
468
  }
593
469
 
594
- function buildDialectChoices ({
595
- babelPreset,
596
- typescript
597
- }) {
598
- return [{
599
- name: 'Common JS (no transpilation)',
600
- value: javascriptCore.dialects.COMMON_JS,
601
- short: 'cjs'
602
- }, ...(babelPreset ? [{
603
- name: 'Modern JavaScript (transpiled)',
604
- value: javascriptCore.dialects.BABEL,
605
- short: 'modern'
606
- }] : []), {
607
- name: 'ESM-only (no transpilation)',
608
- value: javascriptCore.dialects.ESM,
609
- short: 'esm'
610
- }, ...(typescript ? [{
611
- name: 'TypeScript',
612
- value: javascriptCore.dialects.TYPESCRIPT,
613
- short: 'ts'
614
- }] : [])];
470
+ function buildDialectChoices ({babelPreset, typescript}) {
471
+ return [
472
+ {name: 'Common JS (no transpilation)', value: javascriptCore.dialects.COMMON_JS, short: 'cjs'},
473
+ ...babelPreset ? [{name: 'Modern JavaScript (transpiled)', value: javascriptCore.dialects.BABEL, short: 'modern'}] : [],
474
+ {name: 'ESM-only (no transpilation)', value: javascriptCore.dialects.ESM, short: 'esm'},
475
+ ...typescript ? [{name: 'TypeScript', value: javascriptCore.dialects.TYPESCRIPT, short: 'ts'}] : []
476
+ ];
615
477
  }
616
478
 
617
479
  function projectIsPackage(answers) {
@@ -637,9 +499,11 @@ function willBePublishedToNpm(answers) {
637
499
  function shouldBeScopedPromptShouldBePresented(answers) {
638
500
  return willBePublishedToNpm(answers);
639
501
  }
502
+
640
503
  function scopePromptShouldBePresentedFactory(visibility) {
641
504
  return answers => willBePublishedToNpm(answers) && packageShouldBeScoped(visibility, answers);
642
505
  }
506
+
643
507
  function lintingPromptShouldBePresented({
644
508
  [languageScaffolderPrompts.questionNames.UNIT_TESTS]: unitTested,
645
509
  [languageScaffolderPrompts.questionNames.INTEGRATION_TESTS]: integrationTested
@@ -657,38 +521,45 @@ function scope(visibility) {
657
521
  };
658
522
  }
659
523
 
660
- function authorQuestions({
661
- name,
662
- email,
663
- url
664
- }) {
665
- return [{
666
- name: questionNames$1.AUTHOR_NAME,
667
- message: 'What is the author\'s name?',
668
- default: name
669
- }, {
670
- name: questionNames$1.AUTHOR_EMAIL,
671
- message: 'What is the author\'s email?',
672
- default: email
673
- }, {
674
- name: questionNames$1.AUTHOR_URL,
675
- message: 'What is the author\'s website url?',
676
- default: url
677
- }];
678
- }
679
-
680
- async function prompt({
681
- npmAccount,
682
- author
683
- }, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent) {
524
+ function authorQuestions({name, email, url}) {
525
+ return [
526
+ {
527
+ name: questionNames$1.AUTHOR_NAME,
528
+ message: 'What is the author\'s name?',
529
+ default: name
530
+ },
531
+ {
532
+ name: questionNames$1.AUTHOR_EMAIL,
533
+ message: 'What is the author\'s email?',
534
+ default: email
535
+ },
536
+ {
537
+ name: questionNames$1.AUTHOR_URL,
538
+ message: 'What is the author\'s website url?',
539
+ default: url
540
+ }
541
+ ];
542
+ }
543
+
544
+ async function prompt(
545
+ {npmAccount, author},
546
+ ciServices,
547
+ hosts,
548
+ visibility,
549
+ vcs,
550
+ decisions,
551
+ configs,
552
+ pathWithinParent
553
+ ) {
684
554
  const npmConf = npmConf__default["default"]();
685
- let maybeLoggedInNpmUsername;
686
555
 
556
+ let maybeLoggedInNpmUsername;
687
557
  try {
688
558
  maybeLoggedInNpmUsername = (await execa__default["default"]('npm', ['whoami'])).stdout;
689
559
  } catch (failedExecutionResult) {
690
560
  if (!decisions[questionNames$1.SCOPE]) {
691
- cliMessages.warn('No logged in user found with `npm whoami`. Login with `npm login` ' + 'to use your npm account name as the package scope default.');
561
+ cliMessages.warn('No logged in user found with `npm whoami`. Login with `npm login` '
562
+ + 'to use your npm account name as the package scope default.');
692
563
  }
693
564
  }
694
565
 
@@ -706,89 +577,85 @@ async function prompt({
706
577
  [questionNames$1.CONFIGURE_LINTING]: configureLinting,
707
578
  [questionNames$1.PACKAGE_MANAGER]: packageManager,
708
579
  [questionNames$1.DIALECT]: dialect
709
- } = await overridablePrompts.prompt([{
710
- name: questionNames$1.DIALECT,
711
- message: 'Which JavaScript dialect should this project follow?',
712
- type: 'list',
713
- choices: buildDialectChoices(configs),
714
- default: 'babel'
715
- }, ...(pathWithinParent ? [] : [{
716
- name: questionNames$1.NODE_VERSION_CATEGORY,
717
- message: 'What node.js version should be used?',
718
- type: 'list',
719
- choices: ['LTS', 'Latest'],
720
- default: 'LTS'
721
- }]), {
722
- name: questionNames$1.PACKAGE_MANAGER,
723
- message: 'Which package manager will be used with this project?',
724
- type: 'list',
725
- choices: Object.values(javascriptCore.packageManagers),
726
- default: javascriptCore.packageManagers.NPM
727
- }, {
728
- name: questionNames$1.PROJECT_TYPE,
729
- message: 'What type of JavaScript project is this?',
730
- type: 'list',
731
- choices: [...Object.values(javascriptCore.projectTypes), new overridablePrompts.Separator(), 'Other'],
732
- default: javascriptCore.projectTypes.PACKAGE
733
- }, ...('Private' === visibility ? [] : [{
734
- name: questionNames$1.SHOULD_BE_SCOPED,
735
- message: 'Should this package be scoped?',
736
- type: 'confirm',
737
- when: shouldBeScopedPromptShouldBePresented,
738
- default: true
739
- }]), {
740
- name: questionNames$1.SCOPE,
741
- message: 'What is the scope?',
742
- when: scopePromptShouldBePresentedFactory(visibility),
743
- validate: scope(visibility),
744
- default: npmAccount || maybeLoggedInNpmUsername
745
- }, ...authorQuestions(author || {
746
- name: npmConf.get('init.author.name'),
747
- email: npmConf.get('init.author.email'),
748
- url: npmConf.get('init.author.url')
749
- }), ...languageScaffolderPrompts.questions({
750
- vcs,
751
- ciServices,
752
- visibility,
753
- pathWithinParent
754
- }), {
755
- name: questionNames$1.CONFIGURE_LINTING,
756
- message: 'Will there be source code that should be linted?',
757
- type: 'confirm',
758
- when: lintingPromptShouldBePresented
759
- }, {
760
- name: questionNames$1.HOST,
761
- type: 'list',
762
- message: 'Where will the application be hosted?',
763
- when: projectIsApplication,
764
- choices: [...Object.keys(hosts), new overridablePrompts.Separator(), 'Other']
765
- }], decisions);
766
- return {
767
- tests: {
768
- unit: unitTested,
769
- integration: integrationTested
580
+ } = await overridablePrompts.prompt([
581
+ {
582
+ name: questionNames$1.DIALECT,
583
+ message: 'Which JavaScript dialect should this project follow?',
584
+ type: 'list',
585
+ choices: buildDialectChoices(configs),
586
+ default: 'babel'
587
+ },
588
+ ...pathWithinParent ? [] : [{
589
+ name: questionNames$1.NODE_VERSION_CATEGORY,
590
+ message: 'What node.js version should be used?',
591
+ type: 'list',
592
+ choices: ['LTS', 'Latest'],
593
+ default: 'LTS'
594
+ }],
595
+ {
596
+ name: questionNames$1.PACKAGE_MANAGER,
597
+ message: 'Which package manager will be used with this project?',
598
+ type: 'list',
599
+ choices: Object.values(javascriptCore.packageManagers),
600
+ default: javascriptCore.packageManagers.NPM
601
+ },
602
+ {
603
+ name: questionNames$1.PROJECT_TYPE,
604
+ message: 'What type of JavaScript project is this?',
605
+ type: 'list',
606
+ choices: [...Object.values(javascriptCore.projectTypes), new overridablePrompts.Separator(), 'Other'],
607
+ default: javascriptCore.projectTypes.PACKAGE
608
+ },
609
+ ...'Private' === visibility ? [] : [{
610
+ name: questionNames$1.SHOULD_BE_SCOPED,
611
+ message: 'Should this package be scoped?',
612
+ type: 'confirm',
613
+ when: shouldBeScopedPromptShouldBePresented,
614
+ default: true
615
+ }],
616
+ {
617
+ name: questionNames$1.SCOPE,
618
+ message: 'What is the scope?',
619
+ when: scopePromptShouldBePresentedFactory(visibility),
620
+ validate: scope(visibility),
621
+ default: npmAccount || maybeLoggedInNpmUsername
622
+ },
623
+ ...authorQuestions(author || {
624
+ name: npmConf.get('init.author.name'),
625
+ email: npmConf.get('init.author.email'),
626
+ url: npmConf.get('init.author.url')
627
+ }),
628
+ ...languageScaffolderPrompts.questions(({vcs, ciServices, visibility, pathWithinParent})),
629
+ {
630
+ name: questionNames$1.CONFIGURE_LINTING,
631
+ message: 'Will there be source code that should be linted?',
632
+ type: 'confirm',
633
+ when: lintingPromptShouldBePresented
770
634
  },
635
+ {
636
+ name: questionNames$1.HOST,
637
+ type: 'list',
638
+ message: 'Where will the application be hosted?',
639
+ when: projectIsApplication,
640
+ choices: [...Object.keys(hosts), new overridablePrompts.Separator(), 'Other']
641
+ }
642
+ ], decisions);
643
+
644
+ return {
645
+ tests: {unit: unitTested, integration: integrationTested},
771
646
  projectType,
772
647
  ci,
773
648
  chosenHost,
774
649
  scope: scope$1,
775
650
  nodeVersionCategory,
776
- author: {
777
- name: authorName,
778
- email: authorEmail,
779
- url: authorUrl
780
- },
651
+ author: {name: authorName, email: authorEmail, url: authorUrl},
781
652
  configureLinting: false !== configureLinting,
782
653
  packageManager,
783
654
  dialect
784
655
  };
785
656
  }
786
657
 
787
- async function scaffoldBabel ({
788
- projectRoot,
789
- preset,
790
- buildDirectory
791
- }) {
658
+ async function scaffoldBabel ({projectRoot, preset, buildDirectory}) {
792
659
  if (!preset) {
793
660
  throw new Error('No babel preset provided. Cannot configure babel transpilation');
794
661
  }
@@ -797,74 +664,50 @@ async function scaffoldBabel ({
797
664
  path: projectRoot,
798
665
  name: 'babel',
799
666
  format: core.fileTypes.JSON,
800
- config: {
801
- presets: [preset.name],
802
- ignore: [`./${buildDirectory}/`]
803
- }
667
+ config: {presets: [preset.name], ignore: [`./${buildDirectory}/`]}
804
668
  });
669
+
805
670
  return {
806
671
  devDependencies: ['@babel/register', preset.packageName],
807
672
  eslint: {}
808
673
  };
809
674
  }
810
675
 
811
- async function scaffoldTypescript ({
812
- config,
813
- projectType,
814
- projectRoot,
815
- testFilenamePattern
816
- }) {
676
+ async function scaffoldTypescript ({config, projectType, projectRoot, testFilenamePattern}) {
817
677
  const eslintConfigs = ['typescript'];
818
678
  const shareableTsConfigPackage = `${config.scope}/tsconfig`;
819
- await fs.promises.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify(_objectSpread2({
820
- $schema: 'https://json.schemastore.org/tsconfig',
821
- extends: shareableTsConfigPackage,
822
- compilerOptions: _objectSpread2({
823
- rootDir: 'src'
824
- }, javascriptCore.projectTypes.PACKAGE === projectType && {
825
- outDir: 'lib',
826
- declaration: true
827
- }),
828
- include: ['src/**/*.ts']
829
- }, testFilenamePattern && {
830
- exclude: [testFilenamePattern]
831
- })));
679
+
680
+ await fs.promises.writeFile(
681
+ `${projectRoot}/tsconfig.json`,
682
+ JSON.stringify({
683
+ $schema: 'https://json.schemastore.org/tsconfig',
684
+ extends: shareableTsConfigPackage,
685
+ compilerOptions: {
686
+ rootDir: 'src',
687
+ ...javascriptCore.projectTypes.PACKAGE === projectType && {
688
+ outDir: 'lib',
689
+ declaration: true
690
+ }
691
+ },
692
+ include: ['src/**/*.ts'],
693
+ ...testFilenamePattern && {exclude: [testFilenamePattern]}
694
+ })
695
+ );
696
+
832
697
  return {
833
- eslint: {
834
- configs: eslintConfigs
835
- },
698
+ eslint: {configs: eslintConfigs},
836
699
  eslintConfigs,
837
700
  devDependencies: ['typescript', shareableTsConfigPackage],
838
- vcsIgnore: {
839
- files: ['tsconfig.tsbuildinfo']
840
- }
701
+ vcsIgnore: {files: ['tsconfig.tsbuildinfo']}
841
702
  };
842
703
  }
843
704
 
844
- function scaffoldDialect ({
845
- dialect,
846
- projectType,
847
- projectRoot,
848
- configs,
849
- buildDirectory,
850
- testFilenamePattern
851
- }) {
705
+ function scaffoldDialect ({dialect, projectType, projectRoot, configs, buildDirectory, testFilenamePattern}) {
852
706
  switch (dialect) {
853
707
  case javascriptCore.dialects.BABEL:
854
- return scaffoldBabel({
855
- preset: configs.babelPreset,
856
- projectRoot,
857
- buildDirectory
858
- });
859
-
708
+ return scaffoldBabel({preset: configs.babelPreset, projectRoot, buildDirectory});
860
709
  case javascriptCore.dialects.TYPESCRIPT:
861
- return scaffoldTypescript({
862
- config: configs.typescript,
863
- projectType,
864
- projectRoot,
865
- testFilenamePattern
866
- });
867
-
710
+ return scaffoldTypescript({config: configs.typescript, projectType, projectRoot, testFilenamePattern});
868
711
  default:
869
712
  return {};
870
713
  }
@@ -879,34 +722,38 @@ async function scaffoldNpmConfig ({
879
722
  projectType,
880
723
  registries
881
724
  }) {
882
- await fs.promises.writeFile(`${projectRoot}/.npmrc`, ini.stringify(_objectSpread2(_objectSpread2({
883
- 'update-notifier': false
884
- }, projectWillNotBeConsumed(projectType) && {
885
- 'save-exact': true
886
- }), Object.fromEntries(Object.entries(registries).filter(([scope]) => 'publish' !== scope).map(([scope, url]) => {
887
- if ('registry' === scope) return ['registry', url];
888
- return [`@${scope}:registry`, url];
889
- })))));
890
- return {
891
- scripts: {
892
- 'lint:peer': 'npm ls >/dev/null'
893
- }
894
- };
725
+ await fs.promises.writeFile(
726
+ `${projectRoot}/.npmrc`,
727
+ ini.stringify({
728
+ 'update-notifier': false,
729
+ ...projectWillNotBeConsumed(projectType) && {'save-exact': true},
730
+ ...Object.fromEntries(Object.entries(registries)
731
+ .filter(([scope]) => 'publish' !== scope)
732
+ .map(([scope, url]) => {
733
+ if ('registry' === scope) return ['registry', url];
734
+
735
+ return [`@${scope}:registry`, url];
736
+ }))
737
+ })
738
+ );
739
+
740
+ return {scripts: {'lint:peer': 'npm ls >/dev/null'}};
895
741
  }
896
742
 
897
743
  function buildDocumentationCommand (packageManager) {
898
744
  if (javascriptCore.packageManagers.NPM === packageManager) return 'npm run generate:md';
899
745
  if (javascriptCore.packageManagers.YARN === packageManager) return 'yarn generate:md';
900
- throw new Error(`The ${packageManager} package manager is currently not supported. ` + `Only ${Object.values(javascriptCore.packageManagers).join(' and ')} are currently supported.`);
746
+
747
+ throw new Error(
748
+ `The ${packageManager} package manager is currently not supported. `
749
+ + `Only ${Object.values(javascriptCore.packageManagers).join(' and ')} are currently supported.`
750
+ );
901
751
  }
902
752
 
903
- function scaffoldDocumentation ({
904
- projectTypeResults,
905
- packageManager
906
- }) {
907
- return _objectSpread2(_objectSpread2({
908
- toc: `Run \`${buildDocumentationCommand(packageManager)}\` to generate a table of contents`
909
- }, projectTypeResults.documentation), {}, {
753
+ function scaffoldDocumentation ({projectTypeResults, packageManager}) {
754
+ return {
755
+ toc: `Run \`${buildDocumentationCommand(packageManager)}\` to generate a table of contents`,
756
+ ...projectTypeResults.documentation,
910
757
  contributing: `### Dependencies
911
758
 
912
759
  \`\`\`sh
@@ -919,43 +766,43 @@ $ ${packageManager} install
919
766
  \`\`\`sh
920
767
  $ ${packageManager} test
921
768
  \`\`\``
922
- });
769
+ };
923
770
  }
924
771
 
925
772
  async function determineLatestVersionOf(nodeVersionCategory) {
926
- cliMessages.info('Determining version of node', {
927
- level: 'secondary'
928
- });
929
- const {
930
- stdout: nvmLsOutput
931
- } = await execa__default["default"](`. ~/.nvm/nvm.sh && nvm ls-remote${'LTS' === nodeVersionCategory ? ' --lts' : ''}`, {
932
- shell: true
933
- });
773
+ cliMessages.info('Determining version of node', {level: 'secondary'});
774
+
775
+ const {stdout: nvmLsOutput} = await execa__default["default"](
776
+ `. ~/.nvm/nvm.sh && nvm ls-remote${('LTS' === nodeVersionCategory) ? ' --lts' : ''}`,
777
+ {shell: true}
778
+ );
779
+
934
780
  const lsLines = nvmLsOutput.split('\n');
935
781
  const lsLine = lsLines[lsLines.length - 2];
782
+
936
783
  return lsLine.match(/(v[0-9]+)\.[0-9]+\.[0-9]+/)[1];
937
784
  }
785
+
938
786
  function install(nodeVersionCategory) {
939
- cliMessages.info(`Installing ${nodeVersionCategory} version of node using nvm`, {
940
- level: 'secondary'
941
- });
942
- const subprocess = execa__default["default"]('. ~/.nvm/nvm.sh && nvm install', {
943
- shell: true
944
- });
787
+ cliMessages.info(`Installing ${nodeVersionCategory} version of node using nvm`, {level: 'secondary'});
788
+
789
+ const subprocess = execa__default["default"]('. ~/.nvm/nvm.sh && nvm install', {shell: true});
945
790
  subprocess.stdout.pipe(process.stdout);
946
791
  return subprocess;
947
792
  }
948
793
 
949
- async function scaffoldNodeVersion ({
950
- projectRoot,
951
- nodeVersionCategory
952
- }) {
794
+ async function scaffoldNodeVersion ({projectRoot, nodeVersionCategory}) {
953
795
  if (!nodeVersionCategory) return undefined;
796
+
954
797
  const lowerCaseCategory = nodeVersionCategory.toLowerCase();
955
798
  cliMessages.info(`Configuring ${lowerCaseCategory} version of node`);
799
+
956
800
  const version = await determineLatestVersionOf(nodeVersionCategory);
801
+
957
802
  await fs.promises.writeFile(`${projectRoot}/.nvmrc`, version);
803
+
958
804
  await install(nodeVersionCategory);
805
+
959
806
  return version;
960
807
  }
961
808
 
@@ -966,54 +813,52 @@ function buildBadgesDetails (contributors) {
966
813
  function buildVcsIgnoreLists (vcsIgnoreLists = {}) {
967
814
  return {
968
815
  files: vcsIgnoreLists.files || [],
969
- directories: ['/node_modules/', ...(vcsIgnoreLists.directories || [])]
816
+ directories: ['/node_modules/', ...vcsIgnoreLists.directories || []]
970
817
  };
971
818
  }
972
819
 
973
820
  function buildPackageName (projectName, scope) {
974
821
  const name = `${scope ? `@${scope}/` : ''}${projectName}`;
975
- const {
976
- validForNewPackages,
977
- errors
978
- } = validatePackageName__default["default"](name);
822
+
823
+ const {validForNewPackages, errors} = validatePackageName__default["default"](name);
824
+
979
825
  if (validForNewPackages) return name;
980
826
  if (1 === errors.length && errors.includes('name cannot start with a period')) return projectName.slice(1);
827
+
981
828
  throw new Error(`The package name ${name} is invalid:${os.EOL}\t* ${errors.join(`${os.EOL}\t* `)}`);
982
829
  }
983
830
 
984
- async function chooseApplicationType ({
985
- types,
986
- projectType,
987
- decisions
988
- }) {
831
+ async function chooseApplicationType ({types, projectType, decisions}) {
989
832
  if (!Object.keys(types).length) return 'Other';
833
+
990
834
  const answers = await overridablePrompts.prompt([{
991
835
  name: questionNames$1.PROJECT_TYPE_CHOICE,
992
836
  type: 'list',
993
837
  message: `What type of ${projectType} is this?`,
994
838
  choices: [...Object.keys(types), new overridablePrompts.Separator(), 'Other']
995
839
  }], decisions);
840
+
996
841
  return answers[questionNames$1.PROJECT_TYPE_CHOICE];
997
842
  }
998
843
 
999
844
  function getInstallationCommand(packageManager) {
1000
845
  if (javascriptCore.packageManagers.NPM === packageManager) return 'npm install';
1001
846
  if (javascriptCore.packageManagers.YARN === packageManager) return 'yarn add';
1002
- throw new Error(`The ${packageManager} package manager is currently not supported. ` + `Only ${Object.values(javascriptCore.packageManagers).join(' and ')} are currently supported.`);
847
+
848
+ throw new Error(
849
+ `The ${packageManager} package manager is currently not supported. `
850
+ + `Only ${Object.values(javascriptCore.packageManagers).join(' and ')} are currently supported.`
851
+ );
1003
852
  }
1004
853
 
1005
- function scaffoldPackageDocumentation ({
1006
- scope,
1007
- packageName,
1008
- packageManager,
1009
- visibility
1010
- }) {
854
+ function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility}) {
1011
855
  return {
1012
856
  usage: `### Installation
1013
857
  ${'Private' === visibility ? `
1014
858
  :warning: this is a private package, so you will need to use an npm token with
1015
859
  access to private packages under \`@${scope}\`
1016
- ` : ''}
860
+ ` : ''
861
+ }
1017
862
  \`\`\`sh
1018
863
  $ ${getInstallationCommand(packageManager)} ${packageName}
1019
864
  \`\`\`
@@ -1026,49 +871,56 @@ run \`${buildDocumentationCommand(packageManager)}\` to inject the usage example
1026
871
 
1027
872
  function defineBadges (packageName, visibility) {
1028
873
  return {
1029
- consumer: _objectSpread2({}, 'Public' === visibility && {
1030
- npm: {
1031
- img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
1032
- text: 'npm',
1033
- link: `https://www.npmjs.com/package/${packageName}`
874
+ consumer: {
875
+ ...'Public' === visibility && {
876
+ npm: {
877
+ img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
878
+ text: 'npm',
879
+ link: `https://www.npmjs.com/package/${packageName}`
880
+ }
1034
881
  }
1035
- }),
882
+ },
1036
883
  status: {}
1037
884
  };
1038
885
  }
1039
886
 
1040
- async function chooseBundler ({
1041
- bundlers,
1042
- decisions
1043
- }) {
887
+ async function chooseBundler ({bundlers, decisions}) {
1044
888
  if (!Object.keys(bundlers).length) return 'Other';
889
+
1045
890
  const answers = await overridablePrompts.prompt([{
1046
891
  name: questionNames$1.PACKAGE_BUNDLER,
1047
892
  type: 'list',
1048
893
  message: 'Which bundler should be used?',
1049
894
  choices: [...Object.keys(bundlers), new overridablePrompts.Separator(), 'Other']
1050
895
  }], decisions);
896
+
1051
897
  return answers[questionNames$1.PACKAGE_BUNDLER];
1052
898
  }
1053
899
 
1054
900
  function determinePathToTemplateFile (fileName) {
1055
901
  const [, __dirname] = filedirname__default["default"]();
902
+
1056
903
  return path.resolve(__dirname, '..', 'templates', fileName);
1057
904
  }
1058
905
 
1059
906
  const defaultBuildDirectory$2 = 'lib';
1060
907
 
1061
908
  async function createExample(projectRoot, projectName) {
1062
- return fs.promises.writeFile(`${projectRoot}/example.js`, mustache__default["default"].render(await fs.promises.readFile(determinePathToTemplateFile('example.mustache'), 'utf8'), {
1063
- projectName: camelcase__default["default"](projectName)
1064
- }));
909
+ return fs.promises.writeFile(
910
+ `${projectRoot}/example.js`,
911
+ mustache__default["default"].render(
912
+ await fs.promises.readFile(determinePathToTemplateFile('example.mustache'), 'utf8'),
913
+ {projectName: camelcase__default["default"](projectName)}
914
+ )
915
+ );
1065
916
  }
1066
917
 
1067
- async function buildDetailsForCommonJsProject({
1068
- projectRoot,
1069
- projectName
1070
- }) {
1071
- await Promise.all([touch__default["default"](`${projectRoot}/index.js`), fs.promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase__default["default"](projectName)} = require('.');\n`)]);
918
+ async function buildDetailsForCommonJsProject({projectRoot, projectName}) {
919
+ await Promise.all([
920
+ touch__default["default"](`${projectRoot}/index.js`),
921
+ fs.promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase__default["default"](projectName)} = require('.');\n`)
922
+ ]);
923
+
1072
924
  return {};
1073
925
  }
1074
926
 
@@ -1081,42 +933,42 @@ async function buildDetails ({
1081
933
  dialect,
1082
934
  decisions
1083
935
  }) {
1084
- if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({
1085
- projectRoot,
1086
- projectName
1087
- });
1088
- const chosenBundler = await chooseBundler({
1089
- bundlers: packageBundlers,
1090
- decisions
1091
- });
936
+ if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
937
+
938
+ const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
939
+
1092
940
  const pathToCreatedSrcDirectory = await makeDir__default["default"](`${projectRoot}/src`);
1093
- const [bundlerResults] = await Promise.all([javascriptCore.scaffoldChoice(packageBundlers, chosenBundler, {
1094
- projectRoot,
1095
- dialect,
1096
- projectType: javascriptCore.projectTypes.PACKAGE
1097
- }), await createExample(projectRoot, projectName), touch__default["default"](`${pathToCreatedSrcDirectory}/index.js`)]);
1098
- return deepmerge__default["default"](bundlerResults, {
1099
- devDependencies: ['rimraf'],
1100
- scripts: {
1101
- clean: `rimraf ./${defaultBuildDirectory$2}`,
1102
- prebuild: 'run-s clean',
1103
- build: 'npm-run-all --print-label --parallel build:*',
1104
- prepack: 'run-s build'
1105
- },
1106
- vcsIgnore: {
1107
- directories: [`/${defaultBuildDirectory$2}/`]
1108
- },
1109
- buildDirectory: defaultBuildDirectory$2,
1110
- badges: {
1111
- consumer: _objectSpread2({}, 'Public' === visibility && {
1112
- runkit: {
1113
- img: `https://badge.runkitcdn.com/${packageName}.svg`,
1114
- text: `Try ${packageName} on RunKit`,
1115
- link: `https://npm.runkit.com/${packageName}`
941
+ const [bundlerResults] = await Promise.all([
942
+ javascriptCore.scaffoldChoice(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: javascriptCore.projectTypes.PACKAGE}),
943
+ await createExample(projectRoot, projectName),
944
+ touch__default["default"](`${pathToCreatedSrcDirectory}/index.js`)
945
+ ]);
946
+
947
+ return deepmerge__default["default"](
948
+ bundlerResults,
949
+ {
950
+ devDependencies: ['rimraf'],
951
+ scripts: {
952
+ clean: `rimraf ./${defaultBuildDirectory$2}`,
953
+ prebuild: 'run-s clean',
954
+ build: 'npm-run-all --print-label --parallel build:*',
955
+ prepack: 'run-s build'
956
+ },
957
+ vcsIgnore: {directories: [`/${defaultBuildDirectory$2}/`]},
958
+ buildDirectory: defaultBuildDirectory$2,
959
+ badges: {
960
+ consumer: {
961
+ ...'Public' === visibility && {
962
+ runkit: {
963
+ img: `https://badge.runkitcdn.com/${packageName}.svg`,
964
+ text: `Try ${packageName} on RunKit`,
965
+ link: `https://npm.runkit.com/${packageName}`
966
+ }
967
+ }
1116
968
  }
1117
- })
969
+ }
1118
970
  }
1119
- });
971
+ );
1120
972
  }
1121
973
 
1122
974
  async function scaffoldPackageType ({
@@ -1134,78 +986,70 @@ async function scaffoldPackageType ({
1134
986
  publishRegistry
1135
987
  }) {
1136
988
  cliMessages.info('Scaffolding Package Details');
1137
- const [detailsForBuild] = await Promise.all([buildDetails({
1138
- projectRoot,
1139
- projectName,
1140
- packageBundlers,
1141
- visibility,
1142
- packageName,
1143
- dialect,
1144
- decisions
1145
- }), javascriptCore.mergeIntoExistingPackageJson({
1146
- projectRoot,
1147
- config: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
1148
- files: ['example.js', ...(javascriptCore.dialects.COMMON_JS === dialect ? ['index.js'] : ['lib/'])],
1149
- publishConfig: _objectSpread2({
1150
- access: 'Public' === visibility ? 'public' : 'restricted'
1151
- }, publishRegistry && {
1152
- registry: publishRegistry
1153
- }),
1154
- sideEffects: false
1155
- }, 'Public' === visibility && {
1156
- runkitExampleFilename: './example.js'
1157
- }), javascriptCore.dialects.BABEL === dialect && {
1158
- main: './lib/index.cjs.js',
1159
- module: './lib/index.es.js',
1160
- exports: {
1161
- require: './lib/index.cjs.js',
1162
- import: './lib/index.es.js'
1163
- }
1164
- }), javascriptCore.dialects.ESM === dialect && {
1165
- main: './lib/index.es.js',
1166
- exports: './lib/index.es.js'
1167
- }), javascriptCore.dialects.TYPESCRIPT === dialect && {
1168
- main: './lib/index.cjs.js',
1169
- module: './lib/index.es.js',
1170
- types: './lib/index.d.ts',
1171
- exports: {
1172
- types: './lib/index.d.ts',
1173
- require: './lib/index.cjs.js',
1174
- import: './lib/index.es.js'
989
+
990
+ const [detailsForBuild] = await Promise.all([
991
+ buildDetails({projectRoot, projectName, packageBundlers, visibility, packageName, dialect, decisions}),
992
+ javascriptCore.mergeIntoExistingPackageJson({
993
+ projectRoot,
994
+ config: {
995
+ files: ['example.js', ...javascriptCore.dialects.COMMON_JS === dialect ? ['index.js'] : ['lib/']],
996
+ publishConfig: {
997
+ access: 'Public' === visibility ? 'public' : 'restricted',
998
+ ...publishRegistry && {registry: publishRegistry}
999
+ },
1000
+ sideEffects: false,
1001
+ ...'Public' === visibility && {runkitExampleFilename: './example.js'},
1002
+ ...javascriptCore.dialects.BABEL === dialect && {
1003
+ main: './lib/index.cjs.js',
1004
+ module: './lib/index.es.js',
1005
+ exports: {
1006
+ require: './lib/index.cjs.js',
1007
+ import: './lib/index.es.js'
1008
+ }
1009
+ },
1010
+ ...javascriptCore.dialects.ESM === dialect && {
1011
+ main: './lib/index.es.js',
1012
+ exports: './lib/index.es.js'
1013
+ },
1014
+ ...javascriptCore.dialects.TYPESCRIPT === dialect && {
1015
+ main: './lib/index.cjs.js',
1016
+ module: './lib/index.es.js',
1017
+ types: './lib/index.d.ts',
1018
+ exports: {
1019
+ types: './lib/index.d.ts',
1020
+ require: './lib/index.cjs.js',
1021
+ import: './lib/index.es.js'
1022
+ }
1023
+ }
1175
1024
  }
1176
1025
  })
1177
- })]);
1178
- const chosenType = await chooseApplicationType({
1179
- types: packageTypes,
1180
- projectType: 'package',
1181
- decisions
1182
- });
1183
- const results = await javascriptCore.scaffoldChoice(packageTypes, chosenType, {
1184
- projectRoot,
1185
- projectName,
1186
- packageName,
1187
- tests,
1188
- scope
1189
- });
1190
- return deepmerge__default["default"].all([{
1191
- documentation: scaffoldPackageDocumentation({
1192
- packageName,
1193
- visibility,
1194
- scope,
1195
- packageManager
1196
- }),
1197
- eslintConfigs: [],
1198
- nextSteps: [{
1199
- summary: 'Add the appropriate `save` flag to the installation instructions in the README'
1200
- }, {
1201
- summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'
1202
- }],
1203
- scripts: {},
1204
- badges: defineBadges(packageName, visibility)
1205
- }, detailsForBuild, results]);
1026
+ ]);
1027
+
1028
+ const chosenType = await chooseApplicationType({types: packageTypes, projectType: 'package', decisions});
1029
+ const results = await javascriptCore.scaffoldChoice(
1030
+ packageTypes,
1031
+ chosenType,
1032
+ {projectRoot, projectName, packageName, tests, scope}
1033
+ );
1034
+
1035
+ return deepmerge__default["default"].all([
1036
+ {
1037
+ documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager}),
1038
+ eslintConfigs: [],
1039
+ nextSteps: [
1040
+ {summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
1041
+ {summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
1042
+ ],
1043
+ scripts: {},
1044
+ badges: defineBadges(packageName, visibility)
1045
+ },
1046
+ detailsForBuild,
1047
+ results
1048
+ ]);
1206
1049
  }
1207
1050
 
1208
1051
  const defaultBuildDirectory$1 = 'lib';
1052
+
1209
1053
  async function scaffoldApplicationType ({
1210
1054
  applicationTypes,
1211
1055
  projectRoot,
@@ -1216,112 +1060,94 @@ async function scaffoldApplicationType ({
1216
1060
  decisions
1217
1061
  }) {
1218
1062
  cliMessages.info('Scaffolding Application Details');
1219
- const [chosenType] = await Promise.all([chooseApplicationType({
1220
- types: applicationTypes,
1221
- projectType: 'application',
1222
- decisions
1223
- }), javascriptCore.mergeIntoExistingPackageJson({
1224
- projectRoot,
1225
- config: {
1226
- private: true
1227
- }
1228
- })]);
1229
- const results = await javascriptCore.scaffoldChoice(applicationTypes, chosenType, {
1230
- projectRoot,
1231
- projectName,
1232
- packageName,
1233
- packageManager,
1234
- tests
1235
- });
1063
+
1064
+ const [chosenType] = await Promise.all([
1065
+ chooseApplicationType({types: applicationTypes, projectType: 'application', decisions}),
1066
+ javascriptCore.mergeIntoExistingPackageJson({projectRoot, config: {private: true}})
1067
+ ]);
1068
+
1069
+ const results = await javascriptCore.scaffoldChoice(
1070
+ applicationTypes,
1071
+ chosenType,
1072
+ {projectRoot, projectName, packageName, packageManager, tests}
1073
+ );
1074
+
1236
1075
  const buildDirectory = results.buildDirectory || defaultBuildDirectory$1;
1237
- return deepmerge__default["default"]({
1238
- scripts: {
1239
- clean: `rimraf ./${buildDirectory}`,
1240
- start: `node ./${buildDirectory}/index.js`,
1241
- prebuild: 'run-s clean'
1242
- },
1243
- dependencies: [],
1244
- devDependencies: ['rimraf'],
1245
- vcsIgnore: {
1246
- files: ['.env'],
1247
- directories: [`/${buildDirectory}/`]
1076
+
1077
+ return deepmerge__default["default"](
1078
+ {
1079
+ scripts: {
1080
+ clean: `rimraf ./${buildDirectory}`,
1081
+ start: `node ./${buildDirectory}/index.js`,
1082
+ prebuild: 'run-s clean'
1083
+ },
1084
+ dependencies: [],
1085
+ devDependencies: ['rimraf'],
1086
+ vcsIgnore: {files: ['.env'], directories: [`/${buildDirectory}/`]},
1087
+ buildDirectory,
1088
+ eslintConfigs: [],
1089
+ nextSteps: []
1248
1090
  },
1249
- buildDirectory,
1250
- eslintConfigs: [],
1251
- nextSteps: []
1252
- }, results);
1091
+ results
1092
+ );
1253
1093
  }
1254
1094
 
1255
- async function scaffoldMonorepoType ({
1256
- monorepoTypes,
1257
- projectRoot,
1258
- packageManager,
1259
- decisions
1260
- }) {
1095
+ async function scaffoldMonorepoType ({monorepoTypes, projectRoot, packageManager, decisions}) {
1261
1096
  cliMessages.info('Scaffolding Monorepo Details');
1262
- const chosenType = await chooseApplicationType({
1263
- types: monorepoTypes,
1264
- projectType: javascriptCore.projectTypes.MONOREPO,
1265
- decisions
1266
- });
1267
- const results = await javascriptCore.scaffoldChoice(monorepoTypes, chosenType, {
1268
- projectRoot,
1269
- packageManager
1270
- });
1271
- return deepmerge__default["default"]({
1272
- eslintConfigs: [],
1273
- packageProperties: {
1274
- private: true
1097
+
1098
+ const chosenType = await chooseApplicationType({types: monorepoTypes, projectType: javascriptCore.projectTypes.MONOREPO, decisions});
1099
+ const results = await javascriptCore.scaffoldChoice(monorepoTypes, chosenType, {projectRoot, packageManager});
1100
+
1101
+ return deepmerge__default["default"](
1102
+ {
1103
+ eslintConfigs: [],
1104
+ packageProperties: {private: true},
1105
+ nextSteps: [{
1106
+ summary: 'Add packages to your new monorepo',
1107
+ description: 'Leverage [@form8ion/add-package-to-monorepo](https://npm.im/@form8ion/add-package-to-monorepo)'
1108
+ + ' to scaffold new packages into your new monorepo'
1109
+ }]
1275
1110
  },
1276
- nextSteps: [{
1277
- summary: 'Add packages to your new monorepo',
1278
- description: 'Leverage [@form8ion/add-package-to-monorepo](https://npm.im/@form8ion/add-package-to-monorepo)' + ' to scaffold new packages into your new monorepo'
1279
- }]
1280
- }, results);
1111
+ results
1112
+ );
1281
1113
  }
1282
1114
 
1283
1115
  const defaultBuildDirectory = 'bin';
1284
- async function scaffoldCliType ({
1285
- packageName,
1286
- visibility,
1287
- projectRoot,
1288
- dialect,
1289
- publishRegistry
1290
- }) {
1291
- const [rollupResults] = await Promise.all([rollup.scaffold({
1292
- projectRoot,
1293
- dialect,
1294
- projectType: javascriptCore.projectTypes.CLI
1295
- }), javascriptCore.mergeIntoExistingPackageJson({
1296
- projectRoot,
1297
- config: {
1298
- bin: {},
1299
- files: [`${defaultBuildDirectory}/`],
1300
- publishConfig: _objectSpread2({
1301
- access: 'Public' === visibility ? 'public' : 'restricted'
1302
- }, publishRegistry && {
1303
- registry: publishRegistry
1304
- })
1116
+
1117
+ async function scaffoldCliType ({packageName, visibility, projectRoot, dialect, publishRegistry}) {
1118
+ const [rollupResults] = await Promise.all([
1119
+ rollup.scaffold({projectRoot, dialect, projectType: javascriptCore.projectTypes.CLI}),
1120
+ javascriptCore.mergeIntoExistingPackageJson({
1121
+ projectRoot,
1122
+ config: {
1123
+ bin: {},
1124
+ files: [`${defaultBuildDirectory}/`],
1125
+ publishConfig: {
1126
+ access: 'Public' === visibility ? 'public' : 'restricted',
1127
+ ...publishRegistry && {registry: publishRegistry}
1128
+ }
1129
+ }
1130
+ })
1131
+ ]);
1132
+
1133
+ return deepmerge__default["default"](
1134
+ rollupResults,
1135
+ {
1136
+ scripts: {
1137
+ clean: `rimraf ./${defaultBuildDirectory}`,
1138
+ prebuild: 'run-s clean',
1139
+ build: 'npm-run-all --print-label --parallel build:*',
1140
+ prepack: 'run-s build'
1141
+ },
1142
+ dependencies: ['update-notifier'],
1143
+ devDependencies: ['rimraf'],
1144
+ vcsIgnore: {files: [], directories: [`/${defaultBuildDirectory}/`]},
1145
+ buildDirectory: defaultBuildDirectory,
1146
+ badges: defineBadges(packageName, visibility),
1147
+ eslintConfigs: [],
1148
+ nextSteps: []
1305
1149
  }
1306
- })]);
1307
- return deepmerge__default["default"](rollupResults, {
1308
- scripts: {
1309
- clean: `rimraf ./${defaultBuildDirectory}`,
1310
- prebuild: 'run-s clean',
1311
- build: 'npm-run-all --print-label --parallel build:*',
1312
- prepack: 'run-s build'
1313
- },
1314
- dependencies: ['update-notifier'],
1315
- devDependencies: ['rimraf'],
1316
- vcsIgnore: {
1317
- files: [],
1318
- directories: [`/${defaultBuildDirectory}/`]
1319
- },
1320
- buildDirectory: defaultBuildDirectory,
1321
- badges: defineBadges(packageName, visibility),
1322
- eslintConfigs: [],
1323
- nextSteps: []
1324
- });
1150
+ );
1325
1151
  }
1326
1152
 
1327
1153
  async function scaffoldProjectType ({
@@ -1359,7 +1185,6 @@ async function scaffoldProjectType ({
1359
1185
  dialect,
1360
1186
  publishRegistry
1361
1187
  });
1362
-
1363
1188
  case javascriptCore.projectTypes.APPLICATION:
1364
1189
  return scaffoldApplicationType({
1365
1190
  projectRoot,
@@ -1370,29 +1195,14 @@ async function scaffoldProjectType ({
1370
1195
  tests,
1371
1196
  decisions
1372
1197
  });
1373
-
1374
1198
  case javascriptCore.projectTypes.CLI:
1375
- return scaffoldCliType({
1376
- packageName,
1377
- visibility,
1378
- projectRoot,
1379
- dialect,
1380
- publishRegistry
1381
- });
1382
-
1199
+ return scaffoldCliType({packageName, visibility, projectRoot, dialect, publishRegistry});
1383
1200
  case javascriptCore.projectTypes.MONOREPO:
1384
- return scaffoldMonorepoType({
1385
- monorepoTypes,
1386
- projectRoot,
1387
- packageManager,
1388
- decisions
1389
- });
1390
-
1201
+ return scaffoldMonorepoType({monorepoTypes, projectRoot, packageManager, decisions});
1391
1202
  case 'Other':
1392
1203
  return {
1393
1204
  eslintConfigs: []
1394
1205
  };
1395
-
1396
1206
  default:
1397
1207
  throw new Error(`The project-type of ${projectType} is invalid`);
1398
1208
  }
@@ -1401,48 +1211,39 @@ async function scaffoldProjectType ({
1401
1211
  async function scaffoldTesting ({
1402
1212
  projectRoot,
1403
1213
  visibility,
1404
- tests: {
1405
- unit,
1406
- integration
1407
- },
1214
+ tests: {unit, integration},
1408
1215
  vcs,
1409
1216
  unitTestFrameworks,
1410
1217
  decisions,
1411
1218
  dialect,
1412
1219
  pathWithinParent
1413
1220
  }) {
1414
- const unitResults = unit ? await scaffoldUnitTesting({
1415
- projectRoot,
1416
- visibility,
1417
- vcs,
1418
- frameworks: unitTestFrameworks,
1419
- decisions,
1420
- dialect,
1421
- pathWithinParent
1422
- }) : {};
1423
- return deepmerge__default["default"]({
1424
- devDependencies: [...(unit || integration ? ['@travi/any'] : [])],
1425
- eslint: {}
1426
- }, unitResults);
1221
+ const unitResults = unit
1222
+ ? await scaffoldUnitTesting({
1223
+ projectRoot,
1224
+ visibility,
1225
+ vcs,
1226
+ frameworks: unitTestFrameworks,
1227
+ decisions,
1228
+ dialect,
1229
+ pathWithinParent
1230
+ })
1231
+ : {};
1232
+
1233
+ return deepmerge__default["default"]({devDependencies: [...(unit || integration) ? ['@travi/any'] : []], eslint: {}}, unitResults);
1427
1234
  }
1428
1235
 
1429
- function scaffoldBanSensitiveFiles ({
1430
- pathWithinParent
1431
- }) {
1236
+ function scaffoldBanSensitiveFiles ({pathWithinParent}) {
1432
1237
  if (pathWithinParent) return {};
1433
- return {
1434
- scripts: {
1435
- 'lint:sensitive': 'ban'
1436
- },
1437
- devDependencies: ['ban-sensitive-files']
1438
- };
1238
+
1239
+ return {scripts: {'lint:sensitive': 'ban'}, devDependencies: ['ban-sensitive-files']};
1439
1240
  }
1440
1241
 
1441
- function buildAllowedHostsList ({
1442
- packageManager,
1443
- registries
1444
- }) {
1445
- return [...(!registries || registries && !registries.registry ? [packageManager] : []), ...Object.values(Object.fromEntries(Object.entries(registries).filter(([scope]) => 'publish' !== scope)))];
1242
+ function buildAllowedHostsList ({packageManager, registries}) {
1243
+ return [
1244
+ ...(!registries || (registries && !registries.registry)) ? [packageManager] : [],
1245
+ ...Object.values(Object.fromEntries(Object.entries(registries).filter(([scope]) => 'publish' !== scope)))
1246
+ ];
1446
1247
  }
1447
1248
 
1448
1249
  const lockfileLintSupportedPackageManagers = [javascriptCore.packageManagers.NPM, javascriptCore.packageManagers.YARN];
@@ -1452,6 +1253,7 @@ function determineLockfilePathFor(packageManager) {
1452
1253
  [javascriptCore.packageManagers.NPM]: 'package-lock.json',
1453
1254
  [javascriptCore.packageManagers.YARN]: 'yarn.lock'
1454
1255
  };
1256
+
1455
1257
  return lockfilePaths[packageManager];
1456
1258
  }
1457
1259
 
@@ -1459,46 +1261,35 @@ function lockfileLintSupports(packageManager) {
1459
1261
  return lockfileLintSupportedPackageManagers.includes(packageManager);
1460
1262
  }
1461
1263
 
1462
- async function scaffoldLockfileLint ({
1463
- projectRoot,
1464
- packageManager,
1465
- registries
1466
- }) {
1264
+ async function scaffoldLockfileLint ({projectRoot, packageManager, registries}) {
1467
1265
  if (!lockfileLintSupports(packageManager)) {
1468
- throw new Error(`The ${packageManager} package manager is currently not supported by lockfile-lint. ` + `Only ${lockfileLintSupportedPackageManagers.join(' and ')} are currently supported.`);
1266
+ throw new Error(
1267
+ `The ${packageManager} package manager is currently not supported by lockfile-lint. `
1268
+ + `Only ${lockfileLintSupportedPackageManagers.join(' and ')} are currently supported.`
1269
+ );
1469
1270
  }
1470
1271
 
1471
- await fs.promises.writeFile(`${projectRoot}/.lockfile-lintrc.json`, JSON.stringify({
1472
- path: determineLockfilePathFor(packageManager),
1473
- type: packageManager,
1474
- 'validate-https': true,
1475
- 'allowed-hosts': buildAllowedHostsList({
1476
- packageManager,
1477
- registries
1272
+ await fs.promises.writeFile(
1273
+ `${projectRoot}/.lockfile-lintrc.json`,
1274
+ JSON.stringify({
1275
+ path: determineLockfilePathFor(packageManager),
1276
+ type: packageManager,
1277
+ 'validate-https': true,
1278
+ 'allowed-hosts': buildAllowedHostsList({packageManager, registries})
1478
1279
  })
1479
- }));
1280
+ );
1281
+
1480
1282
  return {
1481
1283
  devDependencies: ['lockfile-lint'],
1482
- scripts: {
1483
- 'lint:lockfile': 'lockfile-lint'
1484
- }
1284
+ scripts: {'lint:lockfile': 'lockfile-lint'}
1485
1285
  };
1486
1286
  }
1487
1287
 
1488
- async function scaffoldLinting ({
1489
- projectRoot,
1490
- packageManager,
1491
- registries,
1492
- vcs,
1493
- pathWithinParent
1494
- }) {
1495
- return deepmerge__default["default"].all(await Promise.all([scaffoldLockfileLint({
1496
- projectRoot,
1497
- packageManager,
1498
- registries
1499
- }), vcs ? scaffoldBanSensitiveFiles({
1500
- pathWithinParent
1501
- }) : {}]));
1288
+ async function scaffoldLinting ({projectRoot, packageManager, registries, vcs, pathWithinParent}) {
1289
+ return deepmerge__default["default"].all(await Promise.all([
1290
+ scaffoldLockfileLint({projectRoot, packageManager, registries}),
1291
+ vcs ? scaffoldBanSensitiveFiles({pathWithinParent}) : {}
1292
+ ]));
1502
1293
  }
1503
1294
 
1504
1295
  async function scaffoldVerification({
@@ -1513,60 +1304,33 @@ async function scaffoldVerification({
1513
1304
  decisions,
1514
1305
  pathWithinParent
1515
1306
  }) {
1516
- const [testingResults, lintingResults, huskyResults] = await Promise.all([scaffoldTesting({
1517
- projectRoot,
1518
- tests,
1519
- visibility,
1520
- vcs,
1521
- unitTestFrameworks,
1522
- decisions,
1523
- dialect,
1524
- pathWithinParent
1525
- }), scaffoldLinting({
1526
- projectRoot,
1527
- packageManager,
1528
- registries,
1529
- vcs,
1530
- pathWithinParent
1531
- }), huskyPlugin.scaffold({
1532
- projectRoot,
1533
- packageManager,
1534
- pathWithinParent
1535
- })]);
1307
+ const [testingResults, lintingResults, huskyResults] = await Promise.all([
1308
+ scaffoldTesting({
1309
+ projectRoot,
1310
+ tests,
1311
+ visibility,
1312
+ vcs,
1313
+ unitTestFrameworks,
1314
+ decisions,
1315
+ dialect,
1316
+ pathWithinParent
1317
+ }),
1318
+ scaffoldLinting({projectRoot, packageManager, registries, vcs, pathWithinParent}),
1319
+ huskyPlugin.scaffold({projectRoot, packageManager, pathWithinParent})
1320
+ ]);
1321
+
1536
1322
  return deepmerge__default["default"].all([testingResults, lintingResults, huskyResults]);
1537
1323
  }
1538
1324
 
1539
- async function scaffoldEslint ({
1540
- config,
1541
- projectRoot,
1542
- buildDirectory,
1543
- additionalConfiguration
1544
- }) {
1545
- const {
1546
- scope
1547
- } = config;
1548
- const {
1549
- ignore
1550
- } = additionalConfiguration;
1551
- const ignores = deepmerge__default["default"](ignore, {
1552
- directories: [`/${buildDirectory}/`]
1553
- });
1554
- return eslint.scaffold({
1555
- scope,
1556
- projectRoot,
1557
- ignore: {
1558
- directories: ignores.directories
1559
- }
1560
- });
1325
+ async function scaffoldEslint ({config, projectRoot, buildDirectory, additionalConfiguration}) {
1326
+ const {scope} = config;
1327
+ const {ignore} = additionalConfiguration;
1328
+ const ignores = deepmerge__default["default"](ignore, {directories: [`/${buildDirectory}/`]});
1329
+
1330
+ return eslint.scaffold({scope, projectRoot, ignore: {directories: ignores.directories}});
1561
1331
  }
1562
1332
 
1563
- async function scaffoldRemark ({
1564
- config,
1565
- projectRoot,
1566
- projectType,
1567
- vcs,
1568
- dialect
1569
- }) {
1333
+ async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
1570
1334
  await configFile.write({
1571
1335
  format: core.fileTypes.JSON,
1572
1336
  path: projectRoot,
@@ -1579,28 +1343,30 @@ async function scaffoldRemark ({
1579
1343
  bullet: '*',
1580
1344
  incrementListMarker: false
1581
1345
  },
1582
- plugins: [config, ['remark-toc', {
1583
- tight: true
1584
- }], ...(javascriptCore.projectTypes.PACKAGE === projectType ? [['remark-usage', {
1585
- heading: 'example'
1586
- }]] : []), ...(!vcs ? [['validate-links', {
1587
- repository: false
1588
- }]] : [])]
1346
+ plugins: [
1347
+ config,
1348
+ ['remark-toc', {tight: true}],
1349
+ ...javascriptCore.projectTypes.PACKAGE === projectType ? [['remark-usage', {heading: 'example'}]] : [],
1350
+ ...!vcs ? [['validate-links', {repository: false}]] : []
1351
+ ]
1589
1352
  }
1590
1353
  });
1591
- return deepmerge__default["default"]({
1592
- devDependencies: [config, 'remark-cli', 'remark-toc'],
1593
- scripts: {
1594
- 'lint:md': 'remark . --frail',
1595
- 'generate:md': 'remark . --output'
1596
- }
1597
- }, _objectSpread2({}, javascriptCore.projectTypes.PACKAGE === projectType && _objectSpread2({
1598
- devDependencies: ['remark-usage']
1599
- }, javascriptCore.dialects.COMMON_JS !== dialect && {
1600
- scripts: {
1601
- 'pregenerate:md': 'run-s build'
1354
+
1355
+ return deepmerge__default["default"](
1356
+ {
1357
+ devDependencies: [config, 'remark-cli', 'remark-toc'],
1358
+ scripts: {
1359
+ 'lint:md': 'remark . --frail',
1360
+ 'generate:md': 'remark . --output'
1361
+ }
1362
+ },
1363
+ {
1364
+ ...javascriptCore.projectTypes.PACKAGE === projectType && {
1365
+ devDependencies: ['remark-usage'],
1366
+ ...javascriptCore.dialects.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
1367
+ }
1602
1368
  }
1603
- })));
1369
+ );
1604
1370
  }
1605
1371
 
1606
1372
  async function scaffoldCodeStyle ({
@@ -1613,22 +1379,28 @@ async function scaffoldCodeStyle ({
1613
1379
  buildDirectory,
1614
1380
  eslint
1615
1381
  }) {
1616
- return deepmerge__default["default"].all(await Promise.all([configs.eslint && configureLinting ? scaffoldEslint({
1617
- projectRoot,
1618
- config: configs.eslint,
1619
- buildDirectory,
1620
- additionalConfiguration: eslint
1621
- }) : {}, scaffoldRemark({
1622
- projectRoot,
1623
- projectType,
1624
- dialect,
1625
- vcs,
1626
- config: configs.remark || '@form8ion/remark-lint-preset'
1627
- })]));
1382
+ return deepmerge__default["default"].all(await Promise.all([
1383
+ configs.eslint && configureLinting
1384
+ && scaffoldEslint({
1385
+ projectRoot,
1386
+ config: configs.eslint,
1387
+ buildDirectory,
1388
+ additionalConfiguration: eslint
1389
+ }),
1390
+ scaffoldRemark({
1391
+ projectRoot,
1392
+ projectType,
1393
+ dialect,
1394
+ vcs,
1395
+ config: configs.remark || '@form8ion/remark-lint-preset'
1396
+ }),
1397
+ prettier.scaffold({projectRoot, config: configs.prettier})
1398
+ ].filter(Boolean)));
1628
1399
  }
1629
1400
 
1630
1401
  async function scaffolder (options) {
1631
1402
  cliMessages.info('Initializing JavaScript project');
1403
+
1632
1404
  const {
1633
1405
  projectRoot,
1634
1406
  projectName,
@@ -1649,6 +1421,7 @@ async function scaffolder (options) {
1649
1421
  pathWithinParent,
1650
1422
  registries
1651
1423
  } = validate(options);
1424
+
1652
1425
  const {
1653
1426
  tests,
1654
1427
  projectType,
@@ -1661,13 +1434,11 @@ async function scaffolder (options) {
1661
1434
  packageManager,
1662
1435
  dialect
1663
1436
  } = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
1664
- cliMessages.info('Writing project files', {
1665
- level: 'secondary'
1666
- });
1437
+
1438
+ cliMessages.info('Writing project files', {level: 'secondary'});
1439
+
1667
1440
  const packageName = buildPackageName(projectName, scope);
1668
- const {
1669
- homepage: projectHomepage
1670
- } = await scaffoldPackage({
1441
+ const {homepage: projectHomepage} = await scaffoldPackage({
1671
1442
  projectRoot,
1672
1443
  projectType,
1673
1444
  dialect,
@@ -1678,111 +1449,106 @@ async function scaffolder (options) {
1678
1449
  description,
1679
1450
  pathWithinParent
1680
1451
  });
1681
- const [projectTypeResults, verificationResults] = await Promise.all([scaffoldProjectType({
1682
- projectType,
1683
- projectRoot,
1684
- projectName,
1685
- packageName,
1686
- packageManager,
1687
- visibility,
1688
- applicationTypes,
1689
- packageTypes,
1690
- packageBundlers,
1691
- monorepoTypes,
1692
- scope,
1693
- tests,
1694
- vcs,
1695
- decisions,
1696
- dialect,
1697
- publishRegistry: registries.publish
1698
- }), scaffoldVerification({
1699
- projectRoot,
1700
- dialect,
1701
- visibility,
1702
- packageManager,
1703
- vcs,
1704
- registries,
1705
- tests,
1706
- unitTestFrameworks,
1707
- decisions,
1708
- pathWithinParent
1709
- })]);
1710
- const [nodeVersion, npmResults, dialectResults, codeStyleResults] = await Promise.all([scaffoldNodeVersion({
1711
- projectRoot,
1712
- nodeVersionCategory
1713
- }), scaffoldNpmConfig({
1714
- projectType,
1715
- projectRoot,
1716
- registries
1717
- }), scaffoldDialect({
1718
- dialect,
1719
- configs,
1720
- projectRoot,
1721
- projectType,
1722
- buildDirectory: projectTypeResults.buildDirectory,
1723
- testFilenamePattern: verificationResults.testFilenamePattern
1724
- }), scaffoldCodeStyle({
1725
- projectRoot,
1726
- projectType,
1727
- dialect,
1728
- configs,
1729
- vcs,
1730
- configureLinting,
1731
- buildDirectory: projectTypeResults.buildDirectory,
1732
- eslint: verificationResults.eslint
1733
- })]);
1734
- const mergedContributions = deepmerge__default["default"].all([...(await Promise.all([javascriptCore.scaffoldChoice(hosts, chosenHost, {
1735
- buildDirectory: `./${projectTypeResults.buildDirectory}`,
1736
- projectRoot,
1737
- projectName,
1738
- nodeVersion
1739
- }), javascriptCore.scaffoldChoice(ciServices, ci, {
1740
- projectRoot,
1741
- vcs,
1742
- visibility,
1743
- projectType,
1744
- projectName,
1745
- nodeVersion,
1746
- tests
1747
- }), commitConventionPlugin.scaffold({
1748
- projectRoot,
1749
- projectType,
1750
- configs,
1751
- pathWithinParent
1752
- })])), projectTypeResults, verificationResults, codeStyleResults, npmResults, dialectResults]);
1452
+ const [projectTypeResults, verificationResults] = await Promise.all([
1453
+ scaffoldProjectType({
1454
+ projectType,
1455
+ projectRoot,
1456
+ projectName,
1457
+ packageName,
1458
+ packageManager,
1459
+ visibility,
1460
+ applicationTypes,
1461
+ packageTypes,
1462
+ packageBundlers,
1463
+ monorepoTypes,
1464
+ scope,
1465
+ tests,
1466
+ vcs,
1467
+ decisions,
1468
+ dialect,
1469
+ publishRegistry: registries.publish
1470
+ }),
1471
+ scaffoldVerification({
1472
+ projectRoot,
1473
+ dialect,
1474
+ visibility,
1475
+ packageManager,
1476
+ vcs,
1477
+ registries,
1478
+ tests,
1479
+ unitTestFrameworks,
1480
+ decisions,
1481
+ pathWithinParent
1482
+ })
1483
+ ]);
1484
+ const [nodeVersion, npmResults, dialectResults, codeStyleResults] = await Promise.all([
1485
+ scaffoldNodeVersion({projectRoot, nodeVersionCategory}),
1486
+ scaffoldNpmConfig({projectType, projectRoot, registries}),
1487
+ scaffoldDialect({
1488
+ dialect,
1489
+ configs,
1490
+ projectRoot,
1491
+ projectType,
1492
+ buildDirectory: projectTypeResults.buildDirectory,
1493
+ testFilenamePattern: verificationResults.testFilenamePattern
1494
+ }),
1495
+ scaffoldCodeStyle({
1496
+ projectRoot,
1497
+ projectType,
1498
+ dialect,
1499
+ configs,
1500
+ vcs,
1501
+ configureLinting,
1502
+ buildDirectory: projectTypeResults.buildDirectory,
1503
+ eslint: verificationResults.eslint
1504
+ })
1505
+ ]);
1506
+ const mergedContributions = deepmerge__default["default"].all([
1507
+ ...(await Promise.all([
1508
+ javascriptCore.scaffoldChoice(
1509
+ hosts,
1510
+ chosenHost,
1511
+ {buildDirectory: `./${projectTypeResults.buildDirectory}`, projectRoot, projectName, nodeVersion}
1512
+ ),
1513
+ javascriptCore.scaffoldChoice(ciServices, ci, {projectRoot, vcs, visibility, projectType, projectName, nodeVersion, tests}),
1514
+ commitConventionPlugin.scaffold({projectRoot, projectType, configs, pathWithinParent})
1515
+ ])),
1516
+ projectTypeResults,
1517
+ verificationResults,
1518
+ codeStyleResults,
1519
+ npmResults,
1520
+ dialectResults
1521
+ ]);
1522
+
1753
1523
  const liftResults = await lift({
1754
- results: deepmerge__default["default"]({
1755
- devDependencies: ['npm-run-all'],
1756
- packageManager
1757
- }, mergedContributions),
1524
+ results: deepmerge__default["default"]({devDependencies: ['npm-run-all'], packageManager}, mergedContributions),
1758
1525
  projectRoot,
1759
1526
  configs,
1760
1527
  vcs
1761
1528
  });
1529
+
1762
1530
  return {
1763
1531
  badges: buildBadgesDetails([mergedContributions, liftResults]),
1764
- documentation: scaffoldDocumentation({
1765
- projectTypeResults,
1766
- packageManager
1767
- }),
1532
+ documentation: scaffoldDocumentation({projectTypeResults, packageManager}),
1768
1533
  tags: projectTypeResults.tags,
1769
1534
  vcsIgnore: buildVcsIgnoreLists(mergedContributions.vcsIgnore),
1770
1535
  verificationCommand: `${buildDocumentationCommand(packageManager)} && ${packageManager} test`,
1771
- projectDetails: _objectSpread2({}, projectHomepage && {
1772
- homepage: projectHomepage
1773
- }),
1536
+ projectDetails: {...projectHomepage && {homepage: projectHomepage}},
1774
1537
  nextSteps: mergedContributions.nextSteps
1775
1538
  };
1776
1539
  }
1777
1540
 
1778
- async function test ({
1779
- projectRoot
1780
- }) {
1781
- const [nvmIsConfigured, packageLockExists, yarnLockExists] = await Promise.all([core.fileExists(`${projectRoot}/.nvmrc`), core.fileExists(`${projectRoot}/package-lock.json`), core.fileExists(`${projectRoot}/yarn.lock`)]);
1541
+ async function test ({projectRoot}) {
1542
+ const [nvmIsConfigured, packageLockExists, yarnLockExists] = await Promise.all([
1543
+ core.fileExists(`${projectRoot}/.nvmrc`),
1544
+ core.fileExists(`${projectRoot}/package-lock.json`),
1545
+ core.fileExists(`${projectRoot}/yarn.lock`)
1546
+ ]);
1547
+
1782
1548
  return nvmIsConfigured || packageLockExists || yarnLockExists;
1783
1549
  }
1784
1550
 
1785
- const questionNames = _objectSpread2(_objectSpread2({}, languageScaffolderPrompts.questionNames), questionNames$1);
1551
+ const questionNames = {...languageScaffolderPrompts.questionNames, ...questionNames$1};
1786
1552
 
1787
1553
  exports.lift = lift;
1788
1554
  exports.questionNames = questionNames;