@form8ion/javascript 2.0.0-alpha.1 → 2.2.0

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 CHANGED
@@ -17,14 +17,7 @@ toolset
17
17
  * [Example](#example)
18
18
  * [Import](#import)
19
19
  * [Execute](#execute)
20
- * [API](#api)
21
- * [`scaffoldUnitTesting`](#scaffoldunittesting)
22
- * [`projectRoot` __string__ (_required_)](#projectroot-string-required)
23
- * [`frameworks` __object__ (_required_)](#frameworks-object-required)
24
- * [`decisions` __object__ (_optional_)](#decisions-object-optional)
25
- * [`visibility` __string__ (_required_)](#visibility-string-required)
26
- * [`vcs` __object__ (_required_)](#vcs-object-required)
27
- * [`questionNames`](#questionnames)
20
+ * [Documentation](#documentation)
28
21
  * [Contributing](#contributing)
29
22
  * [Dependencies](#dependencies)
30
23
  * [Verification](#verification)
@@ -51,13 +44,45 @@ $ npm install @form8ion/javascript --save
51
44
  #### Import
52
45
 
53
46
  ```javascript
54
- import {scaffoldUnitTesting, questionNames} from '@form8ion/javascript';
47
+ const {dialects, projectTypes} = require('@form8ion/javascript-core');
48
+ const {scaffold: scaffoldJavaScript, scaffoldUnitTesting, questionNames} = require('./lib/index.cjs');
55
49
  ```
56
50
 
57
51
  #### Execute
58
52
 
59
53
  ```javascript
60
54
  (async () => {
55
+ const accountName = 'form8ion';
56
+
57
+ await scaffoldJavaScript({
58
+ projectRoot: process.cwd(),
59
+ projectName: 'project-name',
60
+ visibility: 'Public',
61
+ license: 'MIT',
62
+ configs: {
63
+ eslint: {scope: `@${accountName}`},
64
+ remark: `@${accountName}/remark-lint-preset`,
65
+ babelPreset: {name: `@${accountName}`, packageName: `@${accountName}/babel-preset`},
66
+ commitlint: {name: `@${accountName}`, packageName: `@${accountName}/commitlint-config`}
67
+ },
68
+ overrides: {npmAccount: accountName},
69
+ ciServices: {},
70
+ unitTestFrameworks: {},
71
+ decisions: {
72
+ [questionNames.DIALECT]: dialects.BABEL,
73
+ [questionNames.NODE_VERSION_CATEGORY]: 'LTS',
74
+ [questionNames.PACKAGE_MANAGER]: 'npm',
75
+ [questionNames.PROJECT_TYPE]: projectTypes.PACKAGE,
76
+ [questionNames.SHOULD_BE_SCOPED]: true,
77
+ [questionNames.SCOPE]: accountName,
78
+ [questionNames.AUTHOR_NAME]: 'Your Name',
79
+ [questionNames.AUTHOR_EMAIL]: 'you@domain.tld',
80
+ [questionNames.AUTHOR_URL]: 'https://your.website.tld',
81
+ [questionNames.UNIT_TESTS]: true,
82
+ [questionNames.INTEGRATION_TESTS]: true
83
+ }
84
+ });
85
+
61
86
  await scaffoldUnitTesting({
62
87
  projectRoot: process.cwd(),
63
88
  frameworks: {
@@ -71,48 +96,10 @@ import {scaffoldUnitTesting, questionNames} from '@form8ion/javascript';
71
96
  })();
72
97
  ```
73
98
 
74
- ### API
75
-
76
- #### `scaffoldUnitTesting`
77
-
78
- Scaffolder for enabling unit-testing in a project with the ability to choose a
79
- desired framework from provided options.
80
-
81
- Takes a single options object as an argument, containing:
82
-
83
- ##### `projectRoot` __string__ (_required_)
84
-
85
- path to the root of the project
86
-
87
- ##### `frameworks` __object__ (_required_)
88
-
89
- A [`choices` object](https://github.com/form8ion/javascript-core#choices-object-required)
90
- for defining [unit-testing framework options](https://github.com/form8ion/awesome#unit-testing-frameworks)
91
-
92
- ##### `decisions` __object__ (_optional_)
93
-
94
- Answers for prompt questions so that the prompt is skipped at execution time
95
-
96
- * keys: __string__ Name of the prompt question
97
- * values: Hard-coded answer for the prompt question
98
-
99
- ##### `visibility` __string__ (_required_)
100
-
101
- visibility of the project (`Public` or `Private`)
102
-
103
- ##### `vcs` __object__ (_required_)
104
-
105
- * `host` __string__ (_required_)
106
- VCS hosting service
107
- * `owner` __string__ (_required_)
108
- account name on the host service for the repository
109
- * `name` __string__ (_required_)
110
- repository name
111
-
112
- #### `questionNames`
99
+ ### Documentation
113
100
 
114
- Constants defining the question names for the prompts implemented in this
115
- package
101
+ * [API](./docs/api)
102
+ * [Constants](./docs/constants)
116
103
 
117
104
  ## Contributing
118
105
 
package/example.js CHANGED
@@ -1,14 +1,57 @@
1
1
  // #### Import
2
- // remark-usage-ignore-next
2
+ // remark-usage-ignore-next 4
3
+ import {resolve} from 'path';
3
4
  import stubbedFs from 'mock-fs';
4
- import {scaffoldUnitTesting, questionNames} from './lib/index.cjs';
5
+ import td from 'testdouble';
6
+ import 'validate-npm-package-name';
5
7
 
6
- // remark-usage-ignore-next
7
- stubbedFs();
8
+ // remark-usage-ignore-next 9
9
+ stubbedFs({
10
+ node_modules: stubbedFs.load(resolve(...[__dirname, 'node_modules'])),
11
+ lib: stubbedFs.load(resolve(...[__dirname, 'lib'])),
12
+ templates: stubbedFs.load(resolve(...[__dirname, 'templates']))
13
+ });
14
+ const execa = td.replace('execa');
15
+ td.when(execa('. ~/.nvm/nvm.sh && nvm ls-remote --lts', {shell: true}))
16
+ .thenResolve({stdout: ['v16.5.4', ''].join('\n')});
17
+ td.when(execa('. ~/.nvm/nvm.sh && nvm install', {shell: true})).thenReturn({stdout: {pipe: () => undefined}});
8
18
 
9
- // #### Execute
19
+ const {dialects, projectTypes} = require('@form8ion/javascript-core');
20
+ const {scaffold: scaffoldJavaScript, scaffoldUnitTesting, questionNames} = require('./lib/index.cjs');
10
21
 
22
+ // #### Execute
11
23
  (async () => {
24
+ const accountName = 'form8ion';
25
+
26
+ await scaffoldJavaScript({
27
+ projectRoot: process.cwd(),
28
+ projectName: 'project-name',
29
+ visibility: 'Public',
30
+ license: 'MIT',
31
+ configs: {
32
+ eslint: {scope: `@${accountName}`},
33
+ remark: `@${accountName}/remark-lint-preset`,
34
+ babelPreset: {name: `@${accountName}`, packageName: `@${accountName}/babel-preset`},
35
+ commitlint: {name: `@${accountName}`, packageName: `@${accountName}/commitlint-config`}
36
+ },
37
+ overrides: {npmAccount: accountName},
38
+ ciServices: {},
39
+ unitTestFrameworks: {},
40
+ decisions: {
41
+ [questionNames.DIALECT]: dialects.BABEL,
42
+ [questionNames.NODE_VERSION_CATEGORY]: 'LTS',
43
+ [questionNames.PACKAGE_MANAGER]: 'npm',
44
+ [questionNames.PROJECT_TYPE]: projectTypes.PACKAGE,
45
+ [questionNames.SHOULD_BE_SCOPED]: true,
46
+ [questionNames.SCOPE]: accountName,
47
+ [questionNames.AUTHOR_NAME]: 'Your Name',
48
+ [questionNames.AUTHOR_EMAIL]: 'you@domain.tld',
49
+ [questionNames.AUTHOR_URL]: 'https://your.website.tld',
50
+ [questionNames.UNIT_TESTS]: true,
51
+ [questionNames.INTEGRATION_TESTS]: true
52
+ }
53
+ });
54
+
12
55
  await scaffoldUnitTesting({
13
56
  projectRoot: process.cwd(),
14
57
  frameworks: {
package/lib/index.cjs.js CHANGED
@@ -7,7 +7,7 @@ var deepmerge = require('deepmerge');
7
7
  var javascriptCore = require('@form8ion/javascript-core');
8
8
  var codecov = require('@form8ion/codecov');
9
9
  var fs = require('fs');
10
- var joi = require('@hapi/joi');
10
+ var joi = require('joi');
11
11
  var inquirer = require('inquirer');
12
12
  var overridablePrompts = require('@form8ion/overridable-prompts');
13
13
  var cliMessages = require('@travi/cli-messages');
@@ -62,14 +62,9 @@ function ownKeys(object, enumerableOnly) {
62
62
 
63
63
  if (Object.getOwnPropertySymbols) {
64
64
  var symbols = Object.getOwnPropertySymbols(object);
65
-
66
- if (enumerableOnly) {
67
- symbols = symbols.filter(function (sym) {
68
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
69
- });
70
- }
71
-
72
- keys.push.apply(keys, symbols);
65
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
66
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
67
+ })), keys.push.apply(keys, symbols);
73
68
  }
74
69
 
75
70
  return keys;
@@ -77,19 +72,12 @@ function ownKeys(object, enumerableOnly) {
77
72
 
78
73
  function _objectSpread2(target) {
79
74
  for (var i = 1; i < arguments.length; i++) {
80
- var source = arguments[i] != null ? arguments[i] : {};
81
-
82
- if (i % 2) {
83
- ownKeys(Object(source), true).forEach(function (key) {
84
- _defineProperty(target, key, source[key]);
85
- });
86
- } else if (Object.getOwnPropertyDescriptors) {
87
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
88
- } else {
89
- ownKeys(Object(source)).forEach(function (key) {
90
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
91
- });
92
- }
75
+ var source = null != arguments[i] ? arguments[i] : {};
76
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
77
+ _defineProperty(target, key, source[key]);
78
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
79
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
80
+ });
93
81
  }
94
82
 
95
83
  return target;
@@ -150,13 +138,15 @@ async function scaffoldC8 ({
150
138
  async function scaffoldCoverage ({
151
139
  projectRoot,
152
140
  vcs,
153
- visibility
141
+ visibility,
142
+ pathWithinParent
154
143
  }) {
155
144
  return deepmerge__default["default"](await scaffoldC8({
156
145
  projectRoot
157
146
  }), await codecov.scaffold({
158
147
  vcs,
159
- visibility
148
+ visibility,
149
+ pathWithinParent
160
150
  }));
161
151
  }
162
152
 
@@ -183,7 +173,8 @@ async function scaffoldUnitTesting ({
183
173
  frameworks,
184
174
  decisions,
185
175
  visibility,
186
- vcs
176
+ vcs,
177
+ pathWithinParent
187
178
  }) {
188
179
  const validatedFrameworks = javascriptCore.validateOptions(unitTestFrameworksSchema, frameworks);
189
180
  const [framework, coverage] = await Promise.all([chooseFramework({
@@ -194,7 +185,8 @@ async function scaffoldUnitTesting ({
194
185
  })), scaffoldCoverage({
195
186
  projectRoot,
196
187
  vcs,
197
- visibility
188
+ visibility,
189
+ pathWithinParent
198
190
  })]);
199
191
  return deepmerge__default["default"].all([{
200
192
  scripts: {
@@ -824,7 +816,7 @@ function defineBadges (packageName, visibility) {
824
816
  return {
825
817
  consumer: _objectSpread2({}, 'Public' === visibility && {
826
818
  npm: {
827
- img: `https://img.shields.io/npm/v/${packageName}.svg`,
819
+ img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
828
820
  text: 'npm',
829
821
  link: `https://www.npmjs.com/package/${packageName}`
830
822
  }
@@ -1171,7 +1163,8 @@ async function scaffoldTesting ({
1171
1163
  vcs,
1172
1164
  unitTestFrameworks,
1173
1165
  decisions,
1174
- dialect
1166
+ dialect,
1167
+ pathWithinParent
1175
1168
  }) {
1176
1169
  const unitResults = unit ? await scaffoldUnitTesting({
1177
1170
  projectRoot,
@@ -1179,7 +1172,8 @@ async function scaffoldTesting ({
1179
1172
  vcs,
1180
1173
  frameworks: unitTestFrameworks,
1181
1174
  decisions,
1182
- dialect
1175
+ dialect,
1176
+ pathWithinParent
1183
1177
  }) : {};
1184
1178
  return deepmerge__default["default"]({
1185
1179
  devDependencies: [...(unit || integration ? ['@travi/any'] : [])],
@@ -1328,7 +1322,8 @@ async function scaffoldVerification({
1328
1322
  unitTestFrameworks,
1329
1323
  decisions,
1330
1324
  buildDirectory,
1331
- eslintConfigs
1325
+ eslintConfigs,
1326
+ pathWithinParent
1332
1327
  }) {
1333
1328
  const [testingResults, huskyResults] = await Promise.all([scaffoldTesting({
1334
1329
  projectRoot,
@@ -1337,7 +1332,8 @@ async function scaffoldVerification({
1337
1332
  vcs,
1338
1333
  unitTestFrameworks,
1339
1334
  decisions,
1340
- dialect
1335
+ dialect,
1336
+ pathWithinParent
1341
1337
  }), husky.scaffold({
1342
1338
  projectRoot,
1343
1339
  packageManager
@@ -1361,7 +1357,7 @@ async function scaffoldVerification({
1361
1357
  return deepmerge__default["default"].all([testingResults, lintingResults, huskyResults]);
1362
1358
  }
1363
1359
 
1364
- async function scaffold(options) {
1360
+ async function scaffolder (options) {
1365
1361
  cliMessages.info('Initializing JavaScript project');
1366
1362
  const {
1367
1363
  projectRoot,
@@ -1427,6 +1423,7 @@ async function scaffold(options) {
1427
1423
  tests,
1428
1424
  unitTestFrameworks,
1429
1425
  decisions,
1426
+ pathWithinParent,
1430
1427
  buildDirectory: projectTypeResults.buildDirectory,
1431
1428
  eslintConfigs: projectTypeResults.eslintConfigs
1432
1429
  });
@@ -1507,6 +1504,6 @@ async function scaffold(options) {
1507
1504
  const questionNames = _objectSpread2(_objectSpread2({}, languageScaffolderPrompts.questionNames), questionNames$1);
1508
1505
 
1509
1506
  exports.questionNames = questionNames;
1510
- exports.scaffold = scaffold;
1507
+ exports.scaffold = scaffolder;
1511
1508
  exports.scaffoldUnitTesting = scaffoldUnitTesting;
1512
1509
  //# sourceMappingURL=index.cjs.js.map