@form8ion/javascript 2.2.0 → 3.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/example.js +25 -3
- package/lib/index.cjs.js +199 -4
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.es.js +201 -8
- package/lib/index.es.js.map +1 -1
- package/package.json +6 -7
package/lib/index.es.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { questionNames as questionNames$2, questions } from '@travi/language-scaffolder-prompts';
|
|
2
2
|
import deepmerge from 'deepmerge';
|
|
3
|
-
import { validateOptions, scaffoldChoice,
|
|
4
|
-
import { scaffold } from '@form8ion/codecov';
|
|
5
|
-
import { promises } from 'fs';
|
|
3
|
+
import { validateOptions, scaffoldChoice, installDependencies, PROD_DEPENDENCY_TYPE, DEV_DEPENDENCY_TYPE, packageManagers, dialects, projectTypes } from '@form8ion/javascript-core';
|
|
6
4
|
import * as joi from 'joi';
|
|
7
5
|
import { Separator } from 'inquirer';
|
|
8
6
|
import { prompt as prompt$1 } from '@form8ion/overridable-prompts';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { scaffold } from '@form8ion/codecov';
|
|
8
|
+
import { promises } from 'fs';
|
|
9
|
+
import { fileExists } from '@form8ion/core';
|
|
10
|
+
import { info, warn } from '@travi/cli-messages';
|
|
11
11
|
import { scaffold as scaffold$4 } from '@form8ion/commit-convention';
|
|
12
12
|
import hoek from '@hapi/hoek';
|
|
13
13
|
import execa from 'execa';
|
|
@@ -20,8 +20,8 @@ import camelcase from 'camelcase';
|
|
|
20
20
|
import makeDir from 'make-dir';
|
|
21
21
|
import touch from 'touch';
|
|
22
22
|
import { resolve } from 'path';
|
|
23
|
-
import { scaffold as scaffold$3 } from '@form8ion/husky';
|
|
24
|
-
import { scaffold as scaffold$2 } from '@form8ion/eslint';
|
|
23
|
+
import { test as test$2, lift as lift$3, scaffold as scaffold$3 } from '@form8ion/husky';
|
|
24
|
+
import { lift as lift$4, scaffold as scaffold$2 } from '@form8ion/eslint';
|
|
25
25
|
|
|
26
26
|
function ownKeys(object, enumerableOnly) {
|
|
27
27
|
var keys = Object.keys(object);
|
|
@@ -116,6 +116,42 @@ async function scaffoldCoverage ({
|
|
|
116
116
|
}));
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
function nycIsConfigured ({
|
|
120
|
+
projectRoot
|
|
121
|
+
}) {
|
|
122
|
+
return fileExists(`${projectRoot}/.nycrc`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function removeNyc ({
|
|
126
|
+
projectRoot
|
|
127
|
+
}) {
|
|
128
|
+
await promises.unlink(`${projectRoot}/.nycrc`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function lift$2({
|
|
132
|
+
projectRoot
|
|
133
|
+
}) {
|
|
134
|
+
if (await nycIsConfigured({
|
|
135
|
+
projectRoot
|
|
136
|
+
})) {
|
|
137
|
+
const [c8Results] = await Promise.all([scaffoldC8({
|
|
138
|
+
projectRoot
|
|
139
|
+
}), removeNyc({
|
|
140
|
+
projectRoot
|
|
141
|
+
})]);
|
|
142
|
+
return c8Results;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
var coveragePlugin = /*#__PURE__*/Object.freeze({
|
|
149
|
+
__proto__: null,
|
|
150
|
+
scaffold: scaffoldCoverage,
|
|
151
|
+
lift: lift$2,
|
|
152
|
+
test: nycIsConfigured
|
|
153
|
+
});
|
|
154
|
+
|
|
119
155
|
const unitTestFrameworksSchema = joi.object().required().pattern(/^/, joi.object({
|
|
120
156
|
scaffolder: joi.func().arity(1).required()
|
|
121
157
|
}));
|
|
@@ -161,6 +197,157 @@ async function scaffoldUnitTesting ({
|
|
|
161
197
|
}, framework, coverage]);
|
|
162
198
|
}
|
|
163
199
|
|
|
200
|
+
async function applyEnhancers ({
|
|
201
|
+
results,
|
|
202
|
+
enhancers = {},
|
|
203
|
+
projectRoot
|
|
204
|
+
}) {
|
|
205
|
+
info('Applying Enhancers');
|
|
206
|
+
return Object.values(enhancers).reduce(async (acc, enhancer) => {
|
|
207
|
+
if (await enhancer.test({
|
|
208
|
+
projectRoot
|
|
209
|
+
})) {
|
|
210
|
+
const previousResults = await acc;
|
|
211
|
+
return deepmerge(previousResults, await enhancer.lift({
|
|
212
|
+
results: previousResults,
|
|
213
|
+
projectRoot
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return acc;
|
|
218
|
+
}, results);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function test$1({
|
|
222
|
+
projectRoot
|
|
223
|
+
}) {
|
|
224
|
+
const {
|
|
225
|
+
engines
|
|
226
|
+
} = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf8'));
|
|
227
|
+
return !!(engines !== null && engines !== void 0 && engines.node);
|
|
228
|
+
}
|
|
229
|
+
async function lift$1({
|
|
230
|
+
projectRoot
|
|
231
|
+
}) {
|
|
232
|
+
const {
|
|
233
|
+
name
|
|
234
|
+
} = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf8'));
|
|
235
|
+
return {
|
|
236
|
+
devDependencies: ['ls-engines'],
|
|
237
|
+
scripts: {
|
|
238
|
+
'lint:engines': 'ls-engines'
|
|
239
|
+
},
|
|
240
|
+
badges: {
|
|
241
|
+
consumer: {
|
|
242
|
+
node: {
|
|
243
|
+
img: `https://img.shields.io/node/v/${name}?logo=node.js`,
|
|
244
|
+
text: 'node'
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
var enginesEnhancer = /*#__PURE__*/Object.freeze({
|
|
252
|
+
__proto__: null,
|
|
253
|
+
test: test$1,
|
|
254
|
+
lift: lift$1
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
function enhanceHuskyEnhancer(packageManager) {
|
|
258
|
+
return {
|
|
259
|
+
test: test$2,
|
|
260
|
+
lift: ({
|
|
261
|
+
projectRoot,
|
|
262
|
+
results
|
|
263
|
+
}) => lift$3({
|
|
264
|
+
projectRoot,
|
|
265
|
+
results,
|
|
266
|
+
packageManager
|
|
267
|
+
})
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function liftPackage ({
|
|
272
|
+
projectRoot,
|
|
273
|
+
scripts,
|
|
274
|
+
tags,
|
|
275
|
+
dependencies,
|
|
276
|
+
devDependencies,
|
|
277
|
+
packageManager
|
|
278
|
+
}) {
|
|
279
|
+
if (scripts || tags) {
|
|
280
|
+
info('Updating `package.json`', {
|
|
281
|
+
level: 'secondary'
|
|
282
|
+
});
|
|
283
|
+
const pathToPackageJson = `${projectRoot}/package.json`;
|
|
284
|
+
const existingPackageJsonContents = JSON.parse(await promises.readFile(pathToPackageJson, 'utf8'));
|
|
285
|
+
await promises.writeFile(pathToPackageJson, JSON.stringify(_objectSpread2(_objectSpread2({}, existingPackageJsonContents), {}, {
|
|
286
|
+
scripts: _objectSpread2(_objectSpread2({}, existingPackageJsonContents.scripts), scripts)
|
|
287
|
+
}, tags && {
|
|
288
|
+
keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags
|
|
289
|
+
}), null, 2));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
info('Installing dependencies');
|
|
293
|
+
await installDependencies(dependencies || [], PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
294
|
+
await installDependencies([...(devDependencies || [])], DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function resolvePackageManager ({
|
|
298
|
+
projectRoot,
|
|
299
|
+
packageManager
|
|
300
|
+
}) {
|
|
301
|
+
if (packageManager) return packageManager;
|
|
302
|
+
|
|
303
|
+
if (await fileExists(`${projectRoot}/package-lock.json`)) {
|
|
304
|
+
return packageManagers.NPM;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (await fileExists(`${projectRoot}/yarn.lock`)) {
|
|
308
|
+
return packageManagers.YARN;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
throw new Error('Package-manager could not be determined');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function lift ({
|
|
315
|
+
projectRoot,
|
|
316
|
+
results
|
|
317
|
+
}) {
|
|
318
|
+
info('Lifting JavaScript-specific details');
|
|
319
|
+
const {
|
|
320
|
+
scripts,
|
|
321
|
+
tags,
|
|
322
|
+
eslintConfigs,
|
|
323
|
+
dependencies,
|
|
324
|
+
devDependencies,
|
|
325
|
+
packageManager: manager
|
|
326
|
+
} = results;
|
|
327
|
+
const packageManager = await resolvePackageManager({
|
|
328
|
+
projectRoot,
|
|
329
|
+
packageManager: manager
|
|
330
|
+
});
|
|
331
|
+
const eslintResults = await lift$4({
|
|
332
|
+
projectRoot,
|
|
333
|
+
configs: eslintConfigs
|
|
334
|
+
});
|
|
335
|
+
const enhancerResults = await applyEnhancers({
|
|
336
|
+
results,
|
|
337
|
+
enhancers: [enhanceHuskyEnhancer(packageManager), enginesEnhancer, coveragePlugin],
|
|
338
|
+
projectRoot
|
|
339
|
+
});
|
|
340
|
+
await liftPackage(deepmerge.all([{
|
|
341
|
+
projectRoot,
|
|
342
|
+
scripts,
|
|
343
|
+
tags,
|
|
344
|
+
dependencies,
|
|
345
|
+
devDependencies,
|
|
346
|
+
packageManager
|
|
347
|
+
}, enhancerResults, eslintResults]));
|
|
348
|
+
return enhancerResults;
|
|
349
|
+
}
|
|
350
|
+
|
|
164
351
|
function validate(options) {
|
|
165
352
|
const schema = joi.object().required().keys({
|
|
166
353
|
projectRoot: joi.string().required(),
|
|
@@ -1467,7 +1654,13 @@ async function scaffolder (options) {
|
|
|
1467
1654
|
};
|
|
1468
1655
|
}
|
|
1469
1656
|
|
|
1657
|
+
async function test ({
|
|
1658
|
+
projectRoot
|
|
1659
|
+
}) {
|
|
1660
|
+
return fileExists(`${projectRoot}/.nvmrc`);
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1470
1663
|
const questionNames = _objectSpread2(_objectSpread2({}, questionNames$2), questionNames$1);
|
|
1471
1664
|
|
|
1472
|
-
export { questionNames, scaffolder as scaffold, scaffoldUnitTesting };
|
|
1665
|
+
export { lift, questionNames, scaffolder as scaffold, scaffoldUnitTesting, test };
|
|
1473
1666
|
//# sourceMappingURL=index.es.js.map
|