@form8ion/javascript 13.0.0-beta.1 → 13.0.0-beta.10
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/README.md +15 -5
- package/example.js +67 -59
- package/lib/index.js +439 -459
- package/lib/index.js.map +1 -1
- package/package.json +19 -27
- package/lib/index.mjs +0 -1824
- package/lib/index.mjs.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,69 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var sortProperties = require('sort-object-keys');
|
|
32
|
-
|
|
33
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
34
|
-
|
|
35
|
-
function _interopNamespace(e) {
|
|
36
|
-
if (e && e.__esModule) return e;
|
|
37
|
-
var n = Object.create(null);
|
|
38
|
-
if (e) {
|
|
39
|
-
Object.keys(e).forEach(function (k) {
|
|
40
|
-
if (k !== 'default') {
|
|
41
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
42
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () { return e[k]; }
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
n["default"] = e;
|
|
50
|
-
return Object.freeze(n);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge);
|
|
54
|
-
var joi__default = /*#__PURE__*/_interopDefaultLegacy(joi);
|
|
55
|
-
var commitConventionPlugin__namespace = /*#__PURE__*/_interopNamespace(commitConventionPlugin);
|
|
56
|
-
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
|
|
57
|
-
var npmConf__default = /*#__PURE__*/_interopDefaultLegacy(npmConf);
|
|
58
|
-
var validatePackageName__default = /*#__PURE__*/_interopDefaultLegacy(validatePackageName);
|
|
59
|
-
var mustache__default = /*#__PURE__*/_interopDefaultLegacy(mustache);
|
|
60
|
-
var mkdir__default = /*#__PURE__*/_interopDefaultLegacy(mkdir);
|
|
61
|
-
var touch__default = /*#__PURE__*/_interopDefaultLegacy(touch);
|
|
62
|
-
var camelcase__default = /*#__PURE__*/_interopDefaultLegacy(camelcase);
|
|
63
|
-
var filedirname__default = /*#__PURE__*/_interopDefaultLegacy(filedirname);
|
|
64
|
-
var huskyPlugin__namespace = /*#__PURE__*/_interopNamespace(huskyPlugin);
|
|
65
|
-
var eslintPlugin__namespace = /*#__PURE__*/_interopNamespace(eslintPlugin);
|
|
66
|
-
var sortProperties__default = /*#__PURE__*/_interopDefaultLegacy(sortProperties);
|
|
1
|
+
import { questionNames as questionNames$2, questions } from '@travi/language-scaffolder-prompts';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
import { fileTypes, fileExists, optionsSchemas, validateOptions, applyEnhancers, writeConfigFile } from '@form8ion/core';
|
|
4
|
+
import { scaffoldChoice, projectTypes as projectTypes$1, packageManagers as packageManagers$1, mergeIntoExistingPackageJson, dialects as dialects$1, writePackageJson, DEV_DEPENDENCY_TYPE, PROD_DEPENDENCY_TYPE } from '@form8ion/javascript-core';
|
|
5
|
+
import { prompt as prompt$1 } from '@form8ion/overridable-prompts';
|
|
6
|
+
import joi from 'joi';
|
|
7
|
+
import { scaffold, lift as lift$3 } from '@form8ion/codecov';
|
|
8
|
+
import { write as write$1, load } from '@form8ion/config-file';
|
|
9
|
+
import { info, warn, error } from '@travi/cli-messages';
|
|
10
|
+
import * as commitConventionPlugin from '@form8ion/commit-convention';
|
|
11
|
+
import { scaffold as scaffold$4 } from '@form8ion/commit-convention';
|
|
12
|
+
import execa from '@form8ion/execa-wrapper';
|
|
13
|
+
import npmConf from 'npm-conf';
|
|
14
|
+
import { EOL } from 'os';
|
|
15
|
+
import validatePackageName from 'validate-npm-package-name';
|
|
16
|
+
import { promises } from 'fs';
|
|
17
|
+
import mustache from 'mustache';
|
|
18
|
+
import mkdir from 'make-dir';
|
|
19
|
+
import touch from 'touch';
|
|
20
|
+
import camelcase from 'camelcase';
|
|
21
|
+
import { resolve } from 'path';
|
|
22
|
+
import filedirname from 'filedirname';
|
|
23
|
+
import * as huskyPlugin from '@form8ion/husky';
|
|
24
|
+
import { scaffold as scaffold$3 } from '@form8ion/husky';
|
|
25
|
+
import { promises as promises$1 } from 'node:fs';
|
|
26
|
+
import { stringify, parse } from 'ini';
|
|
27
|
+
import { scaffold as scaffold$2 } from '@form8ion/prettier';
|
|
28
|
+
import * as eslintPlugin from '@form8ion/eslint';
|
|
29
|
+
import { scaffold as scaffold$1, test as test$1 } from '@form8ion/eslint';
|
|
30
|
+
import sortProperties from 'sort-object-keys';
|
|
67
31
|
|
|
68
32
|
const questionNames$1 = {
|
|
69
33
|
UNIT_TEST_FRAMEWORK: 'unitTestFramework',
|
|
@@ -84,9 +48,9 @@ const questionNames$1 = {
|
|
|
84
48
|
};
|
|
85
49
|
|
|
86
50
|
async function scaffoldC8 ({projectRoot}) {
|
|
87
|
-
await
|
|
51
|
+
await write$1({
|
|
88
52
|
name: 'c8',
|
|
89
|
-
format:
|
|
53
|
+
format: fileTypes.JSON,
|
|
90
54
|
path: projectRoot,
|
|
91
55
|
config: {
|
|
92
56
|
reporter: ['lcov', 'text-summary', 'html'],
|
|
@@ -102,27 +66,27 @@ async function scaffoldC8 ({projectRoot}) {
|
|
|
102
66
|
}
|
|
103
67
|
|
|
104
68
|
async function scaffoldCoverage ({projectRoot, vcs, visibility, pathWithinParent}) {
|
|
105
|
-
return
|
|
69
|
+
return deepmerge(await scaffoldC8({projectRoot}), await scaffold({vcs, visibility, pathWithinParent}));
|
|
106
70
|
}
|
|
107
71
|
|
|
108
72
|
function nycIsConfigured ({projectRoot}) {
|
|
109
|
-
return
|
|
73
|
+
return fileExists(`${projectRoot}/.nycrc`);
|
|
110
74
|
}
|
|
111
75
|
|
|
112
76
|
async function removeDependencies ({packageManager, dependencies}) {
|
|
113
|
-
await
|
|
77
|
+
await execa(packageManager, ['remove', ...dependencies]);
|
|
114
78
|
}
|
|
115
79
|
|
|
116
80
|
async function removeNyc ({projectRoot, packageManager}) {
|
|
117
81
|
await Promise.all([
|
|
118
|
-
|
|
119
|
-
|
|
82
|
+
promises.unlink(`${projectRoot}/.nycrc`),
|
|
83
|
+
promises.rm(`${projectRoot}/.nyc_output`, {recursive: true, force: true}),
|
|
120
84
|
removeDependencies({packageManager, dependencies: ['nyc', '@istanbuljs/nyc-config-babel', 'babel-plugin-istanbul']})
|
|
121
85
|
]);
|
|
122
86
|
}
|
|
123
87
|
|
|
124
88
|
async function lift$2({projectRoot, packageManager, vcs}) {
|
|
125
|
-
const codecovResults = await
|
|
89
|
+
const codecovResults = await lift$3({projectRoot, packageManager, vcs});
|
|
126
90
|
|
|
127
91
|
if (await nycIsConfigured({projectRoot})) {
|
|
128
92
|
const [c8Results] = await Promise.all([
|
|
@@ -130,7 +94,7 @@ async function lift$2({projectRoot, packageManager, vcs}) {
|
|
|
130
94
|
removeNyc({projectRoot, packageManager})
|
|
131
95
|
]);
|
|
132
96
|
|
|
133
|
-
return
|
|
97
|
+
return deepmerge.all([
|
|
134
98
|
c8Results,
|
|
135
99
|
codecovResults,
|
|
136
100
|
{
|
|
@@ -147,10 +111,10 @@ async function lift$2({projectRoot, packageManager, vcs}) {
|
|
|
147
111
|
}
|
|
148
112
|
|
|
149
113
|
function c8IsConfigured ({projectRoot}) {
|
|
150
|
-
return
|
|
114
|
+
return fileExists(`${projectRoot}/.c8rc.json`);
|
|
151
115
|
}
|
|
152
116
|
|
|
153
|
-
async function tester$
|
|
117
|
+
async function tester$5 ({projectRoot}) {
|
|
154
118
|
const [c8Exists, nycExists] = await Promise.all([c8IsConfigured({projectRoot}), nycIsConfigured({projectRoot})]);
|
|
155
119
|
|
|
156
120
|
return c8Exists || nycExists;
|
|
@@ -158,46 +122,144 @@ async function tester$4 ({projectRoot}) {
|
|
|
158
122
|
|
|
159
123
|
var coveragePlugin = /*#__PURE__*/Object.freeze({
|
|
160
124
|
__proto__: null,
|
|
161
|
-
scaffold: scaffoldCoverage,
|
|
162
125
|
lift: lift$2,
|
|
163
|
-
|
|
126
|
+
scaffold: scaffoldCoverage,
|
|
127
|
+
test: tester$5
|
|
164
128
|
});
|
|
165
129
|
|
|
166
|
-
const unitTestFrameworksSchema = joi__default["default"].object().required().pattern(/^/, joi__default["default"].object({
|
|
167
|
-
scaffolder: joi__default["default"].func().arity(1).required()
|
|
168
|
-
}));
|
|
169
|
-
|
|
170
130
|
async function chooseFramework ({frameworks, decisions}) {
|
|
171
131
|
if (!Object.keys(frameworks).length) return 'Other';
|
|
172
132
|
|
|
173
|
-
const answers = await
|
|
133
|
+
const answers = await prompt$1([{
|
|
174
134
|
name: questionNames$1.UNIT_TEST_FRAMEWORK,
|
|
175
135
|
type: 'list',
|
|
176
136
|
message: 'Which type of unit testing framework should be used?',
|
|
177
|
-
choices: [...Object.keys(frameworks),
|
|
137
|
+
choices: [...Object.keys(frameworks), 'Other']
|
|
178
138
|
}], decisions);
|
|
179
139
|
|
|
180
140
|
return answers[questionNames$1.UNIT_TEST_FRAMEWORK];
|
|
181
141
|
}
|
|
182
142
|
|
|
143
|
+
const pluginsSchema = joi.object().pattern(/^/, optionsSchemas.form8ionPlugin).default({});
|
|
144
|
+
|
|
183
145
|
async function scaffoldUnitTesting ({projectRoot, frameworks, decisions, visibility, vcs, pathWithinParent, dialect}) {
|
|
184
|
-
const validatedFrameworks =
|
|
146
|
+
const validatedFrameworks = validateOptions(pluginsSchema, frameworks);
|
|
185
147
|
const [framework, coverage] = await Promise.all([
|
|
186
148
|
chooseFramework({frameworks: validatedFrameworks, decisions})
|
|
187
|
-
.then(chosenFramework =>
|
|
149
|
+
.then(chosenFramework => scaffoldChoice(validatedFrameworks, chosenFramework, {projectRoot, dialect})),
|
|
188
150
|
scaffoldCoverage({projectRoot, vcs, visibility, pathWithinParent})
|
|
189
151
|
]);
|
|
190
152
|
|
|
191
|
-
return
|
|
153
|
+
return deepmerge.all([
|
|
192
154
|
{scripts: {'test:unit': 'cross-env NODE_ENV=test c8 run-s test:unit:base'}},
|
|
193
155
|
framework,
|
|
194
156
|
coverage
|
|
195
157
|
]);
|
|
196
158
|
}
|
|
197
159
|
|
|
160
|
+
function tester$4 () {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function writeNpmConfig ({projectRoot, config}) {
|
|
165
|
+
await promises$1.writeFile(`${projectRoot}/.npmrc`, stringify(config));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function projectWillNotBeConsumed(projectType) {
|
|
169
|
+
return projectTypes$1.APPLICATION === projectType || projectTypes$1.CLI === projectType;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function scaffoldNpmConfig ({
|
|
173
|
+
projectRoot,
|
|
174
|
+
projectType,
|
|
175
|
+
registries
|
|
176
|
+
}) {
|
|
177
|
+
await writeNpmConfig({
|
|
178
|
+
projectRoot,
|
|
179
|
+
config: {
|
|
180
|
+
'update-notifier': false,
|
|
181
|
+
...projectWillNotBeConsumed(projectType) && {'save-exact': true},
|
|
182
|
+
...Object.fromEntries(Object.entries(registries)
|
|
183
|
+
.filter(([scope]) => 'publish' !== scope)
|
|
184
|
+
.map(([scope, url]) => {
|
|
185
|
+
if ('registry' === scope) return ['registry', url];
|
|
186
|
+
|
|
187
|
+
return [`@${scope}:registry`, url];
|
|
188
|
+
}))
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
return {scripts: {'lint:peer': 'npm ls >/dev/null'}};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function tester$3 ({projectRoot}) {
|
|
196
|
+
return fileExists(`${projectRoot}/.npmrc`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function lifter$5 ({projectRoot}) {
|
|
200
|
+
const pathToConfig = `${projectRoot}/.npmrc`;
|
|
201
|
+
|
|
202
|
+
const {
|
|
203
|
+
provenance,
|
|
204
|
+
'engines-strict': enginesStrict,
|
|
205
|
+
...remainingProperties
|
|
206
|
+
} = parse(await promises$1.readFile(pathToConfig, 'utf-8'));
|
|
207
|
+
|
|
208
|
+
await promises$1.writeFile(pathToConfig, stringify(remainingProperties));
|
|
209
|
+
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async function readNpmConfig ({projectRoot}) {
|
|
214
|
+
const pathToConfig = `${projectRoot}/.npmrc`;
|
|
215
|
+
|
|
216
|
+
if (!(await fileExists(pathToConfig))) return {};
|
|
217
|
+
|
|
218
|
+
return parse(await promises$1.readFile(pathToConfig, 'utf-8'));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var npmConfigPlugin = /*#__PURE__*/Object.freeze({
|
|
222
|
+
__proto__: null,
|
|
223
|
+
lift: lifter$5,
|
|
224
|
+
read: readNpmConfig,
|
|
225
|
+
scaffold: scaffoldNpmConfig,
|
|
226
|
+
test: tester$3,
|
|
227
|
+
write: writeNpmConfig
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
function buildRegistriesConfig (registries = {}) {
|
|
231
|
+
return Object.entries(registries)
|
|
232
|
+
.filter(([scope]) => 'publish' !== scope)
|
|
233
|
+
.reduce((acc, [scope, url]) => {
|
|
234
|
+
if ('registry' === scope) return {...acc, registry: url};
|
|
235
|
+
|
|
236
|
+
return {...acc, [`@${scope}:registry`]: url};
|
|
237
|
+
}, {registry: 'https://registry.npmjs.org'});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function lifter$4 ({projectRoot, configs}) {
|
|
241
|
+
const registries = buildRegistriesConfig(configs.registries);
|
|
242
|
+
|
|
243
|
+
await writeNpmConfig({
|
|
244
|
+
projectRoot,
|
|
245
|
+
config: {
|
|
246
|
+
...(await readNpmConfig({projectRoot})),
|
|
247
|
+
...registries
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return {};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
var registriesPlugin = /*#__PURE__*/Object.freeze({
|
|
255
|
+
__proto__: null,
|
|
256
|
+
lift: lifter$4,
|
|
257
|
+
test: tester$4
|
|
258
|
+
});
|
|
259
|
+
|
|
198
260
|
async function scaffoldRemark ({config, projectRoot, projectType, vcs}) {
|
|
199
|
-
await
|
|
200
|
-
format:
|
|
261
|
+
await write$1({
|
|
262
|
+
format: fileTypes.JSON,
|
|
201
263
|
path: projectRoot,
|
|
202
264
|
name: 'remark',
|
|
203
265
|
config: {
|
|
@@ -211,13 +273,13 @@ async function scaffoldRemark ({config, projectRoot, projectType, vcs}) {
|
|
|
211
273
|
plugins: [
|
|
212
274
|
config,
|
|
213
275
|
['remark-toc', {tight: true}],
|
|
214
|
-
...
|
|
276
|
+
...projectTypes$1.PACKAGE === projectType ? [['remark-usage', {heading: 'example'}]] : [],
|
|
215
277
|
...!vcs ? [['validate-links', {repository: false}]] : []
|
|
216
278
|
]
|
|
217
279
|
}
|
|
218
280
|
});
|
|
219
281
|
|
|
220
|
-
return
|
|
282
|
+
return deepmerge(
|
|
221
283
|
{
|
|
222
284
|
devDependencies: [config, 'remark-cli', 'remark-toc'],
|
|
223
285
|
scripts: {
|
|
@@ -225,7 +287,7 @@ async function scaffoldRemark ({config, projectRoot, projectType, vcs}) {
|
|
|
225
287
|
'generate:md': 'remark . --output'
|
|
226
288
|
}
|
|
227
289
|
},
|
|
228
|
-
{...
|
|
290
|
+
{...projectTypes$1.PACKAGE === projectType && {devDependencies: ['remark-usage']}}
|
|
229
291
|
);
|
|
230
292
|
}
|
|
231
293
|
|
|
@@ -236,93 +298,37 @@ async function scaffoldCodeStyle ({
|
|
|
236
298
|
vcs,
|
|
237
299
|
configureLinting
|
|
238
300
|
}) {
|
|
239
|
-
return
|
|
301
|
+
return deepmerge.all(await Promise.all([
|
|
240
302
|
configs.eslint
|
|
241
303
|
&& configureLinting
|
|
242
|
-
&&
|
|
304
|
+
&& scaffold$1({projectRoot, config: configs.eslint}),
|
|
243
305
|
scaffoldRemark({
|
|
244
306
|
projectRoot,
|
|
245
307
|
projectType,
|
|
246
308
|
vcs,
|
|
247
309
|
config: configs.remark || '@form8ion/remark-lint-preset'
|
|
248
310
|
}),
|
|
249
|
-
|
|
311
|
+
scaffold$2({projectRoot, config: configs.prettier})
|
|
250
312
|
].filter(Boolean)));
|
|
251
313
|
}
|
|
252
314
|
|
|
253
|
-
function lifter$
|
|
254
|
-
return
|
|
315
|
+
function lifter$3 (options) {
|
|
316
|
+
return applyEnhancers({options, enhancers: [eslintPlugin]});
|
|
255
317
|
}
|
|
256
318
|
|
|
257
|
-
function tester$
|
|
258
|
-
return
|
|
319
|
+
function tester$2 (options) {
|
|
320
|
+
return test$1(options);
|
|
259
321
|
}
|
|
260
322
|
|
|
261
323
|
var codeStylePlugin = /*#__PURE__*/Object.freeze({
|
|
262
324
|
__proto__: null,
|
|
325
|
+
lift: lifter$3,
|
|
263
326
|
scaffold: scaffoldCodeStyle,
|
|
264
|
-
|
|
265
|
-
test: tester$3
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
async function write$1 ({projectRoot, config}) {
|
|
269
|
-
await node_fs.promises.writeFile(`${projectRoot}/.npmrc`, ini.stringify(config));
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function projectWillNotBeConsumed(projectType) {
|
|
273
|
-
return javascriptCore.projectTypes.APPLICATION === projectType || javascriptCore.projectTypes.CLI === projectType;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
async function scaffoldNpmConfig ({
|
|
277
|
-
projectRoot,
|
|
278
|
-
projectType,
|
|
279
|
-
registries
|
|
280
|
-
}) {
|
|
281
|
-
await write$1({
|
|
282
|
-
projectRoot,
|
|
283
|
-
config: {
|
|
284
|
-
'update-notifier': false,
|
|
285
|
-
...projectWillNotBeConsumed(projectType) && {'save-exact': true},
|
|
286
|
-
...Object.fromEntries(Object.entries(registries)
|
|
287
|
-
.filter(([scope]) => 'publish' !== scope)
|
|
288
|
-
.map(([scope, url]) => {
|
|
289
|
-
if ('registry' === scope) return ['registry', url];
|
|
290
|
-
|
|
291
|
-
return [`@${scope}:registry`, url];
|
|
292
|
-
}))
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
return {scripts: {'lint:peer': 'npm ls >/dev/null'}};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function tester$2 ({projectRoot}) {
|
|
300
|
-
return core.fileExists(`${projectRoot}/.npmrc`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async function lifter$3 ({projectRoot}) {
|
|
304
|
-
const pathToConfig = `${projectRoot}/.npmrc`;
|
|
305
|
-
|
|
306
|
-
const {
|
|
307
|
-
provenance,
|
|
308
|
-
'engines-strict': enginesStrict,
|
|
309
|
-
...remainingProperties
|
|
310
|
-
} = ini.parse(await node_fs.promises.readFile(pathToConfig, 'utf-8'));
|
|
311
|
-
|
|
312
|
-
await node_fs.promises.writeFile(pathToConfig, ini.stringify(remainingProperties));
|
|
313
|
-
|
|
314
|
-
return {};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
var npmConfigPlugin = /*#__PURE__*/Object.freeze({
|
|
318
|
-
__proto__: null,
|
|
319
|
-
scaffold: scaffoldNpmConfig,
|
|
320
|
-
test: tester$2,
|
|
321
|
-
lift: lifter$3
|
|
327
|
+
test: tester$2
|
|
322
328
|
});
|
|
323
329
|
|
|
324
330
|
async function test({projectRoot}) {
|
|
325
|
-
const {engines} = JSON.parse(await
|
|
331
|
+
const {engines} = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf8'));
|
|
326
332
|
|
|
327
333
|
return !!engines?.node;
|
|
328
334
|
}
|
|
@@ -337,27 +343,27 @@ async function lift$1({packageDetails: {name}}) {
|
|
|
337
343
|
|
|
338
344
|
var enginesEnhancer = /*#__PURE__*/Object.freeze({
|
|
339
345
|
__proto__: null,
|
|
340
|
-
|
|
341
|
-
|
|
346
|
+
lift: lift$1,
|
|
347
|
+
test: test
|
|
342
348
|
});
|
|
343
349
|
|
|
344
350
|
function buildDocumentationCommand (packageManager) {
|
|
345
|
-
if (
|
|
346
|
-
if (
|
|
351
|
+
if (packageManagers$1.NPM === packageManager) return 'npm run generate:md';
|
|
352
|
+
if (packageManagers$1.YARN === packageManager) return 'yarn generate:md';
|
|
347
353
|
|
|
348
354
|
throw new Error(
|
|
349
355
|
`The ${packageManager} package manager is currently not supported. `
|
|
350
|
-
+ `Only ${Object.values(
|
|
356
|
+
+ `Only ${Object.values(packageManagers$1).join(' and ')} are currently supported.`
|
|
351
357
|
);
|
|
352
358
|
}
|
|
353
359
|
|
|
354
360
|
function getInstallationCommand(packageManager) {
|
|
355
|
-
if (
|
|
356
|
-
if (
|
|
361
|
+
if (packageManagers$1.NPM === packageManager) return 'npm install';
|
|
362
|
+
if (packageManagers$1.YARN === packageManager) return 'yarn add';
|
|
357
363
|
|
|
358
364
|
throw new Error(
|
|
359
365
|
`The ${packageManager} package manager is currently not supported. `
|
|
360
|
-
+ `Only ${Object.values(
|
|
366
|
+
+ `Only ${Object.values(packageManagers$1).join(' and ')} are currently supported.`
|
|
361
367
|
);
|
|
362
368
|
}
|
|
363
369
|
|
|
@@ -423,7 +429,7 @@ async function liftProvenance ({projectRoot, packageDetails}) {
|
|
|
423
429
|
const {publishConfig: {access}} = packageDetails;
|
|
424
430
|
|
|
425
431
|
if ('public' === access) {
|
|
426
|
-
await
|
|
432
|
+
await mergeIntoExistingPackageJson({projectRoot, config: {publishConfig: {provenance: true}}});
|
|
427
433
|
|
|
428
434
|
return enhanceSlsa({provenance: true});
|
|
429
435
|
}
|
|
@@ -435,9 +441,9 @@ async function liftPublishable ({projectRoot, packageDetails}) {
|
|
|
435
441
|
const {name: packageName, publishConfig: {access: packageAccessLevel}} = packageDetails;
|
|
436
442
|
const homepage = `https://npm.im/${packageName}`;
|
|
437
443
|
|
|
438
|
-
await
|
|
444
|
+
await mergeIntoExistingPackageJson({projectRoot, config: {homepage}});
|
|
439
445
|
|
|
440
|
-
return
|
|
446
|
+
return deepmerge(
|
|
441
447
|
await liftProvenance({packageDetails, projectRoot}),
|
|
442
448
|
{
|
|
443
449
|
homepage,
|
|
@@ -457,7 +463,7 @@ async function scaffoldPublishable ({packageName, packageAccessLevel}) {
|
|
|
457
463
|
async function chooseBundler ({bundlers, decisions}) {
|
|
458
464
|
if (!Object.keys(bundlers).length) return 'Other';
|
|
459
465
|
|
|
460
|
-
const answers = await
|
|
466
|
+
const answers = await prompt$1([{
|
|
461
467
|
name: questionNames$1.PACKAGE_BUNDLER,
|
|
462
468
|
type: 'list',
|
|
463
469
|
message: 'Which bundler should be used?',
|
|
@@ -470,32 +476,32 @@ async function chooseBundler ({bundlers, decisions}) {
|
|
|
470
476
|
async function scaffoldBundler ({projectRoot, projectType, bundlers, dialect, decisions}) {
|
|
471
477
|
const chosenBundler = await chooseBundler({bundlers, decisions});
|
|
472
478
|
|
|
473
|
-
return
|
|
479
|
+
return scaffoldChoice(bundlers, chosenBundler, {projectRoot, projectType, dialect});
|
|
474
480
|
}
|
|
475
481
|
|
|
476
482
|
function determinePathToTemplateFile (fileName) {
|
|
477
|
-
const [, __dirname] =
|
|
483
|
+
const [, __dirname] = filedirname();
|
|
478
484
|
|
|
479
|
-
return
|
|
485
|
+
return resolve(__dirname, '..', 'templates', fileName);
|
|
480
486
|
}
|
|
481
487
|
|
|
482
488
|
const defaultBuildDirectory$2 = 'lib';
|
|
483
489
|
|
|
484
490
|
async function createExample(projectRoot, projectName, dialect) {
|
|
485
|
-
return
|
|
491
|
+
return promises.writeFile(
|
|
486
492
|
`${projectRoot}/example.js`,
|
|
487
|
-
|
|
488
|
-
await
|
|
489
|
-
{projectName:
|
|
493
|
+
mustache.render(
|
|
494
|
+
await promises.readFile(determinePathToTemplateFile('example.mustache'), 'utf8'),
|
|
495
|
+
{projectName: camelcase(projectName), esm: dialect === dialects$1.ESM}
|
|
490
496
|
)
|
|
491
497
|
);
|
|
492
498
|
}
|
|
493
499
|
|
|
494
500
|
async function buildDetailsForCommonJsProject({projectRoot, projectName, provideExample}) {
|
|
495
501
|
await Promise.all([
|
|
496
|
-
|
|
502
|
+
touch(`${projectRoot}/index.js`),
|
|
497
503
|
provideExample
|
|
498
|
-
?
|
|
504
|
+
? promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase(projectName)} = require('.');\n`)
|
|
499
505
|
: Promise.resolve()
|
|
500
506
|
]);
|
|
501
507
|
|
|
@@ -512,16 +518,16 @@ async function buildDetails ({
|
|
|
512
518
|
provideExample,
|
|
513
519
|
decisions
|
|
514
520
|
}) {
|
|
515
|
-
if (
|
|
521
|
+
if (dialects$1.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName, provideExample});
|
|
516
522
|
|
|
517
|
-
const pathToCreatedSrcDirectory = await
|
|
523
|
+
const pathToCreatedSrcDirectory = await mkdir(`${projectRoot}/src`);
|
|
518
524
|
const [bundlerResults] = await Promise.all([
|
|
519
|
-
scaffoldBundler({bundlers: packageBundlers, projectRoot, dialect, decisions, projectType:
|
|
525
|
+
scaffoldBundler({bundlers: packageBundlers, projectRoot, dialect, decisions, projectType: projectTypes$1.PACKAGE}),
|
|
520
526
|
provideExample ? await createExample(projectRoot, projectName, dialect) : Promise.resolve,
|
|
521
|
-
|
|
527
|
+
touch(`${pathToCreatedSrcDirectory}/index.js`)
|
|
522
528
|
]);
|
|
523
529
|
|
|
524
|
-
return
|
|
530
|
+
return deepmerge(
|
|
525
531
|
bundlerResults,
|
|
526
532
|
{
|
|
527
533
|
devDependencies: ['rimraf'],
|
|
@@ -562,7 +568,7 @@ async function scaffoldPackageType ({
|
|
|
562
568
|
provideExample,
|
|
563
569
|
publishRegistry
|
|
564
570
|
}) {
|
|
565
|
-
|
|
571
|
+
info('Scaffolding Package Details');
|
|
566
572
|
|
|
567
573
|
const packageAccessLevel = determinePackageAccessLevelFromProjectVisibility({projectVisibility: visibility});
|
|
568
574
|
const [detailsForBuild, publishableResults] = await Promise.all([
|
|
@@ -577,17 +583,17 @@ async function scaffoldPackageType ({
|
|
|
577
583
|
decisions
|
|
578
584
|
}),
|
|
579
585
|
scaffoldPublishable({packageName, packageAccessLevel}),
|
|
580
|
-
|
|
586
|
+
mergeIntoExistingPackageJson({
|
|
581
587
|
projectRoot,
|
|
582
588
|
config: {
|
|
583
|
-
files: ['example.js', ...
|
|
589
|
+
files: ['example.js', ...dialects$1.COMMON_JS === dialect ? ['index.js'] : ['lib/']],
|
|
584
590
|
publishConfig: {
|
|
585
591
|
access: packageAccessLevel,
|
|
586
592
|
...publishRegistry && {registry: publishRegistry}
|
|
587
593
|
},
|
|
588
594
|
sideEffects: false,
|
|
589
595
|
...'Public' === visibility && {runkitExampleFilename: './example.js'},
|
|
590
|
-
...
|
|
596
|
+
...dialects$1.BABEL === dialect && {
|
|
591
597
|
main: './lib/index.js',
|
|
592
598
|
module: './lib/index.mjs',
|
|
593
599
|
exports: {
|
|
@@ -596,11 +602,11 @@ async function scaffoldPackageType ({
|
|
|
596
602
|
import: './lib/index.mjs'
|
|
597
603
|
}
|
|
598
604
|
},
|
|
599
|
-
...
|
|
605
|
+
...dialects$1.ESM === dialect && {
|
|
600
606
|
main: './lib/index.js',
|
|
601
607
|
exports: './lib/index.js'
|
|
602
608
|
},
|
|
603
|
-
...
|
|
609
|
+
...dialects$1.TYPESCRIPT === dialect && {
|
|
604
610
|
main: './lib/index.js',
|
|
605
611
|
module: './lib/index.mjs',
|
|
606
612
|
types: './lib/index.d.ts',
|
|
@@ -614,12 +620,13 @@ async function scaffoldPackageType ({
|
|
|
614
620
|
})
|
|
615
621
|
]);
|
|
616
622
|
|
|
617
|
-
return
|
|
623
|
+
return deepmerge.all([
|
|
618
624
|
publishableResults,
|
|
619
625
|
{
|
|
620
626
|
documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager, provideExample}),
|
|
621
627
|
nextSteps: [
|
|
622
628
|
{summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
|
|
629
|
+
{summary: 'Define supported node.js versions as `engines.node` in the `package.json` file'},
|
|
623
630
|
{summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
|
|
624
631
|
]
|
|
625
632
|
},
|
|
@@ -638,9 +645,9 @@ async function isPackage ({packageDetails: {exports, publishConfig, bin}}) {
|
|
|
638
645
|
const defaultBuildDirectory$1 = 'public';
|
|
639
646
|
|
|
640
647
|
async function scaffoldApplicationType ({projectRoot}) {
|
|
641
|
-
|
|
648
|
+
info('Scaffolding Application Details');
|
|
642
649
|
|
|
643
|
-
await
|
|
650
|
+
await mergeIntoExistingPackageJson({projectRoot, config: {private: true}});
|
|
644
651
|
|
|
645
652
|
const buildDirectory = defaultBuildDirectory$1;
|
|
646
653
|
|
|
@@ -663,9 +670,9 @@ function isApplication ({packageDetails}) {
|
|
|
663
670
|
}
|
|
664
671
|
|
|
665
672
|
async function scaffoldMonorepoType ({projectRoot}) {
|
|
666
|
-
|
|
673
|
+
info('Scaffolding Monorepo Details');
|
|
667
674
|
|
|
668
|
-
await
|
|
675
|
+
await mergeIntoExistingPackageJson({projectRoot, config: {private: true}});
|
|
669
676
|
|
|
670
677
|
return {
|
|
671
678
|
nextSteps: [{
|
|
@@ -689,9 +696,9 @@ async function scaffoldCliType ({
|
|
|
689
696
|
}) {
|
|
690
697
|
const packageAccessLevel = determinePackageAccessLevelFromProjectVisibility({projectVisibility: visibility});
|
|
691
698
|
const [bundlerResults, publishableResults] = await Promise.all([
|
|
692
|
-
scaffoldBundler({bundlers: packageBundlers, projectRoot, dialect, decisions, projectType:
|
|
699
|
+
scaffoldBundler({bundlers: packageBundlers, projectRoot, dialect, decisions, projectType: projectTypes$1.CLI}),
|
|
693
700
|
scaffoldPublishable({packageName, packageAccessLevel}),
|
|
694
|
-
|
|
701
|
+
mergeIntoExistingPackageJson({
|
|
695
702
|
projectRoot,
|
|
696
703
|
config: {
|
|
697
704
|
bin: {},
|
|
@@ -704,7 +711,7 @@ async function scaffoldCliType ({
|
|
|
704
711
|
})
|
|
705
712
|
]);
|
|
706
713
|
|
|
707
|
-
return
|
|
714
|
+
return deepmerge.all([
|
|
708
715
|
publishableResults,
|
|
709
716
|
bundlerResults,
|
|
710
717
|
{
|
|
@@ -718,7 +725,7 @@ async function scaffoldCliType ({
|
|
|
718
725
|
devDependencies: ['rimraf'],
|
|
719
726
|
vcsIgnore: {files: [], directories: [`/${defaultBuildDirectory}/`]},
|
|
720
727
|
buildDirectory: defaultBuildDirectory,
|
|
721
|
-
nextSteps: []
|
|
728
|
+
nextSteps: [{summary: 'Define supported node.js versions as `engines.node` in the `package.json` file'}]
|
|
722
729
|
}
|
|
723
730
|
]);
|
|
724
731
|
}
|
|
@@ -746,7 +753,7 @@ async function scaffoldProjectType ({
|
|
|
746
753
|
publishRegistry
|
|
747
754
|
}) {
|
|
748
755
|
switch (projectType) {
|
|
749
|
-
case
|
|
756
|
+
case projectTypes$1.PACKAGE:
|
|
750
757
|
return scaffoldPackageType({
|
|
751
758
|
projectRoot,
|
|
752
759
|
projectName,
|
|
@@ -760,9 +767,9 @@ async function scaffoldProjectType ({
|
|
|
760
767
|
provideExample,
|
|
761
768
|
publishRegistry
|
|
762
769
|
});
|
|
763
|
-
case
|
|
770
|
+
case projectTypes$1.APPLICATION:
|
|
764
771
|
return scaffoldApplicationType({projectRoot});
|
|
765
|
-
case
|
|
772
|
+
case projectTypes$1.CLI:
|
|
766
773
|
return scaffoldCliType({
|
|
767
774
|
packageName,
|
|
768
775
|
visibility,
|
|
@@ -772,7 +779,7 @@ async function scaffoldProjectType ({
|
|
|
772
779
|
decisions,
|
|
773
780
|
packageBundlers
|
|
774
781
|
});
|
|
775
|
-
case
|
|
782
|
+
case projectTypes$1.MONOREPO:
|
|
776
783
|
return scaffoldMonorepoType({projectRoot});
|
|
777
784
|
case 'Other':
|
|
778
785
|
return {};
|
|
@@ -800,7 +807,7 @@ async function lifter$2 ({projectRoot, packageDetails, vcs}) {
|
|
|
800
807
|
if (vcsRepositoryHostedOnGithub(vcs)) {
|
|
801
808
|
homepage = `https://github.com/${vcs.owner}/${vcs.name}#readme`;
|
|
802
809
|
|
|
803
|
-
await
|
|
810
|
+
await mergeIntoExistingPackageJson({projectRoot, config: {homepage}});
|
|
804
811
|
}
|
|
805
812
|
|
|
806
813
|
return {homepage};
|
|
@@ -808,18 +815,22 @@ async function lifter$2 ({projectRoot, packageDetails, vcs}) {
|
|
|
808
815
|
|
|
809
816
|
var projectTypes = /*#__PURE__*/Object.freeze({
|
|
810
817
|
__proto__: null,
|
|
818
|
+
lift: lifter$2,
|
|
811
819
|
scaffold: scaffoldProjectType,
|
|
812
|
-
test: tester$1
|
|
813
|
-
lift: lifter$2
|
|
820
|
+
test: tester$1
|
|
814
821
|
});
|
|
815
822
|
|
|
816
823
|
function write ({projectRoot, config}) {
|
|
817
|
-
return
|
|
824
|
+
return write$1({path: projectRoot, name: 'babel', format: fileTypes.JSON, config});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function loadConfig () {
|
|
828
|
+
return load({name: 'babel'});
|
|
818
829
|
}
|
|
819
830
|
|
|
820
831
|
async function addIgnore ({projectRoot, ignore}) {
|
|
821
832
|
if (ignore) {
|
|
822
|
-
const existingConfig =
|
|
833
|
+
const existingConfig = await loadConfig();
|
|
823
834
|
|
|
824
835
|
await write({projectRoot, config: {...existingConfig, ignore: [`./${ignore}/`]}});
|
|
825
836
|
}
|
|
@@ -845,22 +856,22 @@ async function lifter$1 ({results, projectRoot}) {
|
|
|
845
856
|
}
|
|
846
857
|
|
|
847
858
|
function predicate ({projectRoot}) {
|
|
848
|
-
return
|
|
859
|
+
return fileExists(`${projectRoot}/.babelrc.json`);
|
|
849
860
|
}
|
|
850
861
|
|
|
851
862
|
async function scaffoldTypescript ({config, projectType, projectRoot, testFilenamePattern}) {
|
|
852
863
|
const shareableTsConfigPackage = `${config.scope}/tsconfig`;
|
|
853
864
|
|
|
854
|
-
await
|
|
865
|
+
await writeConfigFile({
|
|
855
866
|
path: projectRoot,
|
|
856
867
|
name: 'tsconfig',
|
|
857
|
-
format:
|
|
868
|
+
format: fileTypes.JSON,
|
|
858
869
|
config: {
|
|
859
870
|
$schema: 'https://json.schemastore.org/tsconfig',
|
|
860
871
|
extends: shareableTsConfigPackage,
|
|
861
872
|
compilerOptions: {
|
|
862
873
|
rootDir: 'src',
|
|
863
|
-
...
|
|
874
|
+
...projectTypes$1.PACKAGE === projectType && {
|
|
864
875
|
outDir: 'lib',
|
|
865
876
|
declaration: true
|
|
866
877
|
}
|
|
@@ -879,9 +890,9 @@ async function scaffoldTypescript ({config, projectType, projectRoot, testFilena
|
|
|
879
890
|
|
|
880
891
|
function scaffoldDialect ({dialect, projectType, projectRoot, configs, testFilenamePattern}) {
|
|
881
892
|
switch (dialect) {
|
|
882
|
-
case
|
|
893
|
+
case dialects$1.BABEL:
|
|
883
894
|
return scaffoldBabel({preset: configs.babelPreset, projectRoot});
|
|
884
|
-
case
|
|
895
|
+
case dialects$1.TYPESCRIPT:
|
|
885
896
|
return scaffoldTypescript({config: configs.typescript, projectType, projectRoot, testFilenamePattern});
|
|
886
897
|
default:
|
|
887
898
|
return {};
|
|
@@ -890,11 +901,22 @@ function scaffoldDialect ({dialect, projectType, projectRoot, configs, testFilen
|
|
|
890
901
|
|
|
891
902
|
var dialects = /*#__PURE__*/Object.freeze({
|
|
892
903
|
__proto__: null,
|
|
904
|
+
lift: lifter$1,
|
|
893
905
|
scaffold: scaffoldDialect,
|
|
894
|
-
test: predicate
|
|
895
|
-
lift: lifter$1
|
|
906
|
+
test: predicate
|
|
896
907
|
});
|
|
897
908
|
|
|
909
|
+
function buildPackageName (projectName, scope) {
|
|
910
|
+
const name = `${scope ? `@${scope}/` : ''}${projectName}`;
|
|
911
|
+
|
|
912
|
+
const {validForNewPackages, errors} = validatePackageName(name);
|
|
913
|
+
|
|
914
|
+
if (validForNewPackages) return name;
|
|
915
|
+
if (1 === errors.length && errors.includes('name cannot start with a period')) return projectName.slice(1);
|
|
916
|
+
|
|
917
|
+
throw new Error(`The package name ${name} is invalid:${EOL}\t* ${errors.join(`${EOL}\t* `)}`);
|
|
918
|
+
}
|
|
919
|
+
|
|
898
920
|
function buildPackageDetails ({
|
|
899
921
|
packageName,
|
|
900
922
|
dialect,
|
|
@@ -906,7 +928,7 @@ function buildPackageDetails ({
|
|
|
906
928
|
name: packageName,
|
|
907
929
|
description,
|
|
908
930
|
license,
|
|
909
|
-
type:
|
|
931
|
+
type: dialects$1.ESM === dialect ? 'module' : 'commonjs',
|
|
910
932
|
author: `${author.name}${author.email ? ` <${author.email}>` : ''}${author.url ? ` (${author.url})` : ''}`,
|
|
911
933
|
scripts: {}
|
|
912
934
|
};
|
|
@@ -914,29 +936,33 @@ function buildPackageDetails ({
|
|
|
914
936
|
|
|
915
937
|
async function scaffoldPackage ({
|
|
916
938
|
projectRoot,
|
|
939
|
+
projectName,
|
|
940
|
+
scope,
|
|
917
941
|
dialect,
|
|
918
|
-
packageName,
|
|
919
942
|
license,
|
|
920
943
|
author,
|
|
921
944
|
description
|
|
922
945
|
}) {
|
|
923
|
-
|
|
946
|
+
info('Configuring package.json');
|
|
924
947
|
|
|
925
|
-
const
|
|
926
|
-
packageName,
|
|
927
|
-
dialect,
|
|
928
|
-
license,
|
|
929
|
-
author,
|
|
930
|
-
description
|
|
931
|
-
});
|
|
948
|
+
const packageName = buildPackageName(projectName, scope);
|
|
932
949
|
|
|
933
|
-
await
|
|
950
|
+
await writePackageJson({
|
|
951
|
+
projectRoot,
|
|
952
|
+
config: await buildPackageDetails({
|
|
953
|
+
packageName,
|
|
954
|
+
dialect,
|
|
955
|
+
license,
|
|
956
|
+
author,
|
|
957
|
+
description
|
|
958
|
+
})
|
|
959
|
+
});
|
|
934
960
|
|
|
935
|
-
return {};
|
|
961
|
+
return {packageName};
|
|
936
962
|
}
|
|
937
963
|
|
|
938
964
|
function sortPackageProperties (packageContents) {
|
|
939
|
-
return
|
|
965
|
+
return sortProperties(
|
|
940
966
|
packageContents,
|
|
941
967
|
[
|
|
942
968
|
'name',
|
|
@@ -986,19 +1012,19 @@ function defineVcsHostDetails (vcs, pathWithinParent) {
|
|
|
986
1012
|
}
|
|
987
1013
|
|
|
988
1014
|
const details = {
|
|
989
|
-
[
|
|
1015
|
+
[packageManagers$1.NPM]: {
|
|
990
1016
|
installationCommand: 'install',
|
|
991
1017
|
installationFlags: {
|
|
992
|
-
[
|
|
993
|
-
[
|
|
1018
|
+
[DEV_DEPENDENCY_TYPE]: `save-${DEV_DEPENDENCY_TYPE}`,
|
|
1019
|
+
[PROD_DEPENDENCY_TYPE]: `save-${PROD_DEPENDENCY_TYPE}`,
|
|
994
1020
|
exact: 'save-exact'
|
|
995
1021
|
}
|
|
996
1022
|
},
|
|
997
|
-
[
|
|
1023
|
+
[packageManagers$1.YARN]: {
|
|
998
1024
|
installationCommand: 'add',
|
|
999
1025
|
installationFlags: {
|
|
1000
|
-
[
|
|
1001
|
-
[
|
|
1026
|
+
[DEV_DEPENDENCY_TYPE]: DEV_DEPENDENCY_TYPE,
|
|
1027
|
+
[PROD_DEPENDENCY_TYPE]: PROD_DEPENDENCY_TYPE,
|
|
1002
1028
|
exact: 'exact'
|
|
1003
1029
|
}
|
|
1004
1030
|
}
|
|
@@ -1016,19 +1042,31 @@ function getExactFlag(manager) {
|
|
|
1016
1042
|
return details[manager].installationFlags.exact;
|
|
1017
1043
|
}
|
|
1018
1044
|
|
|
1019
|
-
async function install$1 (dependencies, dependenciesType, projectRoot, packageManager =
|
|
1045
|
+
async function install$1 (dependencies, dependenciesType, projectRoot, packageManager = packageManagers$1.NPM) {
|
|
1020
1046
|
if (dependencies.length) {
|
|
1021
|
-
|
|
1047
|
+
info(`Installing ${dependenciesType} dependencies`, {level: 'secondary'});
|
|
1022
1048
|
|
|
1023
|
-
await
|
|
1049
|
+
await execa(
|
|
1024
1050
|
`. ~/.nvm/nvm.sh && nvm use && ${packageManager} ${
|
|
1025
1051
|
getInstallationCommandFor(packageManager)
|
|
1026
1052
|
} ${[...new Set(dependencies)].join(' ')} --${getDependencyTypeFlag(packageManager, dependenciesType)}${
|
|
1027
|
-
|
|
1053
|
+
DEV_DEPENDENCY_TYPE === dependenciesType ? ` --${getExactFlag(packageManager)}` : ''
|
|
1028
1054
|
}`,
|
|
1029
1055
|
{shell: true, cwd: projectRoot}
|
|
1030
1056
|
);
|
|
1031
|
-
} else
|
|
1057
|
+
} else warn(`No ${dependenciesType} dependencies to install`);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
async function processDependencies ({dependencies, devDependencies, projectRoot, packageManager}) {
|
|
1061
|
+
info('Processing dependencies');
|
|
1062
|
+
|
|
1063
|
+
try {
|
|
1064
|
+
await install$1(dependencies || [], PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
1065
|
+
await install$1(devDependencies || [], DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
1066
|
+
} catch (e) {
|
|
1067
|
+
error('Failed to update dependencies');
|
|
1068
|
+
error(e, {level: 'secondary'});
|
|
1069
|
+
}
|
|
1032
1070
|
}
|
|
1033
1071
|
|
|
1034
1072
|
function projectWillBeTested(scripts) {
|
|
@@ -1064,55 +1102,43 @@ async function liftPackage ({
|
|
|
1064
1102
|
vcs,
|
|
1065
1103
|
pathWithinParent
|
|
1066
1104
|
}) {
|
|
1067
|
-
|
|
1068
|
-
cliMessages.info('Updating `package.json`', {level: 'secondary'});
|
|
1105
|
+
info('Updating `package.json`', {level: 'secondary'});
|
|
1069
1106
|
|
|
1070
|
-
|
|
1107
|
+
const existingPackageJsonContents = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf-8'));
|
|
1071
1108
|
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
scripts
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
})
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
cliMessages.info('Installing dependencies');
|
|
1109
|
+
await writePackageJson({
|
|
1110
|
+
projectRoot,
|
|
1111
|
+
config: sortPackageProperties({
|
|
1112
|
+
...existingPackageJsonContents,
|
|
1113
|
+
...defineVcsHostDetails(vcs, pathWithinParent),
|
|
1114
|
+
scripts: liftScripts({
|
|
1115
|
+
existingScripts: existingPackageJsonContents.scripts,
|
|
1116
|
+
scripts
|
|
1117
|
+
}),
|
|
1118
|
+
...tags && {
|
|
1119
|
+
keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags
|
|
1120
|
+
}
|
|
1121
|
+
})
|
|
1122
|
+
});
|
|
1091
1123
|
|
|
1092
|
-
|
|
1093
|
-
await install$1(dependencies || [], javascriptCore.PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
1094
|
-
await install$1([...devDependencies || []], javascriptCore.DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
1095
|
-
} catch (e) {
|
|
1096
|
-
cliMessages.error('Failed to install dependencies');
|
|
1097
|
-
cliMessages.error(e, {level: 'secondary'});
|
|
1098
|
-
}
|
|
1124
|
+
await processDependencies({dependencies, devDependencies, projectRoot, packageManager});
|
|
1099
1125
|
}
|
|
1100
1126
|
|
|
1101
1127
|
function determineLockfilePathFor (packageManager) {
|
|
1102
1128
|
const lockfilePaths = {
|
|
1103
|
-
[
|
|
1104
|
-
[
|
|
1129
|
+
[packageManagers$1.NPM]: 'package-lock.json',
|
|
1130
|
+
[packageManagers$1.YARN]: 'yarn.lock'
|
|
1105
1131
|
};
|
|
1106
1132
|
|
|
1107
1133
|
return lockfilePaths[packageManager];
|
|
1108
1134
|
}
|
|
1109
1135
|
|
|
1110
1136
|
function npmIsUsed ({projectRoot}) {
|
|
1111
|
-
return
|
|
1137
|
+
return fileExists(`${projectRoot}/${determineLockfilePathFor(packageManagers$1.NPM)}`);
|
|
1112
1138
|
}
|
|
1113
1139
|
|
|
1114
1140
|
function yarnIsUsed ({projectRoot}) {
|
|
1115
|
-
return
|
|
1141
|
+
return fileExists(`${projectRoot}/${determineLockfilePathFor(packageManagers$1.YARN)}`);
|
|
1116
1142
|
}
|
|
1117
1143
|
|
|
1118
1144
|
async function jsPackageManagerIsUsed ({projectRoot}) {
|
|
@@ -1125,7 +1151,7 @@ async function jsPackageManagerIsUsed ({projectRoot}) {
|
|
|
1125
1151
|
}
|
|
1126
1152
|
|
|
1127
1153
|
async function liftCorepack () {
|
|
1128
|
-
await
|
|
1154
|
+
await execa('corepack', ['use', 'npm@latest']);
|
|
1129
1155
|
}
|
|
1130
1156
|
|
|
1131
1157
|
async function lifter () {
|
|
@@ -1138,11 +1164,11 @@ async function resolvePackageManager ({projectRoot, packageManager}) {
|
|
|
1138
1164
|
if (packageManager) return packageManager;
|
|
1139
1165
|
|
|
1140
1166
|
if (await npmIsUsed({projectRoot})) {
|
|
1141
|
-
return
|
|
1167
|
+
return packageManagers$1.NPM;
|
|
1142
1168
|
}
|
|
1143
1169
|
|
|
1144
1170
|
if (await yarnIsUsed({projectRoot})) {
|
|
1145
|
-
return
|
|
1171
|
+
return packageManagers$1.YARN;
|
|
1146
1172
|
}
|
|
1147
1173
|
|
|
1148
1174
|
throw new Error('Package-manager could not be determined');
|
|
@@ -1150,14 +1176,14 @@ async function resolvePackageManager ({projectRoot, packageManager}) {
|
|
|
1150
1176
|
|
|
1151
1177
|
var packageManagers = /*#__PURE__*/Object.freeze({
|
|
1152
1178
|
__proto__: null,
|
|
1153
|
-
|
|
1154
|
-
lift: lifter,
|
|
1179
|
+
defineLockfilePath: determineLockfilePathFor,
|
|
1155
1180
|
determineCurrent: resolvePackageManager,
|
|
1156
|
-
|
|
1181
|
+
lift: lifter,
|
|
1182
|
+
test: jsPackageManagerIsUsed
|
|
1157
1183
|
});
|
|
1158
1184
|
|
|
1159
|
-
async function lift ({projectRoot, vcs, results, pathWithinParent}) {
|
|
1160
|
-
|
|
1185
|
+
async function lift ({projectRoot, vcs, results, pathWithinParent, enhancers = {}, configs = {}}) {
|
|
1186
|
+
info('Lifting JavaScript-specific details');
|
|
1161
1187
|
|
|
1162
1188
|
const {
|
|
1163
1189
|
scripts,
|
|
@@ -1169,27 +1195,29 @@ async function lift ({projectRoot, vcs, results, pathWithinParent}) {
|
|
|
1169
1195
|
|
|
1170
1196
|
const [packageManager, packageContents] = await Promise.all([
|
|
1171
1197
|
resolvePackageManager({projectRoot, packageManager: manager}),
|
|
1172
|
-
|
|
1198
|
+
promises$1.readFile(`${projectRoot}/package.json`, 'utf8')
|
|
1173
1199
|
]);
|
|
1174
1200
|
|
|
1175
|
-
const enhancerResults = await
|
|
1201
|
+
const enhancerResults = await applyEnhancers({
|
|
1176
1202
|
results,
|
|
1177
|
-
enhancers:
|
|
1178
|
-
|
|
1203
|
+
enhancers: {
|
|
1204
|
+
...enhancers,
|
|
1205
|
+
huskyPlugin,
|
|
1179
1206
|
enginesEnhancer,
|
|
1180
1207
|
coveragePlugin,
|
|
1181
|
-
|
|
1208
|
+
commitConventionPlugin,
|
|
1182
1209
|
dialects,
|
|
1183
1210
|
codeStylePlugin,
|
|
1184
1211
|
npmConfigPlugin,
|
|
1185
1212
|
projectTypes,
|
|
1186
|
-
packageManagers
|
|
1187
|
-
|
|
1188
|
-
|
|
1213
|
+
packageManagers,
|
|
1214
|
+
registriesPlugin
|
|
1215
|
+
},
|
|
1216
|
+
options: {packageManager, projectRoot, vcs, packageDetails: JSON.parse(packageContents), configs}
|
|
1189
1217
|
});
|
|
1190
1218
|
|
|
1191
1219
|
await liftPackage(
|
|
1192
|
-
|
|
1220
|
+
deepmerge.all([
|
|
1193
1221
|
{projectRoot, scripts, tags, dependencies, devDependencies, packageManager, vcs, pathWithinParent},
|
|
1194
1222
|
enhancerResults
|
|
1195
1223
|
])
|
|
@@ -1198,109 +1226,77 @@ async function lift ({projectRoot, vcs, results, pathWithinParent}) {
|
|
|
1198
1226
|
return enhancerResults;
|
|
1199
1227
|
}
|
|
1200
1228
|
|
|
1201
|
-
const
|
|
1202
|
-
const pluginMapSchema = joi__default["default"].object().pattern(joi__default["default"].string(), pluginSchema);
|
|
1229
|
+
const scopeBasedConfigSchema = joi.object({scope: joi.string().regex(/^@[a-z0-9-]+$/i, 'scope').required()});
|
|
1203
1230
|
|
|
1204
|
-
const
|
|
1231
|
+
const nameBasedConfigSchema = joi.object({
|
|
1232
|
+
packageName: joi.string().required(),
|
|
1233
|
+
name: joi.string().required()
|
|
1234
|
+
});
|
|
1205
1235
|
|
|
1206
|
-
const
|
|
1236
|
+
const registriesSchema = joi.object().pattern(joi.string(), joi.string().uri()).default({});
|
|
1207
1237
|
|
|
1208
|
-
const
|
|
1238
|
+
const visibilitySchema = joi.string().valid('Public', 'Private').required();
|
|
1209
1239
|
|
|
1210
|
-
const
|
|
1240
|
+
const projectNameSchema = joi.string().regex(/^@\w*\//, {invert: true}).required();
|
|
1241
|
+
|
|
1242
|
+
const vcsSchema = joi.object({
|
|
1243
|
+
host: joi.string().required(),
|
|
1244
|
+
owner: joi.string().required(),
|
|
1245
|
+
name: joi.string().required()
|
|
1246
|
+
});
|
|
1211
1247
|
|
|
1212
1248
|
function validate(options) {
|
|
1213
|
-
const schema =
|
|
1214
|
-
.
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
.
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
}),
|
|
1242
|
-
remark: joi__default["default"].string()
|
|
1243
|
-
}).default({})
|
|
1244
|
-
})
|
|
1245
|
-
.keys({
|
|
1246
|
-
overrides: joi__default["default"].object({
|
|
1247
|
-
npmAccount: joi__default["default"].string(),
|
|
1248
|
-
author: joi__default["default"].object({
|
|
1249
|
-
name: joi__default["default"].string().required(),
|
|
1250
|
-
email: joi__default["default"].string().email(),
|
|
1251
|
-
url: joi__default["default"].string().uri()
|
|
1252
|
-
})
|
|
1253
|
-
}).default({})
|
|
1254
|
-
})
|
|
1255
|
-
.keys({
|
|
1256
|
-
ciServices: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
|
|
1257
|
-
scaffolder: joi__default["default"].func().arity(1).required(),
|
|
1258
|
-
public: joi__default["default"].boolean(),
|
|
1259
|
-
private: joi__default["default"].boolean()
|
|
1260
|
-
})).default({})
|
|
1261
|
-
})
|
|
1262
|
-
.keys({
|
|
1263
|
-
hosts: joi__default["default"].object().pattern(/^/, joi__default["default"].object({
|
|
1264
|
-
scaffolder: joi__default["default"].func().arity(1).required(),
|
|
1265
|
-
projectTypes: joi__default["default"].array().items(joi__default["default"].string().valid('static', 'node')).default([])
|
|
1266
|
-
})).default({})
|
|
1267
|
-
})
|
|
1268
|
-
.keys({
|
|
1269
|
-
applicationTypes: applicationTypesSchema,
|
|
1270
|
-
packageTypes: packageTypesSchema,
|
|
1271
|
-
monorepoTypes: monorepoTypesSchema
|
|
1272
|
-
})
|
|
1273
|
-
.keys({
|
|
1274
|
-
unitTestFrameworks: unitTestFrameworksSchema,
|
|
1275
|
-
packageBundlers: packageBundlersSchema
|
|
1276
|
-
})
|
|
1277
|
-
.keys({
|
|
1278
|
-
decisions: joi__default["default"].object()
|
|
1279
|
-
})
|
|
1280
|
-
.keys({registries: joi__default["default"].object().pattern(joi__default["default"].string(), joi__default["default"].string().uri()).default({})});
|
|
1249
|
+
const schema = joi.object({
|
|
1250
|
+
projectRoot: joi.string().required(),
|
|
1251
|
+
projectName: projectNameSchema,
|
|
1252
|
+
visibility: visibilitySchema,
|
|
1253
|
+
license: joi.string().required(),
|
|
1254
|
+
description: joi.string(),
|
|
1255
|
+
pathWithinParent: joi.string(),
|
|
1256
|
+
decisions: joi.object(),
|
|
1257
|
+
vcs: vcsSchema,
|
|
1258
|
+
configs: joi.object({
|
|
1259
|
+
eslint: scopeBasedConfigSchema,
|
|
1260
|
+
typescript: scopeBasedConfigSchema,
|
|
1261
|
+
prettier: scopeBasedConfigSchema,
|
|
1262
|
+
commitlint: nameBasedConfigSchema,
|
|
1263
|
+
babelPreset: nameBasedConfigSchema,
|
|
1264
|
+
remark: joi.string(),
|
|
1265
|
+
registries: registriesSchema
|
|
1266
|
+
}).default({}),
|
|
1267
|
+
plugins: {
|
|
1268
|
+
unitTestFrameworks: pluginsSchema,
|
|
1269
|
+
packageBundlers: pluginsSchema,
|
|
1270
|
+
applicationTypes: pluginsSchema,
|
|
1271
|
+
packageTypes: pluginsSchema,
|
|
1272
|
+
monorepoTypes: pluginsSchema,
|
|
1273
|
+
hosts: pluginsSchema,
|
|
1274
|
+
ciServices: pluginsSchema
|
|
1275
|
+
}
|
|
1276
|
+
}).required();
|
|
1281
1277
|
|
|
1282
|
-
return
|
|
1278
|
+
return validateOptions(schema, options);
|
|
1283
1279
|
}
|
|
1284
1280
|
|
|
1285
1281
|
function buildDialectChoices ({babelPreset, typescript}) {
|
|
1286
1282
|
return [
|
|
1287
|
-
{name: 'Common JS (no transpilation)', value:
|
|
1288
|
-
...babelPreset ? [{name: 'Modern JavaScript (transpiled)', value:
|
|
1289
|
-
{name: 'ESM-only (no transpilation)', value:
|
|
1290
|
-
...typescript ? [{name: 'TypeScript', value:
|
|
1283
|
+
{name: 'Common JS (no transpilation)', value: dialects$1.COMMON_JS, short: 'cjs'},
|
|
1284
|
+
...babelPreset ? [{name: 'Modern JavaScript (transpiled)', value: dialects$1.BABEL, short: 'modern'}] : [],
|
|
1285
|
+
{name: 'ESM-only (no transpilation)', value: dialects$1.ESM, short: 'esm'},
|
|
1286
|
+
...typescript ? [{name: 'TypeScript', value: dialects$1.TYPESCRIPT, short: 'ts'}] : []
|
|
1291
1287
|
];
|
|
1292
1288
|
}
|
|
1293
1289
|
|
|
1294
1290
|
function projectIsCLI(answers) {
|
|
1295
|
-
return
|
|
1291
|
+
return projectTypes$1.CLI === answers[questionNames$1.PROJECT_TYPE];
|
|
1296
1292
|
}
|
|
1297
1293
|
|
|
1298
1294
|
function projectIsPackage(answers) {
|
|
1299
|
-
return
|
|
1295
|
+
return projectTypes$1.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
|
|
1300
1296
|
}
|
|
1301
1297
|
|
|
1302
1298
|
function projectIsApplication(answers) {
|
|
1303
|
-
return
|
|
1299
|
+
return projectTypes$1.APPLICATION === answers[questionNames$1.PROJECT_TYPE];
|
|
1304
1300
|
}
|
|
1305
1301
|
|
|
1306
1302
|
function packageShouldBeScoped(visibility, answers) {
|
|
@@ -1320,8 +1316,8 @@ function scopePromptShouldBePresentedFactory(visibility) {
|
|
|
1320
1316
|
}
|
|
1321
1317
|
|
|
1322
1318
|
function lintingPromptShouldBePresented({
|
|
1323
|
-
[
|
|
1324
|
-
[
|
|
1319
|
+
[questionNames$2.UNIT_TESTS]: unitTested,
|
|
1320
|
+
[questionNames$2.INTEGRATION_TESTS]: integrationTested
|
|
1325
1321
|
}) {
|
|
1326
1322
|
return !unitTested && !integrationTested;
|
|
1327
1323
|
}
|
|
@@ -1357,7 +1353,6 @@ function authorQuestions({name, email, url}) {
|
|
|
1357
1353
|
}
|
|
1358
1354
|
|
|
1359
1355
|
async function prompt(
|
|
1360
|
-
{npmAccount, author},
|
|
1361
1356
|
ciServices,
|
|
1362
1357
|
hosts,
|
|
1363
1358
|
visibility,
|
|
@@ -1366,23 +1361,23 @@ async function prompt(
|
|
|
1366
1361
|
configs,
|
|
1367
1362
|
pathWithinParent
|
|
1368
1363
|
) {
|
|
1369
|
-
const npmConf =
|
|
1364
|
+
const npmConf$1 = npmConf();
|
|
1370
1365
|
|
|
1371
1366
|
let maybeLoggedInNpmUsername;
|
|
1372
1367
|
try {
|
|
1373
|
-
maybeLoggedInNpmUsername = (await
|
|
1368
|
+
maybeLoggedInNpmUsername = (await execa('npm', ['whoami'])).stdout;
|
|
1374
1369
|
} catch (failedExecutionResult) {
|
|
1375
1370
|
if (!decisions[questionNames$1.SCOPE]) {
|
|
1376
|
-
|
|
1371
|
+
warn('No logged in user found with `npm whoami`. Login with `npm login` '
|
|
1377
1372
|
+ 'to use your npm account name as the package scope default.');
|
|
1378
1373
|
}
|
|
1379
1374
|
}
|
|
1380
1375
|
|
|
1381
1376
|
const {
|
|
1382
|
-
[
|
|
1383
|
-
[
|
|
1377
|
+
[questionNames$2.UNIT_TESTS]: unitTested,
|
|
1378
|
+
[questionNames$2.INTEGRATION_TESTS]: integrationTested,
|
|
1384
1379
|
[questionNames$1.PROJECT_TYPE]: projectType,
|
|
1385
|
-
[
|
|
1380
|
+
[questionNames$2.CI_SERVICE]: ci,
|
|
1386
1381
|
[questionNames$1.HOST]: chosenHost,
|
|
1387
1382
|
[questionNames$1.SCOPE]: scope$1,
|
|
1388
1383
|
[questionNames$1.NODE_VERSION_CATEGORY]: nodeVersionCategory,
|
|
@@ -1393,7 +1388,7 @@ async function prompt(
|
|
|
1393
1388
|
[questionNames$1.PROVIDE_EXAMPLE]: provideExample,
|
|
1394
1389
|
[questionNames$1.PACKAGE_MANAGER]: packageManager,
|
|
1395
1390
|
[questionNames$1.DIALECT]: dialect
|
|
1396
|
-
} = await
|
|
1391
|
+
} = await prompt$1([
|
|
1397
1392
|
{
|
|
1398
1393
|
name: questionNames$1.DIALECT,
|
|
1399
1394
|
message: 'Which JavaScript dialect should this project follow?',
|
|
@@ -1412,15 +1407,15 @@ async function prompt(
|
|
|
1412
1407
|
name: questionNames$1.PACKAGE_MANAGER,
|
|
1413
1408
|
message: 'Which package manager will be used with this project?',
|
|
1414
1409
|
type: 'list',
|
|
1415
|
-
choices: Object.values(
|
|
1416
|
-
default:
|
|
1410
|
+
choices: Object.values(packageManagers$1),
|
|
1411
|
+
default: packageManagers$1.NPM
|
|
1417
1412
|
},
|
|
1418
1413
|
{
|
|
1419
1414
|
name: questionNames$1.PROJECT_TYPE,
|
|
1420
1415
|
message: 'What type of JavaScript project is this?',
|
|
1421
1416
|
type: 'list',
|
|
1422
|
-
choices: [...Object.values(
|
|
1423
|
-
default:
|
|
1417
|
+
choices: [...Object.values(projectTypes$1), 'Other'],
|
|
1418
|
+
default: projectTypes$1.PACKAGE
|
|
1424
1419
|
},
|
|
1425
1420
|
...'Private' === visibility ? [] : [{
|
|
1426
1421
|
name: questionNames$1.SHOULD_BE_SCOPED,
|
|
@@ -1434,14 +1429,14 @@ async function prompt(
|
|
|
1434
1429
|
message: 'What is the scope?',
|
|
1435
1430
|
when: scopePromptShouldBePresentedFactory(visibility),
|
|
1436
1431
|
validate: scope(visibility),
|
|
1437
|
-
default:
|
|
1432
|
+
default: maybeLoggedInNpmUsername
|
|
1438
1433
|
},
|
|
1439
|
-
...authorQuestions(
|
|
1440
|
-
name: npmConf.get('init.author.name'),
|
|
1441
|
-
email: npmConf.get('init.author.email'),
|
|
1442
|
-
url: npmConf.get('init.author.url')
|
|
1434
|
+
...authorQuestions({
|
|
1435
|
+
name: npmConf$1.get('init.author.name'),
|
|
1436
|
+
email: npmConf$1.get('init.author.email'),
|
|
1437
|
+
url: npmConf$1.get('init.author.url')
|
|
1443
1438
|
}),
|
|
1444
|
-
...
|
|
1439
|
+
...questions(({vcs, ciServices, pathWithinParent})),
|
|
1445
1440
|
{
|
|
1446
1441
|
name: questionNames$1.CONFIGURE_LINTING,
|
|
1447
1442
|
message: 'Will there be source code that should be linted?',
|
|
@@ -1459,7 +1454,7 @@ async function prompt(
|
|
|
1459
1454
|
type: 'list',
|
|
1460
1455
|
message: 'Where will the application be hosted?',
|
|
1461
1456
|
when: projectIsApplication,
|
|
1462
|
-
choices: [...Object.keys(hosts),
|
|
1457
|
+
choices: [...Object.keys(hosts), 'Other']
|
|
1463
1458
|
}
|
|
1464
1459
|
], decisions);
|
|
1465
1460
|
|
|
@@ -1497,10 +1492,14 @@ $ ${packageManager} test
|
|
|
1497
1492
|
};
|
|
1498
1493
|
}
|
|
1499
1494
|
|
|
1495
|
+
function buildBadgesDetails (contributors) {
|
|
1496
|
+
return deepmerge.all(contributors).badges;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1500
1499
|
async function determineLatestVersionOf(nodeVersionCategory) {
|
|
1501
|
-
|
|
1500
|
+
info('Determining version of node', {level: 'secondary'});
|
|
1502
1501
|
|
|
1503
|
-
const {stdout: nvmLsOutput} = await
|
|
1502
|
+
const {stdout: nvmLsOutput} = await execa(
|
|
1504
1503
|
`. ~/.nvm/nvm.sh && nvm ls-remote${('LTS' === nodeVersionCategory) ? ' --lts' : ''}`,
|
|
1505
1504
|
{shell: true}
|
|
1506
1505
|
);
|
|
@@ -1512,9 +1511,9 @@ async function determineLatestVersionOf(nodeVersionCategory) {
|
|
|
1512
1511
|
}
|
|
1513
1512
|
|
|
1514
1513
|
function install(nodeVersionCategory) {
|
|
1515
|
-
|
|
1514
|
+
info(`Installing ${nodeVersionCategory} version of node using nvm`, {level: 'secondary'});
|
|
1516
1515
|
|
|
1517
|
-
const subprocess =
|
|
1516
|
+
const subprocess = execa('. ~/.nvm/nvm.sh && nvm install', {shell: true});
|
|
1518
1517
|
subprocess.stdout.pipe(process.stdout);
|
|
1519
1518
|
return subprocess;
|
|
1520
1519
|
}
|
|
@@ -1523,11 +1522,11 @@ async function scaffoldNodeVersion ({projectRoot, nodeVersionCategory}) {
|
|
|
1523
1522
|
if (!nodeVersionCategory) return undefined;
|
|
1524
1523
|
|
|
1525
1524
|
const lowerCaseCategory = nodeVersionCategory.toLowerCase();
|
|
1526
|
-
|
|
1525
|
+
info(`Configuring ${lowerCaseCategory} version of node`);
|
|
1527
1526
|
|
|
1528
1527
|
const version = await determineLatestVersionOf(nodeVersionCategory);
|
|
1529
1528
|
|
|
1530
|
-
await
|
|
1529
|
+
await promises$1.writeFile(`${projectRoot}/.nvmrc`, version);
|
|
1531
1530
|
|
|
1532
1531
|
await install(nodeVersionCategory);
|
|
1533
1532
|
|
|
@@ -1535,11 +1534,7 @@ async function scaffoldNodeVersion ({projectRoot, nodeVersionCategory}) {
|
|
|
1535
1534
|
}
|
|
1536
1535
|
|
|
1537
1536
|
function nvmIsUsed ({projectRoot}) {
|
|
1538
|
-
return
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
function buildBadgesDetails (contributors) {
|
|
1542
|
-
return deepmerge__default["default"].all(contributors).badges;
|
|
1537
|
+
return fileExists(`${projectRoot}/.nvmrc`);
|
|
1543
1538
|
}
|
|
1544
1539
|
|
|
1545
1540
|
function buildVcsIgnoreLists (vcsIgnoreLists = {}) {
|
|
@@ -1549,25 +1544,14 @@ function buildVcsIgnoreLists (vcsIgnoreLists = {}) {
|
|
|
1549
1544
|
};
|
|
1550
1545
|
}
|
|
1551
1546
|
|
|
1552
|
-
function buildPackageName (projectName, scope) {
|
|
1553
|
-
const name = `${scope ? `@${scope}/` : ''}${projectName}`;
|
|
1554
|
-
|
|
1555
|
-
const {validForNewPackages, errors} = validatePackageName__default["default"](name);
|
|
1556
|
-
|
|
1557
|
-
if (validForNewPackages) return name;
|
|
1558
|
-
if (1 === errors.length && errors.includes('name cannot start with a period')) return projectName.slice(1);
|
|
1559
|
-
|
|
1560
|
-
throw new Error(`The package name ${name} is invalid:${os.EOL}\t* ${errors.join(`${os.EOL}\t* `)}`);
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
1547
|
async function chooseProjectTypePlugin ({types, projectType, decisions}) {
|
|
1564
1548
|
if (!Object.keys(types).length) return 'Other';
|
|
1565
1549
|
|
|
1566
|
-
const answers = await
|
|
1550
|
+
const answers = await prompt$1([{
|
|
1567
1551
|
name: questionNames$1.PROJECT_TYPE_CHOICE,
|
|
1568
1552
|
type: 'list',
|
|
1569
1553
|
message: `What type of ${projectType} is this?`,
|
|
1570
|
-
choices: [...Object.keys(types),
|
|
1554
|
+
choices: [...Object.keys(types), 'Other']
|
|
1571
1555
|
}], decisions);
|
|
1572
1556
|
|
|
1573
1557
|
return answers[questionNames$1.PROJECT_TYPE_CHOICE];
|
|
@@ -1591,7 +1575,7 @@ async function scaffoldProjectTypePlugin ({
|
|
|
1591
1575
|
|
|
1592
1576
|
const chosenType = await chooseProjectTypePlugin({types: pluginsForProjectType, decisions, projectType});
|
|
1593
1577
|
|
|
1594
|
-
return
|
|
1578
|
+
return scaffoldChoice(
|
|
1595
1579
|
pluginsForProjectType,
|
|
1596
1580
|
chosenType,
|
|
1597
1581
|
{projectRoot, projectName, packageName, packageManager, scope, tests, dialect}
|
|
@@ -1620,7 +1604,7 @@ async function scaffoldTesting ({
|
|
|
1620
1604
|
})
|
|
1621
1605
|
: {};
|
|
1622
1606
|
|
|
1623
|
-
return
|
|
1607
|
+
return deepmerge({devDependencies: [...(unit || integration) ? ['@travi/any'] : []], eslint: {}}, unitResults);
|
|
1624
1608
|
}
|
|
1625
1609
|
|
|
1626
1610
|
function buildAllowedHostsList ({packageManager, registries}) {
|
|
@@ -1630,7 +1614,7 @@ function buildAllowedHostsList ({packageManager, registries}) {
|
|
|
1630
1614
|
];
|
|
1631
1615
|
}
|
|
1632
1616
|
|
|
1633
|
-
const lockfileLintSupportedPackageManagers = [
|
|
1617
|
+
const lockfileLintSupportedPackageManagers = [packageManagers$1.NPM, packageManagers$1.YARN];
|
|
1634
1618
|
|
|
1635
1619
|
function lockfileLintSupports(packageManager) {
|
|
1636
1620
|
return lockfileLintSupportedPackageManagers.includes(packageManager);
|
|
@@ -1644,9 +1628,9 @@ async function scaffoldLockfileLint ({projectRoot, packageManager, registries})
|
|
|
1644
1628
|
);
|
|
1645
1629
|
}
|
|
1646
1630
|
|
|
1647
|
-
await
|
|
1631
|
+
await write$1({
|
|
1648
1632
|
name: 'lockfile-lint',
|
|
1649
|
-
format:
|
|
1633
|
+
format: fileTypes.JSON,
|
|
1650
1634
|
path: projectRoot,
|
|
1651
1635
|
config: {
|
|
1652
1636
|
path: determineLockfilePathFor(packageManager),
|
|
@@ -1690,14 +1674,14 @@ async function scaffoldVerification({
|
|
|
1690
1674
|
pathWithinParent
|
|
1691
1675
|
}),
|
|
1692
1676
|
scaffoldLinting({projectRoot, packageManager, registries, vcs, pathWithinParent}),
|
|
1693
|
-
|
|
1677
|
+
scaffold$3({projectRoot, packageManager, pathWithinParent})
|
|
1694
1678
|
]);
|
|
1695
1679
|
|
|
1696
|
-
return
|
|
1680
|
+
return deepmerge.all([testingResults, lintingResults, huskyResults]);
|
|
1697
1681
|
}
|
|
1698
1682
|
|
|
1699
1683
|
async function scaffolder (options) {
|
|
1700
|
-
|
|
1684
|
+
info('Initializing JavaScript project');
|
|
1701
1685
|
|
|
1702
1686
|
const {
|
|
1703
1687
|
projectRoot,
|
|
@@ -1707,17 +1691,17 @@ async function scaffolder (options) {
|
|
|
1707
1691
|
vcs,
|
|
1708
1692
|
description,
|
|
1709
1693
|
configs,
|
|
1710
|
-
overrides,
|
|
1711
|
-
ciServices,
|
|
1712
|
-
hosts,
|
|
1713
|
-
applicationTypes,
|
|
1714
|
-
packageTypes,
|
|
1715
|
-
packageBundlers,
|
|
1716
|
-
monorepoTypes,
|
|
1717
1694
|
decisions,
|
|
1718
|
-
unitTestFrameworks,
|
|
1719
1695
|
pathWithinParent,
|
|
1720
|
-
|
|
1696
|
+
plugins: {
|
|
1697
|
+
applicationTypes,
|
|
1698
|
+
packageTypes,
|
|
1699
|
+
monorepoTypes,
|
|
1700
|
+
packageBundlers,
|
|
1701
|
+
unitTestFrameworks,
|
|
1702
|
+
hosts,
|
|
1703
|
+
ciServices
|
|
1704
|
+
}
|
|
1721
1705
|
} = validate(options);
|
|
1722
1706
|
|
|
1723
1707
|
const {
|
|
@@ -1732,15 +1716,15 @@ async function scaffolder (options) {
|
|
|
1732
1716
|
provideExample,
|
|
1733
1717
|
packageManager,
|
|
1734
1718
|
dialect
|
|
1735
|
-
} = await prompt(
|
|
1719
|
+
} = await prompt(ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
|
|
1736
1720
|
|
|
1737
|
-
|
|
1721
|
+
info('Writing project files', {level: 'secondary'});
|
|
1738
1722
|
|
|
1739
|
-
const packageName =
|
|
1740
|
-
await scaffoldPackage({
|
|
1723
|
+
const {packageName} = await scaffoldPackage({
|
|
1741
1724
|
projectRoot,
|
|
1725
|
+
projectName,
|
|
1726
|
+
scope,
|
|
1742
1727
|
dialect,
|
|
1743
|
-
packageName,
|
|
1744
1728
|
license,
|
|
1745
1729
|
author,
|
|
1746
1730
|
description
|
|
@@ -1754,15 +1738,15 @@ async function scaffolder (options) {
|
|
|
1754
1738
|
visibility,
|
|
1755
1739
|
applicationTypes,
|
|
1756
1740
|
packageTypes,
|
|
1757
|
-
packageBundlers,
|
|
1758
1741
|
monorepoTypes,
|
|
1742
|
+
packageBundlers,
|
|
1759
1743
|
scope,
|
|
1760
1744
|
tests,
|
|
1761
1745
|
vcs,
|
|
1762
1746
|
decisions,
|
|
1763
1747
|
dialect,
|
|
1764
1748
|
provideExample,
|
|
1765
|
-
publishRegistry: registries.publish
|
|
1749
|
+
publishRegistry: configs.registries.publish
|
|
1766
1750
|
});
|
|
1767
1751
|
const verificationResults = await scaffoldVerification({
|
|
1768
1752
|
projectRoot,
|
|
@@ -1770,7 +1754,7 @@ async function scaffolder (options) {
|
|
|
1770
1754
|
visibility,
|
|
1771
1755
|
packageManager,
|
|
1772
1756
|
vcs,
|
|
1773
|
-
registries,
|
|
1757
|
+
registries: configs.registries,
|
|
1774
1758
|
tests,
|
|
1775
1759
|
unitTestFrameworks,
|
|
1776
1760
|
decisions,
|
|
@@ -1778,7 +1762,7 @@ async function scaffolder (options) {
|
|
|
1778
1762
|
});
|
|
1779
1763
|
const [nodeVersion, npmResults, dialectResults, codeStyleResults] = await Promise.all([
|
|
1780
1764
|
scaffoldNodeVersion({projectRoot, nodeVersionCategory}),
|
|
1781
|
-
scaffoldNpmConfig({projectType, projectRoot, registries}),
|
|
1765
|
+
scaffoldNpmConfig({projectType, projectRoot, registries: configs.registries}),
|
|
1782
1766
|
scaffoldDialect({
|
|
1783
1767
|
dialect,
|
|
1784
1768
|
configs,
|
|
@@ -1799,20 +1783,20 @@ async function scaffolder (options) {
|
|
|
1799
1783
|
tests,
|
|
1800
1784
|
decisions,
|
|
1801
1785
|
plugins: {
|
|
1802
|
-
[
|
|
1803
|
-
[
|
|
1804
|
-
[
|
|
1786
|
+
[projectTypes$1.PACKAGE]: packageTypes,
|
|
1787
|
+
[projectTypes$1.APPLICATION]: applicationTypes,
|
|
1788
|
+
[projectTypes$1.MONOREPO]: monorepoTypes
|
|
1805
1789
|
}
|
|
1806
1790
|
});
|
|
1807
|
-
const mergedContributions =
|
|
1791
|
+
const mergedContributions = deepmerge.all([
|
|
1808
1792
|
...(await Promise.all([
|
|
1809
|
-
|
|
1793
|
+
scaffoldChoice(
|
|
1810
1794
|
hosts,
|
|
1811
1795
|
chosenHost,
|
|
1812
1796
|
{buildDirectory: `./${projectTypeResults.buildDirectory}`, projectRoot, projectName, nodeVersion}
|
|
1813
1797
|
),
|
|
1814
|
-
|
|
1815
|
-
|
|
1798
|
+
scaffoldChoice(ciServices, ci, {projectRoot, vcs, visibility, projectType, projectName, nodeVersion, tests}),
|
|
1799
|
+
scaffold$4({projectRoot, projectType, configs, pathWithinParent})
|
|
1816
1800
|
])),
|
|
1817
1801
|
projectTypeResults,
|
|
1818
1802
|
verificationResults,
|
|
@@ -1823,7 +1807,7 @@ async function scaffolder (options) {
|
|
|
1823
1807
|
]);
|
|
1824
1808
|
|
|
1825
1809
|
const liftResults = await lift({
|
|
1826
|
-
results:
|
|
1810
|
+
results: deepmerge({devDependencies: ['npm-run-all2'], packageManager}, mergedContributions),
|
|
1827
1811
|
projectRoot,
|
|
1828
1812
|
configs,
|
|
1829
1813
|
vcs,
|
|
@@ -1849,16 +1833,12 @@ async function tester ({projectRoot}) {
|
|
|
1849
1833
|
|
|
1850
1834
|
const jsProjectFound = nvmFound || jsPackageManagerFound;
|
|
1851
1835
|
|
|
1852
|
-
if (jsProjectFound)
|
|
1836
|
+
if (jsProjectFound) info('JavaScript Project Detected');
|
|
1853
1837
|
|
|
1854
1838
|
return jsProjectFound;
|
|
1855
1839
|
}
|
|
1856
1840
|
|
|
1857
|
-
const questionNames = {...
|
|
1841
|
+
const questionNames = {...questionNames$2, ...questionNames$1};
|
|
1858
1842
|
|
|
1859
|
-
|
|
1860
|
-
exports.questionNames = questionNames;
|
|
1861
|
-
exports.scaffold = scaffolder;
|
|
1862
|
-
exports.scaffoldUnitTesting = scaffoldUnitTesting;
|
|
1863
|
-
exports.test = tester;
|
|
1843
|
+
export { lift, questionNames, scaffolder as scaffold, scaffoldUnitTesting, tester as test };
|
|
1864
1844
|
//# sourceMappingURL=index.js.map
|