@form8ion/javascript 2.0.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs.js CHANGED
@@ -7,11 +7,13 @@ var deepmerge = require('deepmerge');
7
7
  var javascriptCore = require('@form8ion/javascript-core');
8
8
  var codecov = require('@form8ion/codecov');
9
9
  var fs = require('fs');
10
- var joi = require('@hapi/joi');
10
+ var joi = require('joi');
11
11
  var inquirer = require('inquirer');
12
12
  var overridablePrompts = require('@form8ion/overridable-prompts');
13
13
  var cliMessages = require('@travi/cli-messages');
14
- var liftJavascript = require('@form8ion/lift-javascript');
14
+ var eslint = require('@form8ion/eslint');
15
+ var core = require('@form8ion/core');
16
+ var husky = require('@form8ion/husky');
15
17
  var commitConvention = require('@form8ion/commit-convention');
16
18
  var hoek = require('@hapi/hoek');
17
19
  var execa = require('execa');
@@ -24,8 +26,6 @@ var camelcase = require('camelcase');
24
26
  var makeDir = require('make-dir');
25
27
  var touch = require('touch');
26
28
  var path = require('path');
27
- var husky = require('@form8ion/husky');
28
- var eslint = require('@form8ion/eslint');
29
29
 
30
30
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
31
31
 
@@ -62,14 +62,9 @@ function ownKeys(object, enumerableOnly) {
62
62
 
63
63
  if (Object.getOwnPropertySymbols) {
64
64
  var symbols = Object.getOwnPropertySymbols(object);
65
-
66
- if (enumerableOnly) {
67
- symbols = symbols.filter(function (sym) {
68
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
69
- });
70
- }
71
-
72
- keys.push.apply(keys, symbols);
65
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
66
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
67
+ })), keys.push.apply(keys, symbols);
73
68
  }
74
69
 
75
70
  return keys;
@@ -77,19 +72,12 @@ function ownKeys(object, enumerableOnly) {
77
72
 
78
73
  function _objectSpread2(target) {
79
74
  for (var i = 1; i < arguments.length; i++) {
80
- var source = arguments[i] != null ? arguments[i] : {};
81
-
82
- if (i % 2) {
83
- ownKeys(Object(source), true).forEach(function (key) {
84
- _defineProperty(target, key, source[key]);
85
- });
86
- } else if (Object.getOwnPropertyDescriptors) {
87
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
88
- } else {
89
- ownKeys(Object(source)).forEach(function (key) {
90
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
91
- });
92
- }
75
+ var source = null != arguments[i] ? arguments[i] : {};
76
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
77
+ _defineProperty(target, key, source[key]);
78
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
79
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
80
+ });
93
81
  }
94
82
 
95
83
  return target;
@@ -150,13 +138,15 @@ async function scaffoldC8 ({
150
138
  async function scaffoldCoverage ({
151
139
  projectRoot,
152
140
  vcs,
153
- visibility
141
+ visibility,
142
+ pathWithinParent
154
143
  }) {
155
144
  return deepmerge__default["default"](await scaffoldC8({
156
145
  projectRoot
157
146
  }), await codecov.scaffold({
158
147
  vcs,
159
- visibility
148
+ visibility,
149
+ pathWithinParent
160
150
  }));
161
151
  }
162
152
 
@@ -183,7 +173,8 @@ async function scaffoldUnitTesting ({
183
173
  frameworks,
184
174
  decisions,
185
175
  visibility,
186
- vcs
176
+ vcs,
177
+ pathWithinParent
187
178
  }) {
188
179
  const validatedFrameworks = javascriptCore.validateOptions(unitTestFrameworksSchema, frameworks);
189
180
  const [framework, coverage] = await Promise.all([chooseFramework({
@@ -194,7 +185,8 @@ async function scaffoldUnitTesting ({
194
185
  })), scaffoldCoverage({
195
186
  projectRoot,
196
187
  vcs,
197
- visibility
188
+ visibility,
189
+ pathWithinParent
198
190
  })]);
199
191
  return deepmerge__default["default"].all([{
200
192
  scripts: {
@@ -203,6 +195,157 @@ async function scaffoldUnitTesting ({
203
195
  }, framework, coverage]);
204
196
  }
205
197
 
198
+ async function applyEnhancers ({
199
+ results,
200
+ enhancers = {},
201
+ projectRoot
202
+ }) {
203
+ cliMessages.info('Applying Enhancers');
204
+ return Object.values(enhancers).reduce(async (acc, enhancer) => {
205
+ if (await enhancer.test({
206
+ projectRoot
207
+ })) {
208
+ const previousResults = await acc;
209
+ return deepmerge__default["default"](previousResults, await enhancer.lift({
210
+ results: previousResults,
211
+ projectRoot
212
+ }));
213
+ }
214
+
215
+ return acc;
216
+ }, results);
217
+ }
218
+
219
+ async function test$1({
220
+ projectRoot
221
+ }) {
222
+ const {
223
+ engines
224
+ } = JSON.parse(await fs.promises.readFile(`${projectRoot}/package.json`, 'utf8'));
225
+ return !!(engines !== null && engines !== void 0 && engines.node);
226
+ }
227
+ async function lift$1({
228
+ projectRoot
229
+ }) {
230
+ const {
231
+ name
232
+ } = JSON.parse(await fs.promises.readFile(`${projectRoot}/package.json`, 'utf8'));
233
+ return {
234
+ devDependencies: ['ls-engines'],
235
+ scripts: {
236
+ 'lint:engines': 'ls-engines'
237
+ },
238
+ badges: {
239
+ consumer: {
240
+ node: {
241
+ img: `https://img.shields.io/node/v/${name}?logo=node.js`,
242
+ text: 'node'
243
+ }
244
+ }
245
+ }
246
+ };
247
+ }
248
+
249
+ var enginesEnhancer = /*#__PURE__*/Object.freeze({
250
+ __proto__: null,
251
+ test: test$1,
252
+ lift: lift$1
253
+ });
254
+
255
+ async function liftPackage ({
256
+ projectRoot,
257
+ scripts,
258
+ tags,
259
+ dependencies,
260
+ devDependencies,
261
+ packageManager
262
+ }) {
263
+ if (scripts || tags) {
264
+ cliMessages.info('Updating `package.json`', {
265
+ level: 'secondary'
266
+ });
267
+ const pathToPackageJson = `${projectRoot}/package.json`;
268
+ const existingPackageJsonContents = JSON.parse(await fs.promises.readFile(pathToPackageJson, 'utf8'));
269
+ await fs.promises.writeFile(pathToPackageJson, JSON.stringify(_objectSpread2(_objectSpread2({}, existingPackageJsonContents), {}, {
270
+ scripts: _objectSpread2(_objectSpread2({}, existingPackageJsonContents.scripts), scripts)
271
+ }, tags && {
272
+ keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags
273
+ }), null, 2));
274
+ }
275
+
276
+ cliMessages.info('Installing dependencies');
277
+ await javascriptCore.installDependencies(dependencies || [], javascriptCore.PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
278
+ await javascriptCore.installDependencies([...(devDependencies || [])], javascriptCore.DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
279
+ }
280
+
281
+ async function resolvePackageManager ({
282
+ projectRoot,
283
+ packageManager
284
+ }) {
285
+ if (packageManager) return packageManager;
286
+
287
+ if (await core.fileExists(`${projectRoot}/package-lock.json`)) {
288
+ return javascriptCore.packageManagers.NPM;
289
+ }
290
+
291
+ if (await core.fileExists(`${projectRoot}/yarn.lock`)) {
292
+ return javascriptCore.packageManagers.YARN;
293
+ }
294
+
295
+ throw new Error('Package-manager could not be determined');
296
+ }
297
+
298
+ function enhanceHuskyEnhancer(packageManager) {
299
+ return {
300
+ test: husky.test,
301
+ lift: ({
302
+ projectRoot,
303
+ results
304
+ }) => husky.lift({
305
+ projectRoot,
306
+ results,
307
+ packageManager
308
+ })
309
+ };
310
+ }
311
+
312
+ async function lift ({
313
+ projectRoot,
314
+ results
315
+ }) {
316
+ cliMessages.info('Lifting JavaScript-specific details');
317
+ const {
318
+ scripts,
319
+ tags,
320
+ eslintConfigs,
321
+ dependencies,
322
+ devDependencies,
323
+ packageManager: manager
324
+ } = results;
325
+ const packageManager = await resolvePackageManager({
326
+ projectRoot,
327
+ packageManager: manager
328
+ });
329
+ const eslintResults = await eslint.lift({
330
+ projectRoot,
331
+ configs: eslintConfigs
332
+ });
333
+ const enhancerResults = await applyEnhancers({
334
+ results,
335
+ enhancers: [enhanceHuskyEnhancer(packageManager), enginesEnhancer],
336
+ projectRoot
337
+ });
338
+ await liftPackage(deepmerge__default["default"].all([{
339
+ projectRoot,
340
+ scripts,
341
+ tags,
342
+ dependencies,
343
+ devDependencies,
344
+ packageManager
345
+ }, enhancerResults, eslintResults]));
346
+ return enhancerResults;
347
+ }
348
+
206
349
  function validate(options) {
207
350
  const schema = joi__namespace.object().required().keys({
208
351
  projectRoot: joi__namespace.string().required(),
@@ -824,7 +967,7 @@ function defineBadges (packageName, visibility) {
824
967
  return {
825
968
  consumer: _objectSpread2({}, 'Public' === visibility && {
826
969
  npm: {
827
- img: `https://img.shields.io/npm/v/${packageName}.svg`,
970
+ img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
828
971
  text: 'npm',
829
972
  link: `https://www.npmjs.com/package/${packageName}`
830
973
  }
@@ -1171,7 +1314,8 @@ async function scaffoldTesting ({
1171
1314
  vcs,
1172
1315
  unitTestFrameworks,
1173
1316
  decisions,
1174
- dialect
1317
+ dialect,
1318
+ pathWithinParent
1175
1319
  }) {
1176
1320
  const unitResults = unit ? await scaffoldUnitTesting({
1177
1321
  projectRoot,
@@ -1179,7 +1323,8 @@ async function scaffoldTesting ({
1179
1323
  vcs,
1180
1324
  frameworks: unitTestFrameworks,
1181
1325
  decisions,
1182
- dialect
1326
+ dialect,
1327
+ pathWithinParent
1183
1328
  }) : {};
1184
1329
  return deepmerge__default["default"]({
1185
1330
  devDependencies: [...(unit || integration ? ['@travi/any'] : [])],
@@ -1328,7 +1473,8 @@ async function scaffoldVerification({
1328
1473
  unitTestFrameworks,
1329
1474
  decisions,
1330
1475
  buildDirectory,
1331
- eslintConfigs
1476
+ eslintConfigs,
1477
+ pathWithinParent
1332
1478
  }) {
1333
1479
  const [testingResults, huskyResults] = await Promise.all([scaffoldTesting({
1334
1480
  projectRoot,
@@ -1337,7 +1483,8 @@ async function scaffoldVerification({
1337
1483
  vcs,
1338
1484
  unitTestFrameworks,
1339
1485
  decisions,
1340
- dialect
1486
+ dialect,
1487
+ pathWithinParent
1341
1488
  }), husky.scaffold({
1342
1489
  projectRoot,
1343
1490
  packageManager
@@ -1361,7 +1508,7 @@ async function scaffoldVerification({
1361
1508
  return deepmerge__default["default"].all([testingResults, lintingResults, huskyResults]);
1362
1509
  }
1363
1510
 
1364
- async function scaffold(options) {
1511
+ async function scaffolder (options) {
1365
1512
  cliMessages.info('Initializing JavaScript project');
1366
1513
  const {
1367
1514
  projectRoot,
@@ -1427,6 +1574,7 @@ async function scaffold(options) {
1427
1574
  tests,
1428
1575
  unitTestFrameworks,
1429
1576
  decisions,
1577
+ pathWithinParent,
1430
1578
  buildDirectory: projectTypeResults.buildDirectory,
1431
1579
  eslintConfigs: projectTypeResults.eslintConfigs
1432
1580
  });
@@ -1480,7 +1628,7 @@ async function scaffold(options) {
1480
1628
  scripts: mergedContributions.scripts,
1481
1629
  pathWithinParent
1482
1630
  });
1483
- const liftResults = await liftJavascript.lift({
1631
+ const liftResults = await lift({
1484
1632
  results: deepmerge__default["default"]({
1485
1633
  devDependencies: ['npm-run-all'],
1486
1634
  packageManager
@@ -1504,9 +1652,23 @@ async function scaffold(options) {
1504
1652
  };
1505
1653
  }
1506
1654
 
1655
+ async function test ({
1656
+ projectRoot
1657
+ }) {
1658
+ try {
1659
+ const stats = await fs.promises.stat(`${projectRoot}/.nvmrc`);
1660
+ return stats.isFile();
1661
+ } catch (e) {
1662
+ if ('ENOENT' === e.code) return false;
1663
+ throw e;
1664
+ }
1665
+ }
1666
+
1507
1667
  const questionNames = _objectSpread2(_objectSpread2({}, languageScaffolderPrompts.questionNames), questionNames$1);
1508
1668
 
1669
+ exports.lift = lift;
1509
1670
  exports.questionNames = questionNames;
1510
- exports.scaffold = scaffold;
1671
+ exports.scaffold = scaffolder;
1511
1672
  exports.scaffoldUnitTesting = scaffoldUnitTesting;
1673
+ exports.test = test;
1512
1674
  //# sourceMappingURL=index.cjs.js.map