@form8ion/javascript 6.0.8 → 6.1.0-alpha.2

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