@form8ion/javascript 7.2.2 → 7.2.5
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 +142 -95
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +150 -103
- package/lib/index.mjs.map +1 -1
- package/package.json +4 -4
package/lib/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { questionNames as questionNames$2, questions } from '@travi/language-scaffolder-prompts';
|
|
2
2
|
import deepmerge from 'deepmerge';
|
|
3
|
-
import { validateOptions, scaffoldChoice, projectTypes, dialects as dialects$1, writePackageJson,
|
|
3
|
+
import { validateOptions, scaffoldChoice, projectTypes, dialects as dialects$1, writePackageJson, packageManagers, DEV_DEPENDENCY_TYPE, PROD_DEPENDENCY_TYPE, mergeIntoExistingPackageJson } from '@form8ion/javascript-core';
|
|
4
4
|
import joi from 'joi';
|
|
5
5
|
import { prompt as prompt$1, Separator } from '@form8ion/overridable-prompts';
|
|
6
6
|
import { scaffold, lift as lift$3 } from '@form8ion/codecov';
|
|
7
7
|
import { promises } from 'fs';
|
|
8
8
|
import { fileExists, fileTypes, writeConfigFile, applyEnhancers } from '@form8ion/core';
|
|
9
|
-
import { info,
|
|
9
|
+
import { info, warn, error } from '@travi/cli-messages';
|
|
10
10
|
import * as commitConventionPlugin from '@form8ion/commit-convention';
|
|
11
11
|
import { scaffold as scaffold$5 } from '@form8ion/commit-convention';
|
|
12
12
|
import hoek from '@hapi/hoek';
|
|
@@ -15,7 +15,7 @@ import npmConf from 'npm-conf';
|
|
|
15
15
|
import { stringify } from 'ini';
|
|
16
16
|
import { EOL } from 'os';
|
|
17
17
|
import validatePackageName from 'validate-npm-package-name';
|
|
18
|
-
import { scaffold as scaffold$
|
|
18
|
+
import { scaffold as scaffold$3 } from '@form8ion/rollup';
|
|
19
19
|
import mustache from 'mustache';
|
|
20
20
|
import camelcase from 'camelcase';
|
|
21
21
|
import makeDir from 'make-dir';
|
|
@@ -23,10 +23,10 @@ import touch from 'touch';
|
|
|
23
23
|
import { resolve } from 'path';
|
|
24
24
|
import filedirname from 'filedirname';
|
|
25
25
|
import * as huskyPlugin from '@form8ion/husky';
|
|
26
|
-
import { scaffold as scaffold$
|
|
26
|
+
import { scaffold as scaffold$4 } from '@form8ion/husky';
|
|
27
27
|
import { write as write$1 } from '@form8ion/config-file';
|
|
28
|
-
import { scaffold as scaffold$
|
|
29
|
-
import { lift as lift$4,
|
|
28
|
+
import { scaffold as scaffold$2 } from '@form8ion/prettier';
|
|
29
|
+
import { scaffold as scaffold$1, lift as lift$4, test as test$2 } from '@form8ion/eslint';
|
|
30
30
|
|
|
31
31
|
const questionNames$1 = {
|
|
32
32
|
UNIT_TEST_FRAMEWORK: 'unitTestFramework',
|
|
@@ -155,6 +155,87 @@ async function scaffoldUnitTesting ({projectRoot, frameworks, decisions, visibil
|
|
|
155
155
|
]);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
async function scaffoldEslint ({config, projectRoot, additionalConfiguration}) {
|
|
159
|
+
const {scope} = config;
|
|
160
|
+
const {ignore} = additionalConfiguration;
|
|
161
|
+
|
|
162
|
+
return scaffold$1({scope, projectRoot, ignore});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function lifter$1 ({results: {buildDirectory, eslintConfigs, eslint}, projectRoot}) {
|
|
166
|
+
return lift$4({projectRoot, configs: [...eslintConfigs || [], ...eslint?.configs || []], buildDirectory});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
|
|
170
|
+
await write$1({
|
|
171
|
+
format: fileTypes.JSON,
|
|
172
|
+
path: projectRoot,
|
|
173
|
+
name: 'remark',
|
|
174
|
+
config: {
|
|
175
|
+
settings: {
|
|
176
|
+
listItemIndent: 1,
|
|
177
|
+
emphasis: '_',
|
|
178
|
+
strong: '_',
|
|
179
|
+
bullet: '*',
|
|
180
|
+
incrementListMarker: false
|
|
181
|
+
},
|
|
182
|
+
plugins: [
|
|
183
|
+
config,
|
|
184
|
+
['remark-toc', {tight: true}],
|
|
185
|
+
...projectTypes.PACKAGE === projectType ? [['remark-usage', {heading: 'example'}]] : [],
|
|
186
|
+
...!vcs ? [['validate-links', {repository: false}]] : []
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return deepmerge(
|
|
192
|
+
{
|
|
193
|
+
devDependencies: [config, 'remark-cli', 'remark-toc'],
|
|
194
|
+
scripts: {
|
|
195
|
+
'lint:md': 'remark . --frail',
|
|
196
|
+
'generate:md': 'remark . --output'
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
...projectTypes.PACKAGE === projectType && {
|
|
201
|
+
devDependencies: ['remark-usage'],
|
|
202
|
+
...dialects$1.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function scaffoldCodeStyle ({
|
|
209
|
+
projectRoot,
|
|
210
|
+
projectType,
|
|
211
|
+
dialect,
|
|
212
|
+
configs,
|
|
213
|
+
vcs,
|
|
214
|
+
configureLinting,
|
|
215
|
+
eslint
|
|
216
|
+
}) {
|
|
217
|
+
return deepmerge.all(await Promise.all([
|
|
218
|
+
configs.eslint
|
|
219
|
+
&& configureLinting
|
|
220
|
+
&& scaffoldEslint({projectRoot, config: configs.eslint, additionalConfiguration: eslint}),
|
|
221
|
+
scaffoldRemark({
|
|
222
|
+
projectRoot,
|
|
223
|
+
projectType,
|
|
224
|
+
dialect,
|
|
225
|
+
vcs,
|
|
226
|
+
config: configs.remark || '@form8ion/remark-lint-preset'
|
|
227
|
+
}),
|
|
228
|
+
scaffold$2({projectRoot, config: configs.prettier})
|
|
229
|
+
].filter(Boolean)));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
var codeStylePlugin = /*#__PURE__*/Object.freeze({
|
|
233
|
+
__proto__: null,
|
|
234
|
+
scaffold: scaffoldCodeStyle,
|
|
235
|
+
lift: lifter$1,
|
|
236
|
+
test: test$2
|
|
237
|
+
});
|
|
238
|
+
|
|
158
239
|
async function test$1({projectRoot}) {
|
|
159
240
|
const {engines} = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf8'));
|
|
160
241
|
|
|
@@ -202,8 +283,8 @@ async function scaffoldBabel ({projectRoot, preset}) {
|
|
|
202
283
|
};
|
|
203
284
|
}
|
|
204
285
|
|
|
205
|
-
async function lifter ({
|
|
206
|
-
await addIgnore({ignore: buildDirectory, projectRoot});
|
|
286
|
+
async function lifter ({results, projectRoot}) {
|
|
287
|
+
await addIgnore({ignore: results.buildDirectory, projectRoot});
|
|
207
288
|
|
|
208
289
|
return {};
|
|
209
290
|
}
|
|
@@ -354,6 +435,52 @@ async function scaffoldPackage ({
|
|
|
354
435
|
return {homepage: packageData.homepage};
|
|
355
436
|
}
|
|
356
437
|
|
|
438
|
+
const details = {
|
|
439
|
+
[packageManagers.NPM]: {
|
|
440
|
+
installationCommand: 'install',
|
|
441
|
+
installationFlags: {
|
|
442
|
+
[DEV_DEPENDENCY_TYPE]: `save-${DEV_DEPENDENCY_TYPE}`,
|
|
443
|
+
[PROD_DEPENDENCY_TYPE]: `save-${PROD_DEPENDENCY_TYPE}`,
|
|
444
|
+
exact: 'save-exact'
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
[packageManagers.YARN]: {
|
|
448
|
+
installationCommand: 'add',
|
|
449
|
+
installationFlags: {
|
|
450
|
+
[DEV_DEPENDENCY_TYPE]: DEV_DEPENDENCY_TYPE,
|
|
451
|
+
[PROD_DEPENDENCY_TYPE]: PROD_DEPENDENCY_TYPE,
|
|
452
|
+
exact: 'exact'
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
function getInstallationCommandFor(manager) {
|
|
458
|
+
return details[manager].installationCommand;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function getDependencyTypeFlag(manager, type) {
|
|
462
|
+
return details[manager].installationFlags[type];
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function getExactFlag(manager) {
|
|
466
|
+
return details[manager].installationFlags.exact;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function install$1 (dependencies, dependenciesType, projectRoot, packageManager = packageManagers.NPM) {
|
|
470
|
+
if (dependencies.length) {
|
|
471
|
+
info(`Installing ${dependenciesType} dependencies`, {level: 'secondary'});
|
|
472
|
+
|
|
473
|
+
await execa(
|
|
474
|
+
`. ~/.nvm/nvm.sh && nvm use && ${packageManager} ${
|
|
475
|
+
getInstallationCommandFor(packageManager)
|
|
476
|
+
} ${[...new Set(dependencies)].join(' ')} --${getDependencyTypeFlag(packageManager, dependenciesType)}${
|
|
477
|
+
DEV_DEPENDENCY_TYPE === dependenciesType ? ` --${getExactFlag(packageManager)}` : ''
|
|
478
|
+
}`,
|
|
479
|
+
{shell: true, cwd: projectRoot}
|
|
480
|
+
);
|
|
481
|
+
} else warn(`No ${dependenciesType} dependencies to install`);
|
|
482
|
+
}
|
|
483
|
+
|
|
357
484
|
async function liftPackage ({
|
|
358
485
|
projectRoot,
|
|
359
486
|
scripts,
|
|
@@ -384,8 +511,8 @@ async function liftPackage ({
|
|
|
384
511
|
info('Installing dependencies');
|
|
385
512
|
|
|
386
513
|
try {
|
|
387
|
-
await
|
|
388
|
-
await
|
|
514
|
+
await install$1(dependencies || [], PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
515
|
+
await install$1([...devDependencies || []], DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
389
516
|
} catch (e) {
|
|
390
517
|
error('Failed to install dependencies');
|
|
391
518
|
}
|
|
@@ -411,28 +538,23 @@ async function lift ({projectRoot, vcs, results}) {
|
|
|
411
538
|
const {
|
|
412
539
|
scripts,
|
|
413
540
|
tags,
|
|
414
|
-
eslintConfigs,
|
|
415
|
-
eslint,
|
|
416
541
|
dependencies,
|
|
417
542
|
devDependencies,
|
|
418
|
-
packageManager: manager
|
|
419
|
-
buildDirectory
|
|
543
|
+
packageManager: manager
|
|
420
544
|
} = results;
|
|
421
545
|
|
|
422
546
|
const packageManager = await resolvePackageManager({projectRoot, packageManager: manager});
|
|
423
547
|
|
|
424
|
-
const eslintResults = await lift$4({projectRoot, configs: [...eslintConfigs || [], ...eslint?.configs || []]});
|
|
425
548
|
const enhancerResults = await applyEnhancers({
|
|
426
549
|
results,
|
|
427
|
-
enhancers: [huskyPlugin, enginesEnhancer, coveragePlugin, commitConventionPlugin, dialects],
|
|
428
|
-
options: {packageManager, projectRoot, vcs
|
|
550
|
+
enhancers: [huskyPlugin, enginesEnhancer, coveragePlugin, commitConventionPlugin, dialects, codeStylePlugin],
|
|
551
|
+
options: {packageManager, projectRoot, vcs}
|
|
429
552
|
});
|
|
430
553
|
|
|
431
554
|
await liftPackage(
|
|
432
555
|
deepmerge.all([
|
|
433
556
|
{projectRoot, scripts, tags, dependencies, devDependencies, packageManager},
|
|
434
|
-
enhancerResults
|
|
435
|
-
eslintResults
|
|
557
|
+
enhancerResults
|
|
436
558
|
])
|
|
437
559
|
);
|
|
438
560
|
|
|
@@ -1068,7 +1190,7 @@ const defaultBuildDirectory = 'bin';
|
|
|
1068
1190
|
|
|
1069
1191
|
async function scaffoldCliType ({packageName, visibility, projectRoot, dialect, publishRegistry}) {
|
|
1070
1192
|
const [rollupResults] = await Promise.all([
|
|
1071
|
-
scaffold$
|
|
1193
|
+
scaffold$3({projectRoot, dialect, projectType: projectTypes.CLI}),
|
|
1072
1194
|
mergeIntoExistingPackageJson({
|
|
1073
1195
|
projectRoot,
|
|
1074
1196
|
config: {
|
|
@@ -1245,15 +1367,17 @@ async function scaffoldLockfileLint ({projectRoot, packageManager, registries})
|
|
|
1245
1367
|
);
|
|
1246
1368
|
}
|
|
1247
1369
|
|
|
1248
|
-
await
|
|
1249
|
-
|
|
1250
|
-
JSON
|
|
1370
|
+
await write$1({
|
|
1371
|
+
name: 'lockfile-lint',
|
|
1372
|
+
format: fileTypes.JSON,
|
|
1373
|
+
path: projectRoot,
|
|
1374
|
+
config: {
|
|
1251
1375
|
path: determineLockfilePathFor(packageManager),
|
|
1252
1376
|
type: packageManager,
|
|
1253
1377
|
'validate-https': true,
|
|
1254
1378
|
'allowed-hosts': buildAllowedHostsList({packageManager, registries})
|
|
1255
|
-
}
|
|
1256
|
-
);
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1257
1381
|
|
|
1258
1382
|
return {
|
|
1259
1383
|
devDependencies: ['lockfile-lint'],
|
|
@@ -1292,88 +1416,12 @@ async function scaffoldVerification({
|
|
|
1292
1416
|
pathWithinParent
|
|
1293
1417
|
}),
|
|
1294
1418
|
scaffoldLinting({projectRoot, packageManager, registries, vcs, pathWithinParent}),
|
|
1295
|
-
scaffold$
|
|
1419
|
+
scaffold$4({projectRoot, packageManager, pathWithinParent})
|
|
1296
1420
|
]);
|
|
1297
1421
|
|
|
1298
1422
|
return deepmerge.all([testingResults, lintingResults, huskyResults]);
|
|
1299
1423
|
}
|
|
1300
1424
|
|
|
1301
|
-
async function scaffoldEslint ({config, projectRoot, buildDirectory, additionalConfiguration}) {
|
|
1302
|
-
const {scope} = config;
|
|
1303
|
-
const {ignore} = additionalConfiguration;
|
|
1304
|
-
const ignores = deepmerge(ignore, {directories: [`/${buildDirectory}/`]});
|
|
1305
|
-
|
|
1306
|
-
return scaffold$3({scope, projectRoot, ignore: {directories: ignores.directories}});
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
|
|
1310
|
-
await write$1({
|
|
1311
|
-
format: fileTypes.JSON,
|
|
1312
|
-
path: projectRoot,
|
|
1313
|
-
name: 'remark',
|
|
1314
|
-
config: {
|
|
1315
|
-
settings: {
|
|
1316
|
-
listItemIndent: 1,
|
|
1317
|
-
emphasis: '_',
|
|
1318
|
-
strong: '_',
|
|
1319
|
-
bullet: '*',
|
|
1320
|
-
incrementListMarker: false
|
|
1321
|
-
},
|
|
1322
|
-
plugins: [
|
|
1323
|
-
config,
|
|
1324
|
-
['remark-toc', {tight: true}],
|
|
1325
|
-
...projectTypes.PACKAGE === projectType ? [['remark-usage', {heading: 'example'}]] : [],
|
|
1326
|
-
...!vcs ? [['validate-links', {repository: false}]] : []
|
|
1327
|
-
]
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
|
|
1331
|
-
return deepmerge(
|
|
1332
|
-
{
|
|
1333
|
-
devDependencies: [config, 'remark-cli', 'remark-toc'],
|
|
1334
|
-
scripts: {
|
|
1335
|
-
'lint:md': 'remark . --frail',
|
|
1336
|
-
'generate:md': 'remark . --output'
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
{
|
|
1340
|
-
...projectTypes.PACKAGE === projectType && {
|
|
1341
|
-
devDependencies: ['remark-usage'],
|
|
1342
|
-
...dialects$1.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
);
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
async function scaffoldCodeStyle ({
|
|
1349
|
-
projectRoot,
|
|
1350
|
-
projectType,
|
|
1351
|
-
dialect,
|
|
1352
|
-
configs,
|
|
1353
|
-
vcs,
|
|
1354
|
-
configureLinting,
|
|
1355
|
-
buildDirectory,
|
|
1356
|
-
eslint
|
|
1357
|
-
}) {
|
|
1358
|
-
return deepmerge.all(await Promise.all([
|
|
1359
|
-
configs.eslint && configureLinting
|
|
1360
|
-
&& scaffoldEslint({
|
|
1361
|
-
projectRoot,
|
|
1362
|
-
config: configs.eslint,
|
|
1363
|
-
buildDirectory,
|
|
1364
|
-
additionalConfiguration: eslint
|
|
1365
|
-
}),
|
|
1366
|
-
scaffoldRemark({
|
|
1367
|
-
projectRoot,
|
|
1368
|
-
projectType,
|
|
1369
|
-
dialect,
|
|
1370
|
-
vcs,
|
|
1371
|
-
config: configs.remark || '@form8ion/remark-lint-preset'
|
|
1372
|
-
}),
|
|
1373
|
-
scaffold$4({projectRoot, config: configs.prettier})
|
|
1374
|
-
].filter(Boolean)));
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
1425
|
async function scaffolder (options) {
|
|
1378
1426
|
info('Initializing JavaScript project');
|
|
1379
1427
|
|
|
@@ -1474,7 +1522,6 @@ async function scaffolder (options) {
|
|
|
1474
1522
|
configs,
|
|
1475
1523
|
vcs,
|
|
1476
1524
|
configureLinting,
|
|
1477
|
-
buildDirectory: projectTypeResults.buildDirectory,
|
|
1478
1525
|
eslint: verificationResults.eslint
|
|
1479
1526
|
}),
|
|
1480
1527
|
scaffoldProjectTypePlugin({
|