@form8ion/javascript 7.2.1 → 7.2.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 +97 -63
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +112 -78
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
package/lib/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { questionNames as questionNames$2, questions } from '@travi/language-scaffolder-prompts';
|
|
2
2
|
import deepmerge from 'deepmerge';
|
|
3
|
-
import { validateOptions, scaffoldChoice,
|
|
3
|
+
import { validateOptions, scaffoldChoice, projectTypes, dialects as dialects$1, writePackageJson, installDependencies, PROD_DEPENDENCY_TYPE, DEV_DEPENDENCY_TYPE, packageManagers, 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
|
-
import { fileExists,
|
|
8
|
+
import { fileExists, fileTypes, writeConfigFile, applyEnhancers } from '@form8ion/core';
|
|
9
9
|
import { info, error, warn } from '@travi/cli-messages';
|
|
10
10
|
import * as commitConventionPlugin from '@form8ion/commit-convention';
|
|
11
11
|
import { scaffold as scaffold$5 } from '@form8ion/commit-convention';
|
|
@@ -24,7 +24,7 @@ import { resolve } from 'path';
|
|
|
24
24
|
import filedirname from 'filedirname';
|
|
25
25
|
import * as huskyPlugin from '@form8ion/husky';
|
|
26
26
|
import { scaffold as scaffold$2 } from '@form8ion/husky';
|
|
27
|
-
import { write } from '@form8ion/config-file';
|
|
27
|
+
import { write as write$1 } from '@form8ion/config-file';
|
|
28
28
|
import { scaffold as scaffold$4 } from '@form8ion/prettier';
|
|
29
29
|
import { lift as lift$4, scaffold as scaffold$3 } from '@form8ion/eslint';
|
|
30
30
|
|
|
@@ -177,6 +177,90 @@ var enginesEnhancer = /*#__PURE__*/Object.freeze({
|
|
|
177
177
|
lift: lift$1
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
+
function write ({projectRoot, config}) {
|
|
181
|
+
return write$1({path: projectRoot, name: 'babel', format: fileTypes.JSON, config});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function addIgnore ({projectRoot, ignore}) {
|
|
185
|
+
if (ignore) {
|
|
186
|
+
const existingConfig = JSON.parse(await promises.readFile(`${projectRoot}/.babelrc.json`, 'utf-8'));
|
|
187
|
+
|
|
188
|
+
await write({projectRoot, config: {...existingConfig, ignore: [`./${ignore}/`]}});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function scaffoldBabel ({projectRoot, preset}) {
|
|
193
|
+
if (!preset) {
|
|
194
|
+
throw new Error('No babel preset provided. Cannot configure babel transpilation');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
await write({projectRoot, config: {presets: [preset.name]}});
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
devDependencies: ['@babel/register', preset.packageName],
|
|
201
|
+
eslint: {}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function lifter ({buildDirectory, projectRoot}) {
|
|
206
|
+
await addIgnore({ignore: buildDirectory, projectRoot});
|
|
207
|
+
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function predicate ({projectRoot}) {
|
|
212
|
+
return fileExists(`${projectRoot}/.babelrc.json`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function scaffoldTypescript ({config, projectType, projectRoot, testFilenamePattern}) {
|
|
216
|
+
const eslintConfigs = ['typescript'];
|
|
217
|
+
const shareableTsConfigPackage = `${config.scope}/tsconfig`;
|
|
218
|
+
|
|
219
|
+
await writeConfigFile({
|
|
220
|
+
path: projectRoot,
|
|
221
|
+
name: 'tsconfig',
|
|
222
|
+
format: fileTypes.JSON,
|
|
223
|
+
config: {
|
|
224
|
+
$schema: 'https://json.schemastore.org/tsconfig',
|
|
225
|
+
extends: shareableTsConfigPackage,
|
|
226
|
+
compilerOptions: {
|
|
227
|
+
rootDir: 'src',
|
|
228
|
+
...projectTypes.PACKAGE === projectType && {
|
|
229
|
+
outDir: 'lib',
|
|
230
|
+
declaration: true
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
include: ['src/**/*.ts'],
|
|
234
|
+
...testFilenamePattern && {exclude: [testFilenamePattern]}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
eslint: {configs: eslintConfigs},
|
|
240
|
+
eslintConfigs,
|
|
241
|
+
devDependencies: ['typescript', shareableTsConfigPackage],
|
|
242
|
+
vcsIgnore: {files: ['tsconfig.tsbuildinfo']}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function scaffoldDialect ({dialect, projectType, projectRoot, configs, testFilenamePattern}) {
|
|
247
|
+
switch (dialect) {
|
|
248
|
+
case dialects$1.BABEL:
|
|
249
|
+
return scaffoldBabel({preset: configs.babelPreset, projectRoot});
|
|
250
|
+
case dialects$1.TYPESCRIPT:
|
|
251
|
+
return scaffoldTypescript({config: configs.typescript, projectType, projectRoot, testFilenamePattern});
|
|
252
|
+
default:
|
|
253
|
+
return {};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var dialects = /*#__PURE__*/Object.freeze({
|
|
258
|
+
__proto__: null,
|
|
259
|
+
scaffold: scaffoldDialect,
|
|
260
|
+
test: predicate,
|
|
261
|
+
lift: lifter
|
|
262
|
+
});
|
|
263
|
+
|
|
180
264
|
function scaffoldScripts () {
|
|
181
265
|
return {};
|
|
182
266
|
}
|
|
@@ -234,7 +318,7 @@ function buildPackageDetails ({
|
|
|
234
318
|
name: packageName,
|
|
235
319
|
description,
|
|
236
320
|
license,
|
|
237
|
-
type: dialects.ESM === dialect ? 'module' : 'commonjs',
|
|
321
|
+
type: dialects$1.ESM === dialect ? 'module' : 'commonjs',
|
|
238
322
|
...defineVcsHostDetails(vcs, projectType, packageName, pathWithinParent),
|
|
239
323
|
author: `${author.name}${author.email ? ` <${author.email}>` : ''}${author.url ? ` (${author.url})` : ''}`,
|
|
240
324
|
scripts: scaffoldScripts()
|
|
@@ -324,15 +408,24 @@ async function resolvePackageManager ({projectRoot, packageManager}) {
|
|
|
324
408
|
async function lift ({projectRoot, vcs, results}) {
|
|
325
409
|
info('Lifting JavaScript-specific details');
|
|
326
410
|
|
|
327
|
-
const {
|
|
411
|
+
const {
|
|
412
|
+
scripts,
|
|
413
|
+
tags,
|
|
414
|
+
eslintConfigs,
|
|
415
|
+
eslint,
|
|
416
|
+
dependencies,
|
|
417
|
+
devDependencies,
|
|
418
|
+
packageManager: manager,
|
|
419
|
+
buildDirectory
|
|
420
|
+
} = results;
|
|
328
421
|
|
|
329
422
|
const packageManager = await resolvePackageManager({projectRoot, packageManager: manager});
|
|
330
423
|
|
|
331
424
|
const eslintResults = await lift$4({projectRoot, configs: [...eslintConfigs || [], ...eslint?.configs || []]});
|
|
332
425
|
const enhancerResults = await applyEnhancers({
|
|
333
426
|
results,
|
|
334
|
-
enhancers: [huskyPlugin, enginesEnhancer, coveragePlugin, commitConventionPlugin],
|
|
335
|
-
options: {packageManager, projectRoot, vcs}
|
|
427
|
+
enhancers: [huskyPlugin, enginesEnhancer, coveragePlugin, commitConventionPlugin, dialects],
|
|
428
|
+
options: {packageManager, projectRoot, vcs, buildDirectory}
|
|
336
429
|
});
|
|
337
430
|
|
|
338
431
|
await liftPackage(
|
|
@@ -434,10 +527,10 @@ function validate(options) {
|
|
|
434
527
|
|
|
435
528
|
function buildDialectChoices ({babelPreset, typescript}) {
|
|
436
529
|
return [
|
|
437
|
-
{name: 'Common JS (no transpilation)', value: dialects.COMMON_JS, short: 'cjs'},
|
|
438
|
-
...babelPreset ? [{name: 'Modern JavaScript (transpiled)', value: dialects.BABEL, short: 'modern'}] : [],
|
|
439
|
-
{name: 'ESM-only (no transpilation)', value: dialects.ESM, short: 'esm'},
|
|
440
|
-
...typescript ? [{name: 'TypeScript', value: dialects.TYPESCRIPT, short: 'ts'}] : []
|
|
530
|
+
{name: 'Common JS (no transpilation)', value: dialects$1.COMMON_JS, short: 'cjs'},
|
|
531
|
+
...babelPreset ? [{name: 'Modern JavaScript (transpiled)', value: dialects$1.BABEL, short: 'modern'}] : [],
|
|
532
|
+
{name: 'ESM-only (no transpilation)', value: dialects$1.ESM, short: 'esm'},
|
|
533
|
+
...typescript ? [{name: 'TypeScript', value: dialects$1.TYPESCRIPT, short: 'ts'}] : []
|
|
441
534
|
];
|
|
442
535
|
}
|
|
443
536
|
|
|
@@ -620,64 +713,6 @@ async function prompt(
|
|
|
620
713
|
};
|
|
621
714
|
}
|
|
622
715
|
|
|
623
|
-
async function scaffoldBabel ({projectRoot, preset, buildDirectory}) {
|
|
624
|
-
if (!preset) {
|
|
625
|
-
throw new Error('No babel preset provided. Cannot configure babel transpilation');
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
await write({
|
|
629
|
-
path: projectRoot,
|
|
630
|
-
name: 'babel',
|
|
631
|
-
format: fileTypes.JSON,
|
|
632
|
-
config: {presets: [preset.name], ignore: [`./${buildDirectory}/`]}
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
return {
|
|
636
|
-
devDependencies: ['@babel/register', preset.packageName],
|
|
637
|
-
eslint: {}
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
async function scaffoldTypescript ({config, projectType, projectRoot, testFilenamePattern}) {
|
|
642
|
-
const eslintConfigs = ['typescript'];
|
|
643
|
-
const shareableTsConfigPackage = `${config.scope}/tsconfig`;
|
|
644
|
-
|
|
645
|
-
await promises.writeFile(
|
|
646
|
-
`${projectRoot}/tsconfig.json`,
|
|
647
|
-
JSON.stringify({
|
|
648
|
-
$schema: 'https://json.schemastore.org/tsconfig',
|
|
649
|
-
extends: shareableTsConfigPackage,
|
|
650
|
-
compilerOptions: {
|
|
651
|
-
rootDir: 'src',
|
|
652
|
-
...projectTypes.PACKAGE === projectType && {
|
|
653
|
-
outDir: 'lib',
|
|
654
|
-
declaration: true
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
include: ['src/**/*.ts'],
|
|
658
|
-
...testFilenamePattern && {exclude: [testFilenamePattern]}
|
|
659
|
-
})
|
|
660
|
-
);
|
|
661
|
-
|
|
662
|
-
return {
|
|
663
|
-
eslint: {configs: eslintConfigs},
|
|
664
|
-
eslintConfigs,
|
|
665
|
-
devDependencies: ['typescript', shareableTsConfigPackage],
|
|
666
|
-
vcsIgnore: {files: ['tsconfig.tsbuildinfo']}
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function scaffoldDialect ({dialect, projectType, projectRoot, configs, buildDirectory, testFilenamePattern}) {
|
|
671
|
-
switch (dialect) {
|
|
672
|
-
case dialects.BABEL:
|
|
673
|
-
return scaffoldBabel({preset: configs.babelPreset, projectRoot, buildDirectory});
|
|
674
|
-
case dialects.TYPESCRIPT:
|
|
675
|
-
return scaffoldTypescript({config: configs.typescript, projectType, projectRoot, testFilenamePattern});
|
|
676
|
-
default:
|
|
677
|
-
return {};
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
716
|
function projectWillNotBeConsumed(projectType) {
|
|
682
717
|
return projectTypes.APPLICATION === projectType || projectTypes.CLI === projectType;
|
|
683
718
|
}
|
|
@@ -885,7 +920,7 @@ async function buildDetails ({
|
|
|
885
920
|
dialect,
|
|
886
921
|
decisions
|
|
887
922
|
}) {
|
|
888
|
-
if (dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
|
|
923
|
+
if (dialects$1.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
|
|
889
924
|
|
|
890
925
|
const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
|
|
891
926
|
|
|
@@ -942,14 +977,14 @@ async function scaffoldPackageType ({
|
|
|
942
977
|
mergeIntoExistingPackageJson({
|
|
943
978
|
projectRoot,
|
|
944
979
|
config: {
|
|
945
|
-
files: ['example.js', ...dialects.COMMON_JS === dialect ? ['index.js'] : ['lib/']],
|
|
980
|
+
files: ['example.js', ...dialects$1.COMMON_JS === dialect ? ['index.js'] : ['lib/']],
|
|
946
981
|
publishConfig: {
|
|
947
982
|
access: 'Public' === visibility ? 'public' : 'restricted',
|
|
948
983
|
...publishRegistry && {registry: publishRegistry}
|
|
949
984
|
},
|
|
950
985
|
sideEffects: false,
|
|
951
986
|
...'Public' === visibility && {runkitExampleFilename: './example.js'},
|
|
952
|
-
...dialects.BABEL === dialect && {
|
|
987
|
+
...dialects$1.BABEL === dialect && {
|
|
953
988
|
main: './lib/index.js',
|
|
954
989
|
module: './lib/index.mjs',
|
|
955
990
|
exports: {
|
|
@@ -957,11 +992,11 @@ async function scaffoldPackageType ({
|
|
|
957
992
|
import: './lib/index.mjs'
|
|
958
993
|
}
|
|
959
994
|
},
|
|
960
|
-
...dialects.ESM === dialect && {
|
|
995
|
+
...dialects$1.ESM === dialect && {
|
|
961
996
|
main: './lib/index.mjs',
|
|
962
997
|
exports: './lib/index.mjs'
|
|
963
998
|
},
|
|
964
|
-
...dialects.TYPESCRIPT === dialect && {
|
|
999
|
+
...dialects$1.TYPESCRIPT === dialect && {
|
|
965
1000
|
main: './lib/index.js',
|
|
966
1001
|
module: './lib/index.mjs',
|
|
967
1002
|
types: './lib/index.d.ts',
|
|
@@ -1272,7 +1307,7 @@ async function scaffoldEslint ({config, projectRoot, buildDirectory, additionalC
|
|
|
1272
1307
|
}
|
|
1273
1308
|
|
|
1274
1309
|
async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
|
|
1275
|
-
await write({
|
|
1310
|
+
await write$1({
|
|
1276
1311
|
format: fileTypes.JSON,
|
|
1277
1312
|
path: projectRoot,
|
|
1278
1313
|
name: 'remark',
|
|
@@ -1304,7 +1339,7 @@ async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect})
|
|
|
1304
1339
|
{
|
|
1305
1340
|
...projectTypes.PACKAGE === projectType && {
|
|
1306
1341
|
devDependencies: ['remark-usage'],
|
|
1307
|
-
...dialects.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
|
|
1342
|
+
...dialects$1.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
|
|
1308
1343
|
}
|
|
1309
1344
|
}
|
|
1310
1345
|
);
|
|
@@ -1430,7 +1465,6 @@ async function scaffolder (options) {
|
|
|
1430
1465
|
configs,
|
|
1431
1466
|
projectRoot,
|
|
1432
1467
|
projectType,
|
|
1433
|
-
buildDirectory: projectTypeResults.buildDirectory,
|
|
1434
1468
|
testFilenamePattern: verificationResults.testFilenamePattern
|
|
1435
1469
|
}),
|
|
1436
1470
|
scaffoldCodeStyle({
|
|
@@ -1470,8 +1504,8 @@ async function scaffolder (options) {
|
|
|
1470
1504
|
scaffoldChoice(ciServices, ci, {projectRoot, vcs, visibility, projectType, projectName, nodeVersion, tests}),
|
|
1471
1505
|
scaffold$5({projectRoot, projectType, configs, pathWithinParent})
|
|
1472
1506
|
])),
|
|
1473
|
-
projectTypePluginResults,
|
|
1474
1507
|
projectTypeResults,
|
|
1508
|
+
projectTypePluginResults,
|
|
1475
1509
|
verificationResults,
|
|
1476
1510
|
codeStyleResults,
|
|
1477
1511
|
npmResults,
|