@form8ion/javascript 6.0.9 → 6.1.0-alpha.3

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,94 @@ 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
+ prettier: joi__default["default"].object({scope: joi__default["default"].string().regex(/^@[a-z0-9-]+$/i, 'scope').required()}),
411
+ commitlint: joi__default["default"].object({
412
+ packageName: joi__default["default"].string().required(),
413
+ name: joi__default["default"].string().required()
414
+ }),
415
+ babelPreset: joi__default["default"].object({
416
+ packageName: joi__default["default"].string().required(),
417
+ name: joi__default["default"].string().required()
418
+ }),
419
+ remark: joi__default["default"].string()
420
+ }).default({})
421
+ })
422
+ .keys({
423
+ overrides: joi__default["default"].object({
424
+ npmAccount: joi__default["default"].string(),
425
+ author: joi__default["default"].object({
426
+ name: joi__default["default"].string().required(),
427
+ email: joi__default["default"].string().email(),
428
+ url: joi__default["default"].string().uri()
429
+ })
430
+ }).default({})
431
+ })
432
+ .keys({
433
+ ciServices: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
434
+ scaffolder: joi__default["default"].func().arity(1).required(),
435
+ public: joi__default["default"].boolean(),
436
+ private: joi__default["default"].boolean()
437
+ })).default({})
438
+ })
439
+ .keys({
440
+ hosts: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
441
+ scaffolder: joi__default["default"].func().arity(1).required(),
442
+ projectTypes: joi__default["default"].array().items(joi__default["default"].string().valid('static', 'node')).default([])
443
+ })).default({})
444
+ })
445
+ .keys({
446
+ applicationTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
447
+ scaffolder: joi__default["default"].func().arity(1).required()
448
+ })).default({}),
449
+ packageTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
450
+ scaffolder: joi__default["default"].func().arity(1).required()
451
+ })).default({}),
452
+ monorepoTypes: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
453
+ scaffolder: joi__default["default"].func().arity(1).required()
454
+ }))
455
+ })
456
+ .keys({
457
+ unitTestFrameworks: unitTestFrameworksSchema,
458
+ packageBundlers: packageBundlersSchema
459
+ })
460
+ .keys({
461
+ decisions: joi__default["default"].object()
462
+ })
463
+ .keys({registries: joi__default["default"].object().pattern(joi__default["default"].string(), joi__default["default"].string().uri()).default({})});
464
+ const {error, value} = schema.validate(options);
465
+
590
466
  hoek__default["default"].assert(!error, error);
467
+
591
468
  return value;
592
469
  }
593
470
 
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
- }] : [])];
471
+ function buildDialectChoices ({babelPreset, typescript}) {
472
+ return [
473
+ {name: 'Common JS (no transpilation)', value: javascriptCore.dialects.COMMON_JS, short: 'cjs'},
474
+ ...babelPreset ? [{name: 'Modern JavaScript (transpiled)', value: javascriptCore.dialects.BABEL, short: 'modern'}] : [],
475
+ {name: 'ESM-only (no transpilation)', value: javascriptCore.dialects.ESM, short: 'esm'},
476
+ ...typescript ? [{name: 'TypeScript', value: javascriptCore.dialects.TYPESCRIPT, short: 'ts'}] : []
477
+ ];
615
478
  }
616
479
 
617
480
  function projectIsPackage(answers) {
@@ -637,9 +500,11 @@ function willBePublishedToNpm(answers) {
637
500
  function shouldBeScopedPromptShouldBePresented(answers) {
638
501
  return willBePublishedToNpm(answers);
639
502
  }
503
+
640
504
  function scopePromptShouldBePresentedFactory(visibility) {
641
505
  return answers => willBePublishedToNpm(answers) && packageShouldBeScoped(visibility, answers);
642
506
  }
507
+
643
508
  function lintingPromptShouldBePresented({
644
509
  [languageScaffolderPrompts.questionNames.UNIT_TESTS]: unitTested,
645
510
  [languageScaffolderPrompts.questionNames.INTEGRATION_TESTS]: integrationTested
@@ -657,38 +522,45 @@ function scope(visibility) {
657
522
  };
658
523
  }
659
524
 
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) {
525
+ function authorQuestions({name, email, url}) {
526
+ return [
527
+ {
528
+ name: questionNames$1.AUTHOR_NAME,
529
+ message: 'What is the author\'s name?',
530
+ default: name
531
+ },
532
+ {
533
+ name: questionNames$1.AUTHOR_EMAIL,
534
+ message: 'What is the author\'s email?',
535
+ default: email
536
+ },
537
+ {
538
+ name: questionNames$1.AUTHOR_URL,
539
+ message: 'What is the author\'s website url?',
540
+ default: url
541
+ }
542
+ ];
543
+ }
544
+
545
+ async function prompt(
546
+ {npmAccount, author},
547
+ ciServices,
548
+ hosts,
549
+ visibility,
550
+ vcs,
551
+ decisions,
552
+ configs,
553
+ pathWithinParent
554
+ ) {
684
555
  const npmConf = npmConf__default["default"]();
685
- let maybeLoggedInNpmUsername;
686
556
 
557
+ let maybeLoggedInNpmUsername;
687
558
  try {
688
559
  maybeLoggedInNpmUsername = (await execa__default["default"]('npm', ['whoami'])).stdout;
689
560
  } catch (failedExecutionResult) {
690
561
  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.');
562
+ cliMessages.warn('No logged in user found with `npm whoami`. Login with `npm login` '
563
+ + 'to use your npm account name as the package scope default.');
692
564
  }
693
565
  }
694
566
 
@@ -706,89 +578,85 @@ async function prompt({
706
578
  [questionNames$1.CONFIGURE_LINTING]: configureLinting,
707
579
  [questionNames$1.PACKAGE_MANAGER]: packageManager,
708
580
  [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
581
+ } = await overridablePrompts.prompt([
582
+ {
583
+ name: questionNames$1.DIALECT,
584
+ message: 'Which JavaScript dialect should this project follow?',
585
+ type: 'list',
586
+ choices: buildDialectChoices(configs),
587
+ default: 'babel'
588
+ },
589
+ ...pathWithinParent ? [] : [{
590
+ name: questionNames$1.NODE_VERSION_CATEGORY,
591
+ message: 'What node.js version should be used?',
592
+ type: 'list',
593
+ choices: ['LTS', 'Latest'],
594
+ default: 'LTS'
595
+ }],
596
+ {
597
+ name: questionNames$1.PACKAGE_MANAGER,
598
+ message: 'Which package manager will be used with this project?',
599
+ type: 'list',
600
+ choices: Object.values(javascriptCore.packageManagers),
601
+ default: javascriptCore.packageManagers.NPM
602
+ },
603
+ {
604
+ name: questionNames$1.PROJECT_TYPE,
605
+ message: 'What type of JavaScript project is this?',
606
+ type: 'list',
607
+ choices: [...Object.values(javascriptCore.projectTypes), new overridablePrompts.Separator(), 'Other'],
608
+ default: javascriptCore.projectTypes.PACKAGE
609
+ },
610
+ ...'Private' === visibility ? [] : [{
611
+ name: questionNames$1.SHOULD_BE_SCOPED,
612
+ message: 'Should this package be scoped?',
613
+ type: 'confirm',
614
+ when: shouldBeScopedPromptShouldBePresented,
615
+ default: true
616
+ }],
617
+ {
618
+ name: questionNames$1.SCOPE,
619
+ message: 'What is the scope?',
620
+ when: scopePromptShouldBePresentedFactory(visibility),
621
+ validate: scope(visibility),
622
+ default: npmAccount || maybeLoggedInNpmUsername
623
+ },
624
+ ...authorQuestions(author || {
625
+ name: npmConf.get('init.author.name'),
626
+ email: npmConf.get('init.author.email'),
627
+ url: npmConf.get('init.author.url')
628
+ }),
629
+ ...languageScaffolderPrompts.questions(({vcs, ciServices, visibility, pathWithinParent})),
630
+ {
631
+ name: questionNames$1.CONFIGURE_LINTING,
632
+ message: 'Will there be source code that should be linted?',
633
+ type: 'confirm',
634
+ when: lintingPromptShouldBePresented
770
635
  },
636
+ {
637
+ name: questionNames$1.HOST,
638
+ type: 'list',
639
+ message: 'Where will the application be hosted?',
640
+ when: projectIsApplication,
641
+ choices: [...Object.keys(hosts), new overridablePrompts.Separator(), 'Other']
642
+ }
643
+ ], decisions);
644
+
645
+ return {
646
+ tests: {unit: unitTested, integration: integrationTested},
771
647
  projectType,
772
648
  ci,
773
649
  chosenHost,
774
650
  scope: scope$1,
775
651
  nodeVersionCategory,
776
- author: {
777
- name: authorName,
778
- email: authorEmail,
779
- url: authorUrl
780
- },
652
+ author: {name: authorName, email: authorEmail, url: authorUrl},
781
653
  configureLinting: false !== configureLinting,
782
654
  packageManager,
783
655
  dialect
784
656
  };
785
657
  }
786
658
 
787
- async function scaffoldBabel ({
788
- projectRoot,
789
- preset,
790
- buildDirectory
791
- }) {
659
+ async function scaffoldBabel ({projectRoot, preset, buildDirectory}) {
792
660
  if (!preset) {
793
661
  throw new Error('No babel preset provided. Cannot configure babel transpilation');
794
662
  }
@@ -797,74 +665,50 @@ async function scaffoldBabel ({
797
665
  path: projectRoot,
798
666
  name: 'babel',
799
667
  format: core.fileTypes.JSON,
800
- config: {
801
- presets: [preset.name],
802
- ignore: [`./${buildDirectory}/`]
803
- }
668
+ config: {presets: [preset.name], ignore: [`./${buildDirectory}/`]}
804
669
  });
670
+
805
671
  return {
806
672
  devDependencies: ['@babel/register', preset.packageName],
807
673
  eslint: {}
808
674
  };
809
675
  }
810
676
 
811
- async function scaffoldTypescript ({
812
- config,
813
- projectType,
814
- projectRoot,
815
- testFilenamePattern
816
- }) {
677
+ async function scaffoldTypescript ({config, projectType, projectRoot, testFilenamePattern}) {
817
678
  const eslintConfigs = ['typescript'];
818
679
  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
- })));
680
+
681
+ await fs.promises.writeFile(
682
+ `${projectRoot}/tsconfig.json`,
683
+ JSON.stringify({
684
+ $schema: 'https://json.schemastore.org/tsconfig',
685
+ extends: shareableTsConfigPackage,
686
+ compilerOptions: {
687
+ rootDir: 'src',
688
+ ...javascriptCore.projectTypes.PACKAGE === projectType && {
689
+ outDir: 'lib',
690
+ declaration: true
691
+ }
692
+ },
693
+ include: ['src/**/*.ts'],
694
+ ...testFilenamePattern && {exclude: [testFilenamePattern]}
695
+ })
696
+ );
697
+
832
698
  return {
833
- eslint: {
834
- configs: eslintConfigs
835
- },
699
+ eslint: {configs: eslintConfigs},
836
700
  eslintConfigs,
837
701
  devDependencies: ['typescript', shareableTsConfigPackage],
838
- vcsIgnore: {
839
- files: ['tsconfig.tsbuildinfo']
840
- }
702
+ vcsIgnore: {files: ['tsconfig.tsbuildinfo']}
841
703
  };
842
704
  }
843
705
 
844
- function scaffoldDialect ({
845
- dialect,
846
- projectType,
847
- projectRoot,
848
- configs,
849
- buildDirectory,
850
- testFilenamePattern
851
- }) {
706
+ function scaffoldDialect ({dialect, projectType, projectRoot, configs, buildDirectory, testFilenamePattern}) {
852
707
  switch (dialect) {
853
708
  case javascriptCore.dialects.BABEL:
854
- return scaffoldBabel({
855
- preset: configs.babelPreset,
856
- projectRoot,
857
- buildDirectory
858
- });
859
-
709
+ return scaffoldBabel({preset: configs.babelPreset, projectRoot, buildDirectory});
860
710
  case javascriptCore.dialects.TYPESCRIPT:
861
- return scaffoldTypescript({
862
- config: configs.typescript,
863
- projectType,
864
- projectRoot,
865
- testFilenamePattern
866
- });
867
-
711
+ return scaffoldTypescript({config: configs.typescript, projectType, projectRoot, testFilenamePattern});
868
712
  default:
869
713
  return {};
870
714
  }
@@ -879,34 +723,38 @@ async function scaffoldNpmConfig ({
879
723
  projectType,
880
724
  registries
881
725
  }) {
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
- };
726
+ await fs.promises.writeFile(
727
+ `${projectRoot}/.npmrc`,
728
+ ini.stringify({
729
+ 'update-notifier': false,
730
+ ...projectWillNotBeConsumed(projectType) && {'save-exact': true},
731
+ ...Object.fromEntries(Object.entries(registries)
732
+ .filter(([scope]) => 'publish' !== scope)
733
+ .map(([scope, url]) => {
734
+ if ('registry' === scope) return ['registry', url];
735
+
736
+ return [`@${scope}:registry`, url];
737
+ }))
738
+ })
739
+ );
740
+
741
+ return {scripts: {'lint:peer': 'npm ls >/dev/null'}};
895
742
  }
896
743
 
897
744
  function buildDocumentationCommand (packageManager) {
898
745
  if (javascriptCore.packageManagers.NPM === packageManager) return 'npm run generate:md';
899
746
  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.`);
747
+
748
+ throw new Error(
749
+ `The ${packageManager} package manager is currently not supported. `
750
+ + `Only ${Object.values(javascriptCore.packageManagers).join(' and ')} are currently supported.`
751
+ );
901
752
  }
902
753
 
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), {}, {
754
+ function scaffoldDocumentation ({projectTypeResults, packageManager}) {
755
+ return {
756
+ toc: `Run \`${buildDocumentationCommand(packageManager)}\` to generate a table of contents`,
757
+ ...projectTypeResults.documentation,
910
758
  contributing: `### Dependencies
911
759
 
912
760
  \`\`\`sh
@@ -919,43 +767,43 @@ $ ${packageManager} install
919
767
  \`\`\`sh
920
768
  $ ${packageManager} test
921
769
  \`\`\``
922
- });
770
+ };
923
771
  }
924
772
 
925
773
  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
- });
774
+ cliMessages.info('Determining version of node', {level: 'secondary'});
775
+
776
+ const {stdout: nvmLsOutput} = await execa__default["default"](
777
+ `. ~/.nvm/nvm.sh && nvm ls-remote${('LTS' === nodeVersionCategory) ? ' --lts' : ''}`,
778
+ {shell: true}
779
+ );
780
+
934
781
  const lsLines = nvmLsOutput.split('\n');
935
782
  const lsLine = lsLines[lsLines.length - 2];
783
+
936
784
  return lsLine.match(/(v[0-9]+)\.[0-9]+\.[0-9]+/)[1];
937
785
  }
786
+
938
787
  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
- });
788
+ cliMessages.info(`Installing ${nodeVersionCategory} version of node using nvm`, {level: 'secondary'});
789
+
790
+ const subprocess = execa__default["default"]('. ~/.nvm/nvm.sh && nvm install', {shell: true});
945
791
  subprocess.stdout.pipe(process.stdout);
946
792
  return subprocess;
947
793
  }
948
794
 
949
- async function scaffoldNodeVersion ({
950
- projectRoot,
951
- nodeVersionCategory
952
- }) {
795
+ async function scaffoldNodeVersion ({projectRoot, nodeVersionCategory}) {
953
796
  if (!nodeVersionCategory) return undefined;
797
+
954
798
  const lowerCaseCategory = nodeVersionCategory.toLowerCase();
955
799
  cliMessages.info(`Configuring ${lowerCaseCategory} version of node`);
800
+
956
801
  const version = await determineLatestVersionOf(nodeVersionCategory);
802
+
957
803
  await fs.promises.writeFile(`${projectRoot}/.nvmrc`, version);
804
+
958
805
  await install(nodeVersionCategory);
806
+
959
807
  return version;
960
808
  }
961
809
 
@@ -966,54 +814,52 @@ function buildBadgesDetails (contributors) {
966
814
  function buildVcsIgnoreLists (vcsIgnoreLists = {}) {
967
815
  return {
968
816
  files: vcsIgnoreLists.files || [],
969
- directories: ['/node_modules/', ...(vcsIgnoreLists.directories || [])]
817
+ directories: ['/node_modules/', ...vcsIgnoreLists.directories || []]
970
818
  };
971
819
  }
972
820
 
973
821
  function buildPackageName (projectName, scope) {
974
822
  const name = `${scope ? `@${scope}/` : ''}${projectName}`;
975
- const {
976
- validForNewPackages,
977
- errors
978
- } = validatePackageName__default["default"](name);
823
+
824
+ const {validForNewPackages, errors} = validatePackageName__default["default"](name);
825
+
979
826
  if (validForNewPackages) return name;
980
827
  if (1 === errors.length && errors.includes('name cannot start with a period')) return projectName.slice(1);
828
+
981
829
  throw new Error(`The package name ${name} is invalid:${os.EOL}\t* ${errors.join(`${os.EOL}\t* `)}`);
982
830
  }
983
831
 
984
- async function chooseApplicationType ({
985
- types,
986
- projectType,
987
- decisions
988
- }) {
832
+ async function chooseApplicationType ({types, projectType, decisions}) {
989
833
  if (!Object.keys(types).length) return 'Other';
834
+
990
835
  const answers = await overridablePrompts.prompt([{
991
836
  name: questionNames$1.PROJECT_TYPE_CHOICE,
992
837
  type: 'list',
993
838
  message: `What type of ${projectType} is this?`,
994
839
  choices: [...Object.keys(types), new overridablePrompts.Separator(), 'Other']
995
840
  }], decisions);
841
+
996
842
  return answers[questionNames$1.PROJECT_TYPE_CHOICE];
997
843
  }
998
844
 
999
845
  function getInstallationCommand(packageManager) {
1000
846
  if (javascriptCore.packageManagers.NPM === packageManager) return 'npm install';
1001
847
  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.`);
848
+
849
+ throw new Error(
850
+ `The ${packageManager} package manager is currently not supported. `
851
+ + `Only ${Object.values(javascriptCore.packageManagers).join(' and ')} are currently supported.`
852
+ );
1003
853
  }
1004
854
 
1005
- function scaffoldPackageDocumentation ({
1006
- scope,
1007
- packageName,
1008
- packageManager,
1009
- visibility
1010
- }) {
855
+ function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility}) {
1011
856
  return {
1012
857
  usage: `### Installation
1013
858
  ${'Private' === visibility ? `
1014
859
  :warning: this is a private package, so you will need to use an npm token with
1015
860
  access to private packages under \`@${scope}\`
1016
- ` : ''}
861
+ ` : ''
862
+ }
1017
863
  \`\`\`sh
1018
864
  $ ${getInstallationCommand(packageManager)} ${packageName}
1019
865
  \`\`\`
@@ -1026,49 +872,56 @@ run \`${buildDocumentationCommand(packageManager)}\` to inject the usage example
1026
872
 
1027
873
  function defineBadges (packageName, visibility) {
1028
874
  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}`
875
+ consumer: {
876
+ ...'Public' === visibility && {
877
+ npm: {
878
+ img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
879
+ text: 'npm',
880
+ link: `https://www.npmjs.com/package/${packageName}`
881
+ }
1034
882
  }
1035
- }),
883
+ },
1036
884
  status: {}
1037
885
  };
1038
886
  }
1039
887
 
1040
- async function chooseBundler ({
1041
- bundlers,
1042
- decisions
1043
- }) {
888
+ async function chooseBundler ({bundlers, decisions}) {
1044
889
  if (!Object.keys(bundlers).length) return 'Other';
890
+
1045
891
  const answers = await overridablePrompts.prompt([{
1046
892
  name: questionNames$1.PACKAGE_BUNDLER,
1047
893
  type: 'list',
1048
894
  message: 'Which bundler should be used?',
1049
895
  choices: [...Object.keys(bundlers), new overridablePrompts.Separator(), 'Other']
1050
896
  }], decisions);
897
+
1051
898
  return answers[questionNames$1.PACKAGE_BUNDLER];
1052
899
  }
1053
900
 
1054
901
  function determinePathToTemplateFile (fileName) {
1055
902
  const [, __dirname] = filedirname__default["default"]();
903
+
1056
904
  return path.resolve(__dirname, '..', 'templates', fileName);
1057
905
  }
1058
906
 
1059
907
  const defaultBuildDirectory$2 = 'lib';
1060
908
 
1061
909
  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
- }));
910
+ return fs.promises.writeFile(
911
+ `${projectRoot}/example.js`,
912
+ mustache__default["default"].render(
913
+ await fs.promises.readFile(determinePathToTemplateFile('example.mustache'), 'utf8'),
914
+ {projectName: camelcase__default["default"](projectName)}
915
+ )
916
+ );
1065
917
  }
1066
918
 
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`)]);
919
+ async function buildDetailsForCommonJsProject({projectRoot, projectName}) {
920
+ await Promise.all([
921
+ touch__default["default"](`${projectRoot}/index.js`),
922
+ fs.promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase__default["default"](projectName)} = require('.');\n`)
923
+ ]);
924
+
1072
925
  return {};
1073
926
  }
1074
927
 
@@ -1081,42 +934,42 @@ async function buildDetails ({
1081
934
  dialect,
1082
935
  decisions
1083
936
  }) {
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
- });
937
+ if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
938
+
939
+ const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
940
+
1092
941
  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}`
942
+ const [bundlerResults] = await Promise.all([
943
+ javascriptCore.scaffoldChoice(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: javascriptCore.projectTypes.PACKAGE}),
944
+ await createExample(projectRoot, projectName),
945
+ touch__default["default"](`${pathToCreatedSrcDirectory}/index.js`)
946
+ ]);
947
+
948
+ return deepmerge__default["default"](
949
+ bundlerResults,
950
+ {
951
+ devDependencies: ['rimraf'],
952
+ scripts: {
953
+ clean: `rimraf ./${defaultBuildDirectory$2}`,
954
+ prebuild: 'run-s clean',
955
+ build: 'npm-run-all --print-label --parallel build:*',
956
+ prepack: 'run-s build'
957
+ },
958
+ vcsIgnore: {directories: [`/${defaultBuildDirectory$2}/`]},
959
+ buildDirectory: defaultBuildDirectory$2,
960
+ badges: {
961
+ consumer: {
962
+ ...'Public' === visibility && {
963
+ runkit: {
964
+ img: `https://badge.runkitcdn.com/${packageName}.svg`,
965
+ text: `Try ${packageName} on RunKit`,
966
+ link: `https://npm.runkit.com/${packageName}`
967
+ }
968
+ }
1116
969
  }
1117
- })
970
+ }
1118
971
  }
1119
- });
972
+ );
1120
973
  }
1121
974
 
1122
975
  async function scaffoldPackageType ({
@@ -1134,78 +987,70 @@ async function scaffoldPackageType ({
1134
987
  publishRegistry
1135
988
  }) {
1136
989
  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'
990
+
991
+ const [detailsForBuild] = await Promise.all([
992
+ buildDetails({projectRoot, projectName, packageBundlers, visibility, packageName, dialect, decisions}),
993
+ javascriptCore.mergeIntoExistingPackageJson({
994
+ projectRoot,
995
+ config: {
996
+ files: ['example.js', ...javascriptCore.dialects.COMMON_JS === dialect ? ['index.js'] : ['lib/']],
997
+ publishConfig: {
998
+ access: 'Public' === visibility ? 'public' : 'restricted',
999
+ ...publishRegistry && {registry: publishRegistry}
1000
+ },
1001
+ sideEffects: false,
1002
+ ...'Public' === visibility && {runkitExampleFilename: './example.js'},
1003
+ ...javascriptCore.dialects.BABEL === dialect && {
1004
+ main: './lib/index.cjs.js',
1005
+ module: './lib/index.es.js',
1006
+ exports: {
1007
+ require: './lib/index.cjs.js',
1008
+ import: './lib/index.es.js'
1009
+ }
1010
+ },
1011
+ ...javascriptCore.dialects.ESM === dialect && {
1012
+ main: './lib/index.es.js',
1013
+ exports: './lib/index.es.js'
1014
+ },
1015
+ ...javascriptCore.dialects.TYPESCRIPT === dialect && {
1016
+ main: './lib/index.cjs.js',
1017
+ module: './lib/index.es.js',
1018
+ types: './lib/index.d.ts',
1019
+ exports: {
1020
+ types: './lib/index.d.ts',
1021
+ require: './lib/index.cjs.js',
1022
+ import: './lib/index.es.js'
1023
+ }
1024
+ }
1175
1025
  }
1176
1026
  })
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]);
1027
+ ]);
1028
+
1029
+ const chosenType = await chooseApplicationType({types: packageTypes, projectType: 'package', decisions});
1030
+ const results = await javascriptCore.scaffoldChoice(
1031
+ packageTypes,
1032
+ chosenType,
1033
+ {projectRoot, projectName, packageName, tests, scope}
1034
+ );
1035
+
1036
+ return deepmerge__default["default"].all([
1037
+ {
1038
+ documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager}),
1039
+ eslintConfigs: [],
1040
+ nextSteps: [
1041
+ {summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
1042
+ {summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
1043
+ ],
1044
+ scripts: {},
1045
+ badges: defineBadges(packageName, visibility)
1046
+ },
1047
+ detailsForBuild,
1048
+ results
1049
+ ]);
1206
1050
  }
1207
1051
 
1208
1052
  const defaultBuildDirectory$1 = 'lib';
1053
+
1209
1054
  async function scaffoldApplicationType ({
1210
1055
  applicationTypes,
1211
1056
  projectRoot,
@@ -1216,112 +1061,94 @@ async function scaffoldApplicationType ({
1216
1061
  decisions
1217
1062
  }) {
1218
1063
  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
- });
1064
+
1065
+ const [chosenType] = await Promise.all([
1066
+ chooseApplicationType({types: applicationTypes, projectType: 'application', decisions}),
1067
+ javascriptCore.mergeIntoExistingPackageJson({projectRoot, config: {private: true}})
1068
+ ]);
1069
+
1070
+ const results = await javascriptCore.scaffoldChoice(
1071
+ applicationTypes,
1072
+ chosenType,
1073
+ {projectRoot, projectName, packageName, packageManager, tests}
1074
+ );
1075
+
1236
1076
  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}/`]
1077
+
1078
+ return deepmerge__default["default"](
1079
+ {
1080
+ scripts: {
1081
+ clean: `rimraf ./${buildDirectory}`,
1082
+ start: `node ./${buildDirectory}/index.js`,
1083
+ prebuild: 'run-s clean'
1084
+ },
1085
+ dependencies: [],
1086
+ devDependencies: ['rimraf'],
1087
+ vcsIgnore: {files: ['.env'], directories: [`/${buildDirectory}/`]},
1088
+ buildDirectory,
1089
+ eslintConfigs: [],
1090
+ nextSteps: []
1248
1091
  },
1249
- buildDirectory,
1250
- eslintConfigs: [],
1251
- nextSteps: []
1252
- }, results);
1092
+ results
1093
+ );
1253
1094
  }
1254
1095
 
1255
- async function scaffoldMonorepoType ({
1256
- monorepoTypes,
1257
- projectRoot,
1258
- packageManager,
1259
- decisions
1260
- }) {
1096
+ async function scaffoldMonorepoType ({monorepoTypes, projectRoot, packageManager, decisions}) {
1261
1097
  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
1098
+
1099
+ const chosenType = await chooseApplicationType({types: monorepoTypes, projectType: javascriptCore.projectTypes.MONOREPO, decisions});
1100
+ const results = await javascriptCore.scaffoldChoice(monorepoTypes, chosenType, {projectRoot, packageManager});
1101
+
1102
+ return deepmerge__default["default"](
1103
+ {
1104
+ eslintConfigs: [],
1105
+ packageProperties: {private: true},
1106
+ nextSteps: [{
1107
+ summary: 'Add packages to your new monorepo',
1108
+ description: 'Leverage [@form8ion/add-package-to-monorepo](https://npm.im/@form8ion/add-package-to-monorepo)'
1109
+ + ' to scaffold new packages into your new monorepo'
1110
+ }]
1275
1111
  },
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);
1112
+ results
1113
+ );
1281
1114
  }
1282
1115
 
1283
1116
  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
- })
1117
+
1118
+ async function scaffoldCliType ({packageName, visibility, projectRoot, dialect, publishRegistry}) {
1119
+ const [rollupResults] = await Promise.all([
1120
+ rollup.scaffold({projectRoot, dialect, projectType: javascriptCore.projectTypes.CLI}),
1121
+ javascriptCore.mergeIntoExistingPackageJson({
1122
+ projectRoot,
1123
+ config: {
1124
+ bin: {},
1125
+ files: [`${defaultBuildDirectory}/`],
1126
+ publishConfig: {
1127
+ access: 'Public' === visibility ? 'public' : 'restricted',
1128
+ ...publishRegistry && {registry: publishRegistry}
1129
+ }
1130
+ }
1131
+ })
1132
+ ]);
1133
+
1134
+ return deepmerge__default["default"](
1135
+ rollupResults,
1136
+ {
1137
+ scripts: {
1138
+ clean: `rimraf ./${defaultBuildDirectory}`,
1139
+ prebuild: 'run-s clean',
1140
+ build: 'npm-run-all --print-label --parallel build:*',
1141
+ prepack: 'run-s build'
1142
+ },
1143
+ dependencies: ['update-notifier'],
1144
+ devDependencies: ['rimraf'],
1145
+ vcsIgnore: {files: [], directories: [`/${defaultBuildDirectory}/`]},
1146
+ buildDirectory: defaultBuildDirectory,
1147
+ badges: defineBadges(packageName, visibility),
1148
+ eslintConfigs: [],
1149
+ nextSteps: []
1305
1150
  }
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
- });
1151
+ );
1325
1152
  }
1326
1153
 
1327
1154
  async function scaffoldProjectType ({
@@ -1359,7 +1186,6 @@ async function scaffoldProjectType ({
1359
1186
  dialect,
1360
1187
  publishRegistry
1361
1188
  });
1362
-
1363
1189
  case javascriptCore.projectTypes.APPLICATION:
1364
1190
  return scaffoldApplicationType({
1365
1191
  projectRoot,
@@ -1370,29 +1196,14 @@ async function scaffoldProjectType ({
1370
1196
  tests,
1371
1197
  decisions
1372
1198
  });
1373
-
1374
1199
  case javascriptCore.projectTypes.CLI:
1375
- return scaffoldCliType({
1376
- packageName,
1377
- visibility,
1378
- projectRoot,
1379
- dialect,
1380
- publishRegistry
1381
- });
1382
-
1200
+ return scaffoldCliType({packageName, visibility, projectRoot, dialect, publishRegistry});
1383
1201
  case javascriptCore.projectTypes.MONOREPO:
1384
- return scaffoldMonorepoType({
1385
- monorepoTypes,
1386
- projectRoot,
1387
- packageManager,
1388
- decisions
1389
- });
1390
-
1202
+ return scaffoldMonorepoType({monorepoTypes, projectRoot, packageManager, decisions});
1391
1203
  case 'Other':
1392
1204
  return {
1393
1205
  eslintConfigs: []
1394
1206
  };
1395
-
1396
1207
  default:
1397
1208
  throw new Error(`The project-type of ${projectType} is invalid`);
1398
1209
  }
@@ -1401,48 +1212,39 @@ async function scaffoldProjectType ({
1401
1212
  async function scaffoldTesting ({
1402
1213
  projectRoot,
1403
1214
  visibility,
1404
- tests: {
1405
- unit,
1406
- integration
1407
- },
1215
+ tests: {unit, integration},
1408
1216
  vcs,
1409
1217
  unitTestFrameworks,
1410
1218
  decisions,
1411
1219
  dialect,
1412
1220
  pathWithinParent
1413
1221
  }) {
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);
1222
+ const unitResults = unit
1223
+ ? await scaffoldUnitTesting({
1224
+ projectRoot,
1225
+ visibility,
1226
+ vcs,
1227
+ frameworks: unitTestFrameworks,
1228
+ decisions,
1229
+ dialect,
1230
+ pathWithinParent
1231
+ })
1232
+ : {};
1233
+
1234
+ return deepmerge__default["default"]({devDependencies: [...(unit || integration) ? ['@travi/any'] : []], eslint: {}}, unitResults);
1427
1235
  }
1428
1236
 
1429
- function scaffoldBanSensitiveFiles ({
1430
- pathWithinParent
1431
- }) {
1237
+ function scaffoldBanSensitiveFiles ({pathWithinParent}) {
1432
1238
  if (pathWithinParent) return {};
1433
- return {
1434
- scripts: {
1435
- 'lint:sensitive': 'ban'
1436
- },
1437
- devDependencies: ['ban-sensitive-files']
1438
- };
1239
+
1240
+ return {scripts: {'lint:sensitive': 'ban'}, devDependencies: ['ban-sensitive-files']};
1439
1241
  }
1440
1242
 
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)))];
1243
+ function buildAllowedHostsList ({packageManager, registries}) {
1244
+ return [
1245
+ ...(!registries || (registries && !registries.registry)) ? [packageManager] : [],
1246
+ ...Object.values(Object.fromEntries(Object.entries(registries).filter(([scope]) => 'publish' !== scope)))
1247
+ ];
1446
1248
  }
1447
1249
 
1448
1250
  const lockfileLintSupportedPackageManagers = [javascriptCore.packageManagers.NPM, javascriptCore.packageManagers.YARN];
@@ -1452,6 +1254,7 @@ function determineLockfilePathFor(packageManager) {
1452
1254
  [javascriptCore.packageManagers.NPM]: 'package-lock.json',
1453
1255
  [javascriptCore.packageManagers.YARN]: 'yarn.lock'
1454
1256
  };
1257
+
1455
1258
  return lockfilePaths[packageManager];
1456
1259
  }
1457
1260
 
@@ -1459,46 +1262,35 @@ function lockfileLintSupports(packageManager) {
1459
1262
  return lockfileLintSupportedPackageManagers.includes(packageManager);
1460
1263
  }
1461
1264
 
1462
- async function scaffoldLockfileLint ({
1463
- projectRoot,
1464
- packageManager,
1465
- registries
1466
- }) {
1265
+ async function scaffoldLockfileLint ({projectRoot, packageManager, registries}) {
1467
1266
  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.`);
1267
+ throw new Error(
1268
+ `The ${packageManager} package manager is currently not supported by lockfile-lint. `
1269
+ + `Only ${lockfileLintSupportedPackageManagers.join(' and ')} are currently supported.`
1270
+ );
1469
1271
  }
1470
1272
 
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
1273
+ await fs.promises.writeFile(
1274
+ `${projectRoot}/.lockfile-lintrc.json`,
1275
+ JSON.stringify({
1276
+ path: determineLockfilePathFor(packageManager),
1277
+ type: packageManager,
1278
+ 'validate-https': true,
1279
+ 'allowed-hosts': buildAllowedHostsList({packageManager, registries})
1478
1280
  })
1479
- }));
1281
+ );
1282
+
1480
1283
  return {
1481
1284
  devDependencies: ['lockfile-lint'],
1482
- scripts: {
1483
- 'lint:lockfile': 'lockfile-lint'
1484
- }
1285
+ scripts: {'lint:lockfile': 'lockfile-lint'}
1485
1286
  };
1486
1287
  }
1487
1288
 
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
- }) : {}]));
1289
+ async function scaffoldLinting ({projectRoot, packageManager, registries, vcs, pathWithinParent}) {
1290
+ return deepmerge__default["default"].all(await Promise.all([
1291
+ scaffoldLockfileLint({projectRoot, packageManager, registries}),
1292
+ vcs ? scaffoldBanSensitiveFiles({pathWithinParent}) : {}
1293
+ ]));
1502
1294
  }
1503
1295
 
1504
1296
  async function scaffoldVerification({
@@ -1513,60 +1305,33 @@ async function scaffoldVerification({
1513
1305
  decisions,
1514
1306
  pathWithinParent
1515
1307
  }) {
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
- })]);
1308
+ const [testingResults, lintingResults, huskyResults] = await Promise.all([
1309
+ scaffoldTesting({
1310
+ projectRoot,
1311
+ tests,
1312
+ visibility,
1313
+ vcs,
1314
+ unitTestFrameworks,
1315
+ decisions,
1316
+ dialect,
1317
+ pathWithinParent
1318
+ }),
1319
+ scaffoldLinting({projectRoot, packageManager, registries, vcs, pathWithinParent}),
1320
+ huskyPlugin.scaffold({projectRoot, packageManager, pathWithinParent})
1321
+ ]);
1322
+
1536
1323
  return deepmerge__default["default"].all([testingResults, lintingResults, huskyResults]);
1537
1324
  }
1538
1325
 
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
- });
1326
+ async function scaffoldEslint ({config, projectRoot, buildDirectory, additionalConfiguration}) {
1327
+ const {scope} = config;
1328
+ const {ignore} = additionalConfiguration;
1329
+ const ignores = deepmerge__default["default"](ignore, {directories: [`/${buildDirectory}/`]});
1330
+
1331
+ return eslint.scaffold({scope, projectRoot, ignore: {directories: ignores.directories}});
1561
1332
  }
1562
1333
 
1563
- async function scaffoldRemark ({
1564
- config,
1565
- projectRoot,
1566
- projectType,
1567
- vcs,
1568
- dialect
1569
- }) {
1334
+ async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
1570
1335
  await configFile.write({
1571
1336
  format: core.fileTypes.JSON,
1572
1337
  path: projectRoot,
@@ -1579,28 +1344,30 @@ async function scaffoldRemark ({
1579
1344
  bullet: '*',
1580
1345
  incrementListMarker: false
1581
1346
  },
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
- }]] : [])]
1347
+ plugins: [
1348
+ config,
1349
+ ['remark-toc', {tight: true}],
1350
+ ...javascriptCore.projectTypes.PACKAGE === projectType ? [['remark-usage', {heading: 'example'}]] : [],
1351
+ ...!vcs ? [['validate-links', {repository: false}]] : []
1352
+ ]
1589
1353
  }
1590
1354
  });
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'
1355
+
1356
+ return deepmerge__default["default"](
1357
+ {
1358
+ devDependencies: [config, 'remark-cli', 'remark-toc'],
1359
+ scripts: {
1360
+ 'lint:md': 'remark . --frail',
1361
+ 'generate:md': 'remark . --output'
1362
+ }
1363
+ },
1364
+ {
1365
+ ...javascriptCore.projectTypes.PACKAGE === projectType && {
1366
+ devDependencies: ['remark-usage'],
1367
+ ...javascriptCore.dialects.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
1368
+ }
1602
1369
  }
1603
- })));
1370
+ );
1604
1371
  }
1605
1372
 
1606
1373
  async function scaffoldCodeStyle ({
@@ -1613,22 +1380,28 @@ async function scaffoldCodeStyle ({
1613
1380
  buildDirectory,
1614
1381
  eslint
1615
1382
  }) {
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
- })]));
1383
+ return deepmerge__default["default"].all(await Promise.all([
1384
+ configs.eslint && configureLinting
1385
+ && scaffoldEslint({
1386
+ projectRoot,
1387
+ config: configs.eslint,
1388
+ buildDirectory,
1389
+ additionalConfiguration: eslint
1390
+ }),
1391
+ scaffoldRemark({
1392
+ projectRoot,
1393
+ projectType,
1394
+ dialect,
1395
+ vcs,
1396
+ config: configs.remark || '@form8ion/remark-lint-preset'
1397
+ }),
1398
+ prettier.scaffold({projectRoot, config: configs.prettier})
1399
+ ].filter(Boolean)));
1628
1400
  }
1629
1401
 
1630
1402
  async function scaffolder (options) {
1631
1403
  cliMessages.info('Initializing JavaScript project');
1404
+
1632
1405
  const {
1633
1406
  projectRoot,
1634
1407
  projectName,
@@ -1649,6 +1422,7 @@ async function scaffolder (options) {
1649
1422
  pathWithinParent,
1650
1423
  registries
1651
1424
  } = validate(options);
1425
+
1652
1426
  const {
1653
1427
  tests,
1654
1428
  projectType,
@@ -1661,13 +1435,11 @@ async function scaffolder (options) {
1661
1435
  packageManager,
1662
1436
  dialect
1663
1437
  } = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
1664
- cliMessages.info('Writing project files', {
1665
- level: 'secondary'
1666
- });
1438
+
1439
+ cliMessages.info('Writing project files', {level: 'secondary'});
1440
+
1667
1441
  const packageName = buildPackageName(projectName, scope);
1668
- const {
1669
- homepage: projectHomepage
1670
- } = await scaffoldPackage({
1442
+ const {homepage: projectHomepage} = await scaffoldPackage({
1671
1443
  projectRoot,
1672
1444
  projectType,
1673
1445
  dialect,
@@ -1678,111 +1450,106 @@ async function scaffolder (options) {
1678
1450
  description,
1679
1451
  pathWithinParent
1680
1452
  });
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]);
1453
+ const [projectTypeResults, verificationResults] = await Promise.all([
1454
+ scaffoldProjectType({
1455
+ projectType,
1456
+ projectRoot,
1457
+ projectName,
1458
+ packageName,
1459
+ packageManager,
1460
+ visibility,
1461
+ applicationTypes,
1462
+ packageTypes,
1463
+ packageBundlers,
1464
+ monorepoTypes,
1465
+ scope,
1466
+ tests,
1467
+ vcs,
1468
+ decisions,
1469
+ dialect,
1470
+ publishRegistry: registries.publish
1471
+ }),
1472
+ scaffoldVerification({
1473
+ projectRoot,
1474
+ dialect,
1475
+ visibility,
1476
+ packageManager,
1477
+ vcs,
1478
+ registries,
1479
+ tests,
1480
+ unitTestFrameworks,
1481
+ decisions,
1482
+ pathWithinParent
1483
+ })
1484
+ ]);
1485
+ const [nodeVersion, npmResults, dialectResults, codeStyleResults] = await Promise.all([
1486
+ scaffoldNodeVersion({projectRoot, nodeVersionCategory}),
1487
+ scaffoldNpmConfig({projectType, projectRoot, registries}),
1488
+ scaffoldDialect({
1489
+ dialect,
1490
+ configs,
1491
+ projectRoot,
1492
+ projectType,
1493
+ buildDirectory: projectTypeResults.buildDirectory,
1494
+ testFilenamePattern: verificationResults.testFilenamePattern
1495
+ }),
1496
+ scaffoldCodeStyle({
1497
+ projectRoot,
1498
+ projectType,
1499
+ dialect,
1500
+ configs,
1501
+ vcs,
1502
+ configureLinting,
1503
+ buildDirectory: projectTypeResults.buildDirectory,
1504
+ eslint: verificationResults.eslint
1505
+ })
1506
+ ]);
1507
+ const mergedContributions = deepmerge__default["default"].all([
1508
+ ...(await Promise.all([
1509
+ javascriptCore.scaffoldChoice(
1510
+ hosts,
1511
+ chosenHost,
1512
+ {buildDirectory: `./${projectTypeResults.buildDirectory}`, projectRoot, projectName, nodeVersion}
1513
+ ),
1514
+ javascriptCore.scaffoldChoice(ciServices, ci, {projectRoot, vcs, visibility, projectType, projectName, nodeVersion, tests}),
1515
+ commitConventionPlugin.scaffold({projectRoot, projectType, configs, pathWithinParent})
1516
+ ])),
1517
+ projectTypeResults,
1518
+ verificationResults,
1519
+ codeStyleResults,
1520
+ npmResults,
1521
+ dialectResults
1522
+ ]);
1523
+
1753
1524
  const liftResults = await lift({
1754
- results: deepmerge__default["default"]({
1755
- devDependencies: ['npm-run-all'],
1756
- packageManager
1757
- }, mergedContributions),
1525
+ results: deepmerge__default["default"]({devDependencies: ['npm-run-all'], packageManager}, mergedContributions),
1758
1526
  projectRoot,
1759
1527
  configs,
1760
1528
  vcs
1761
1529
  });
1530
+
1762
1531
  return {
1763
1532
  badges: buildBadgesDetails([mergedContributions, liftResults]),
1764
- documentation: scaffoldDocumentation({
1765
- projectTypeResults,
1766
- packageManager
1767
- }),
1533
+ documentation: scaffoldDocumentation({projectTypeResults, packageManager}),
1768
1534
  tags: projectTypeResults.tags,
1769
1535
  vcsIgnore: buildVcsIgnoreLists(mergedContributions.vcsIgnore),
1770
1536
  verificationCommand: `${buildDocumentationCommand(packageManager)} && ${packageManager} test`,
1771
- projectDetails: _objectSpread2({}, projectHomepage && {
1772
- homepage: projectHomepage
1773
- }),
1537
+ projectDetails: {...projectHomepage && {homepage: projectHomepage}},
1774
1538
  nextSteps: mergedContributions.nextSteps
1775
1539
  };
1776
1540
  }
1777
1541
 
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`)]);
1542
+ async function test ({projectRoot}) {
1543
+ const [nvmIsConfigured, packageLockExists, yarnLockExists] = await Promise.all([
1544
+ core.fileExists(`${projectRoot}/.nvmrc`),
1545
+ core.fileExists(`${projectRoot}/package-lock.json`),
1546
+ core.fileExists(`${projectRoot}/yarn.lock`)
1547
+ ]);
1548
+
1782
1549
  return nvmIsConfigured || packageLockExists || yarnLockExists;
1783
1550
  }
1784
1551
 
1785
- const questionNames = _objectSpread2(_objectSpread2({}, languageScaffolderPrompts.questionNames), questionNames$1);
1552
+ const questionNames = {...languageScaffolderPrompts.questionNames, ...questionNames$1};
1786
1553
 
1787
1554
  exports.lift = lift;
1788
1555
  exports.questionNames = questionNames;