@form8ion/javascript 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.es.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import { questionNames as questionNames$2, questions } from '@travi/language-scaffolder-prompts';
2
2
  import deepmerge from 'deepmerge';
3
- import { validateOptions, scaffoldChoice, dialects, projectTypes, packageManagers } from '@form8ion/javascript-core';
3
+ import { validateOptions, scaffoldChoice, installDependencies, PROD_DEPENDENCY_TYPE, DEV_DEPENDENCY_TYPE, packageManagers, dialects, projectTypes } from '@form8ion/javascript-core';
4
4
  import { scaffold } from '@form8ion/codecov';
5
5
  import { promises } from 'fs';
6
6
  import * as joi from 'joi';
7
7
  import { Separator } from 'inquirer';
8
8
  import { prompt as prompt$1 } from '@form8ion/overridable-prompts';
9
- import { warn, info } from '@travi/cli-messages';
10
- import { lift } from '@form8ion/lift-javascript';
9
+ import { info, warn } from '@travi/cli-messages';
10
+ import { lift as lift$3, scaffold as scaffold$2 } from '@form8ion/eslint';
11
+ import { fileExists } from '@form8ion/core';
12
+ import { test as test$2, lift as lift$2, scaffold as scaffold$3 } from '@form8ion/husky';
11
13
  import { scaffold as scaffold$4 } from '@form8ion/commit-convention';
12
14
  import hoek from '@hapi/hoek';
13
15
  import execa from 'execa';
@@ -20,8 +22,6 @@ import camelcase from 'camelcase';
20
22
  import makeDir from 'make-dir';
21
23
  import touch from 'touch';
22
24
  import { resolve } from 'path';
23
- import { scaffold as scaffold$3 } from '@form8ion/husky';
24
- import { scaffold as scaffold$2 } from '@form8ion/eslint';
25
25
 
26
26
  function ownKeys(object, enumerableOnly) {
27
27
  var keys = Object.keys(object);
@@ -161,6 +161,157 @@ async function scaffoldUnitTesting ({
161
161
  }, framework, coverage]);
162
162
  }
163
163
 
164
+ async function applyEnhancers ({
165
+ results,
166
+ enhancers = {},
167
+ projectRoot
168
+ }) {
169
+ info('Applying Enhancers');
170
+ return Object.values(enhancers).reduce(async (acc, enhancer) => {
171
+ if (await enhancer.test({
172
+ projectRoot
173
+ })) {
174
+ const previousResults = await acc;
175
+ return deepmerge(previousResults, await enhancer.lift({
176
+ results: previousResults,
177
+ projectRoot
178
+ }));
179
+ }
180
+
181
+ return acc;
182
+ }, results);
183
+ }
184
+
185
+ async function test$1({
186
+ projectRoot
187
+ }) {
188
+ const {
189
+ engines
190
+ } = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf8'));
191
+ return !!(engines !== null && engines !== void 0 && engines.node);
192
+ }
193
+ async function lift$1({
194
+ projectRoot
195
+ }) {
196
+ const {
197
+ name
198
+ } = JSON.parse(await promises.readFile(`${projectRoot}/package.json`, 'utf8'));
199
+ return {
200
+ devDependencies: ['ls-engines'],
201
+ scripts: {
202
+ 'lint:engines': 'ls-engines'
203
+ },
204
+ badges: {
205
+ consumer: {
206
+ node: {
207
+ img: `https://img.shields.io/node/v/${name}?logo=node.js`,
208
+ text: 'node'
209
+ }
210
+ }
211
+ }
212
+ };
213
+ }
214
+
215
+ var enginesEnhancer = /*#__PURE__*/Object.freeze({
216
+ __proto__: null,
217
+ test: test$1,
218
+ lift: lift$1
219
+ });
220
+
221
+ async function liftPackage ({
222
+ projectRoot,
223
+ scripts,
224
+ tags,
225
+ dependencies,
226
+ devDependencies,
227
+ packageManager
228
+ }) {
229
+ if (scripts || tags) {
230
+ info('Updating `package.json`', {
231
+ level: 'secondary'
232
+ });
233
+ const pathToPackageJson = `${projectRoot}/package.json`;
234
+ const existingPackageJsonContents = JSON.parse(await promises.readFile(pathToPackageJson, 'utf8'));
235
+ await promises.writeFile(pathToPackageJson, JSON.stringify(_objectSpread2(_objectSpread2({}, existingPackageJsonContents), {}, {
236
+ scripts: _objectSpread2(_objectSpread2({}, existingPackageJsonContents.scripts), scripts)
237
+ }, tags && {
238
+ keywords: existingPackageJsonContents.keywords ? [...existingPackageJsonContents.keywords, ...tags] : tags
239
+ }), null, 2));
240
+ }
241
+
242
+ info('Installing dependencies');
243
+ await installDependencies(dependencies || [], PROD_DEPENDENCY_TYPE, projectRoot, packageManager);
244
+ await installDependencies([...(devDependencies || [])], DEV_DEPENDENCY_TYPE, projectRoot, packageManager);
245
+ }
246
+
247
+ async function resolvePackageManager ({
248
+ projectRoot,
249
+ packageManager
250
+ }) {
251
+ if (packageManager) return packageManager;
252
+
253
+ if (await fileExists(`${projectRoot}/package-lock.json`)) {
254
+ return packageManagers.NPM;
255
+ }
256
+
257
+ if (await fileExists(`${projectRoot}/yarn.lock`)) {
258
+ return packageManagers.YARN;
259
+ }
260
+
261
+ throw new Error('Package-manager could not be determined');
262
+ }
263
+
264
+ function enhanceHuskyEnhancer(packageManager) {
265
+ return {
266
+ test: test$2,
267
+ lift: ({
268
+ projectRoot,
269
+ results
270
+ }) => lift$2({
271
+ projectRoot,
272
+ results,
273
+ packageManager
274
+ })
275
+ };
276
+ }
277
+
278
+ async function lift ({
279
+ projectRoot,
280
+ results
281
+ }) {
282
+ info('Lifting JavaScript-specific details');
283
+ const {
284
+ scripts,
285
+ tags,
286
+ eslintConfigs,
287
+ dependencies,
288
+ devDependencies,
289
+ packageManager: manager
290
+ } = results;
291
+ const packageManager = await resolvePackageManager({
292
+ projectRoot,
293
+ packageManager: manager
294
+ });
295
+ const eslintResults = await lift$3({
296
+ projectRoot,
297
+ configs: eslintConfigs
298
+ });
299
+ const enhancerResults = await applyEnhancers({
300
+ results,
301
+ enhancers: [enhanceHuskyEnhancer(packageManager), enginesEnhancer],
302
+ projectRoot
303
+ });
304
+ await liftPackage(deepmerge.all([{
305
+ projectRoot,
306
+ scripts,
307
+ tags,
308
+ dependencies,
309
+ devDependencies,
310
+ packageManager
311
+ }, enhancerResults, eslintResults]));
312
+ return enhancerResults;
313
+ }
314
+
164
315
  function validate(options) {
165
316
  const schema = joi.object().required().keys({
166
317
  projectRoot: joi.string().required(),
@@ -782,7 +933,7 @@ function defineBadges (packageName, visibility) {
782
933
  return {
783
934
  consumer: _objectSpread2({}, 'Public' === visibility && {
784
935
  npm: {
785
- img: `https://img.shields.io/npm/v/${packageName}.svg`,
936
+ img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
786
937
  text: 'npm',
787
938
  link: `https://www.npmjs.com/package/${packageName}`
788
939
  }
@@ -1467,7 +1618,13 @@ async function scaffolder (options) {
1467
1618
  };
1468
1619
  }
1469
1620
 
1621
+ async function test ({
1622
+ projectRoot
1623
+ }) {
1624
+ return fileExists(`${projectRoot}/.nvmrc`);
1625
+ }
1626
+
1470
1627
  const questionNames = _objectSpread2(_objectSpread2({}, questionNames$2), questionNames$1);
1471
1628
 
1472
- export { questionNames, scaffolder as scaffold, scaffoldUnitTesting };
1629
+ export { lift, questionNames, scaffolder as scaffold, scaffoldUnitTesting, test };
1473
1630
  //# sourceMappingURL=index.es.js.map