@form8ion/javascript 8.4.0 → 8.5.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
@@ -86,7 +86,8 @@ const {
86
86
  [questionNames.AUTHOR_EMAIL]: 'you@domain.tld',
87
87
  [questionNames.AUTHOR_URL]: 'https://your.website.tld',
88
88
  [questionNames.UNIT_TESTS]: true,
89
- [questionNames.INTEGRATION_TESTS]: true
89
+ [questionNames.INTEGRATION_TESTS]: true,
90
+ [questionNames.PROVIDE_EXAMPLE]: true
90
91
  }
91
92
  });
92
93
 
package/example.js CHANGED
@@ -56,7 +56,8 @@ const {
56
56
  [questionNames.AUTHOR_EMAIL]: 'you@domain.tld',
57
57
  [questionNames.AUTHOR_URL]: 'https://your.website.tld',
58
58
  [questionNames.UNIT_TESTS]: true,
59
- [questionNames.INTEGRATION_TESTS]: true
59
+ [questionNames.INTEGRATION_TESTS]: true,
60
+ [questionNames.PROVIDE_EXAMPLE]: true
60
61
  }
61
62
  });
62
63
 
package/lib/index.js CHANGED
@@ -80,6 +80,7 @@ const questionNames$1 = {
80
80
  AUTHOR_URL: 'authorUrl',
81
81
  HOST: 'host',
82
82
  CONFIGURE_LINTING: 'configureLint',
83
+ PROVIDE_EXAMPLE: 'provideExample',
83
84
  DIALECT: 'dialect'
84
85
  };
85
86
 
@@ -195,7 +196,7 @@ async function scaffoldUnitTesting ({projectRoot, frameworks, decisions, visibil
195
196
  ]);
196
197
  }
197
198
 
198
- async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
199
+ async function scaffoldRemark ({config, projectRoot, projectType, vcs}) {
199
200
  await configFile.write({
200
201
  format: core.fileTypes.JSON,
201
202
  path: projectRoot,
@@ -225,19 +226,13 @@ async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect})
225
226
  'generate:md': 'remark . --output'
226
227
  }
227
228
  },
228
- {
229
- ...javascriptCore.projectTypes.PACKAGE === projectType && {
230
- devDependencies: ['remark-usage'],
231
- ...javascriptCore.dialects.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
232
- }
233
- }
229
+ {...javascriptCore.projectTypes.PACKAGE === projectType && {devDependencies: ['remark-usage']}}
234
230
  );
235
231
  }
236
232
 
237
233
  async function scaffoldCodeStyle ({
238
234
  projectRoot,
239
235
  projectType,
240
- dialect,
241
236
  configs,
242
237
  vcs,
243
238
  configureLinting
@@ -249,7 +244,6 @@ async function scaffoldCodeStyle ({
249
244
  scaffoldRemark({
250
245
  projectRoot,
251
246
  projectType,
252
- dialect,
253
247
  vcs,
254
248
  config: configs.remark || '@form8ion/remark-lint-preset'
255
249
  }),
@@ -715,14 +709,14 @@ function buildDialectChoices ({babelPreset, typescript}) {
715
709
  ];
716
710
  }
717
711
 
718
- function projectIsPackage(answers) {
719
- return javascriptCore.projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
720
- }
721
-
722
712
  function projectIsCLI(answers) {
723
713
  return javascriptCore.projectTypes.CLI === answers[questionNames$1.PROJECT_TYPE];
724
714
  }
725
715
 
716
+ function projectIsPackage(answers) {
717
+ return javascriptCore.projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
718
+ }
719
+
726
720
  function projectIsApplication(answers) {
727
721
  return javascriptCore.projectTypes.APPLICATION === answers[questionNames$1.PROJECT_TYPE];
728
722
  }
@@ -814,6 +808,7 @@ async function prompt(
814
808
  [questionNames$1.AUTHOR_EMAIL]: authorEmail,
815
809
  [questionNames$1.AUTHOR_URL]: authorUrl,
816
810
  [questionNames$1.CONFIGURE_LINTING]: configureLinting,
811
+ [questionNames$1.PROVIDE_EXAMPLE]: provideExample,
817
812
  [questionNames$1.PACKAGE_MANAGER]: packageManager,
818
813
  [questionNames$1.DIALECT]: dialect
819
814
  } = await overridablePrompts.prompt([
@@ -871,6 +866,12 @@ async function prompt(
871
866
  type: 'confirm',
872
867
  when: lintingPromptShouldBePresented
873
868
  },
869
+ {
870
+ name: questionNames$1.PROVIDE_EXAMPLE,
871
+ message: 'Should an example be provided in the README?',
872
+ type: 'confirm',
873
+ when: projectIsPackage
874
+ },
874
875
  {
875
876
  name: questionNames$1.HOST,
876
877
  type: 'list',
@@ -889,6 +890,7 @@ async function prompt(
889
890
  nodeVersionCategory,
890
891
  author: {name: authorName, email: authorEmail, url: authorUrl},
891
892
  configureLinting: false !== configureLinting,
893
+ provideExample,
892
894
  packageManager,
893
895
  dialect
894
896
  };
@@ -1019,7 +1021,7 @@ function getInstallationCommand(packageManager) {
1019
1021
  );
1020
1022
  }
1021
1023
 
1022
- function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility}) {
1024
+ function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility, provideExample}) {
1023
1025
  return {
1024
1026
  usage: `### Installation
1025
1027
  ${'Private' === visibility ? `
@@ -1029,11 +1031,14 @@ access to private packages under \`@${scope}\`
1029
1031
  }
1030
1032
  \`\`\`sh
1031
1033
  $ ${getInstallationCommand(packageManager)} ${packageName}
1032
- \`\`\`
1034
+ \`\`\`${provideExample
1035
+ ? `
1033
1036
 
1034
1037
  ### Example
1035
1038
 
1036
1039
  run \`${buildDocumentationCommand(packageManager)}\` to inject the usage example`
1040
+ : ''
1041
+ }`
1037
1042
  };
1038
1043
  }
1039
1044
 
@@ -1083,10 +1088,12 @@ async function createExample(projectRoot, projectName) {
1083
1088
  );
1084
1089
  }
1085
1090
 
1086
- async function buildDetailsForCommonJsProject({projectRoot, projectName}) {
1091
+ async function buildDetailsForCommonJsProject({projectRoot, projectName, provideExample}) {
1087
1092
  await Promise.all([
1088
1093
  touch__default["default"](`${projectRoot}/index.js`),
1089
- fs.promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase__default["default"](projectName)} = require('.');\n`)
1094
+ provideExample
1095
+ ? fs.promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase__default["default"](projectName)} = require('.');\n`)
1096
+ : Promise.resolve()
1090
1097
  ]);
1091
1098
 
1092
1099
  return {};
@@ -1099,16 +1106,17 @@ async function buildDetails ({
1099
1106
  packageName,
1100
1107
  packageBundlers,
1101
1108
  dialect,
1109
+ provideExample,
1102
1110
  decisions
1103
1111
  }) {
1104
- if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
1112
+ if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName, provideExample});
1105
1113
 
1106
1114
  const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
1107
1115
 
1108
1116
  const pathToCreatedSrcDirectory = await makeDir__default["default"](`${projectRoot}/src`);
1109
1117
  const [bundlerResults] = await Promise.all([
1110
1118
  javascriptCore.scaffoldChoice(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: javascriptCore.projectTypes.PACKAGE}),
1111
- await createExample(projectRoot, projectName),
1119
+ provideExample ? await createExample(projectRoot, projectName) : Promise.resolve,
1112
1120
  touch__default["default"](`${pathToCreatedSrcDirectory}/index.js`)
1113
1121
  ]);
1114
1122
 
@@ -1120,7 +1128,8 @@ async function buildDetails ({
1120
1128
  clean: `rimraf ./${defaultBuildDirectory$2}`,
1121
1129
  prebuild: 'run-s clean',
1122
1130
  build: 'npm-run-all --print-label --parallel build:*',
1123
- prepack: 'run-s build'
1131
+ prepack: 'run-s build',
1132
+ ...provideExample && {'pregenerate:md': 'run-s build'}
1124
1133
  },
1125
1134
  vcsIgnore: {directories: [`/${defaultBuildDirectory$2}/`]},
1126
1135
  buildDirectory: defaultBuildDirectory$2,
@@ -1149,12 +1158,22 @@ async function scaffoldPackageType ({
1149
1158
  packageBundlers,
1150
1159
  decisions,
1151
1160
  dialect,
1161
+ provideExample,
1152
1162
  publishRegistry
1153
1163
  }) {
1154
1164
  cliMessages.info('Scaffolding Package Details');
1155
1165
 
1156
1166
  const [detailsForBuild] = await Promise.all([
1157
- buildDetails({projectRoot, projectName, packageBundlers, visibility, packageName, dialect, decisions}),
1167
+ buildDetails({
1168
+ projectRoot,
1169
+ projectName,
1170
+ packageBundlers,
1171
+ visibility,
1172
+ packageName,
1173
+ dialect,
1174
+ provideExample,
1175
+ decisions
1176
+ }),
1158
1177
  javascriptCore.mergeIntoExistingPackageJson({
1159
1178
  projectRoot,
1160
1179
  config: {
@@ -1193,7 +1212,7 @@ async function scaffoldPackageType ({
1193
1212
 
1194
1213
  return deepmerge__default["default"].all([
1195
1214
  {
1196
- documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager}),
1215
+ documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager, provideExample}),
1197
1216
  nextSteps: [
1198
1217
  {summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
1199
1218
  {summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
@@ -1291,6 +1310,7 @@ async function scaffoldProjectType ({
1291
1310
  vcs,
1292
1311
  decisions,
1293
1312
  dialect,
1313
+ provideExample,
1294
1314
  publishRegistry
1295
1315
  }) {
1296
1316
  switch (projectType) {
@@ -1306,6 +1326,7 @@ async function scaffoldProjectType ({
1306
1326
  vcs,
1307
1327
  decisions,
1308
1328
  dialect,
1329
+ provideExample,
1309
1330
  publishRegistry
1310
1331
  });
1311
1332
  case javascriptCore.projectTypes.APPLICATION:
@@ -1508,6 +1529,7 @@ async function scaffolder (options) {
1508
1529
  nodeVersionCategory,
1509
1530
  author,
1510
1531
  configureLinting,
1532
+ provideExample,
1511
1533
  packageManager,
1512
1534
  dialect
1513
1535
  } = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
@@ -1542,6 +1564,7 @@ async function scaffolder (options) {
1542
1564
  vcs,
1543
1565
  decisions,
1544
1566
  dialect,
1567
+ provideExample,
1545
1568
  publishRegistry: registries.publish
1546
1569
  });
1547
1570
  const verificationResults = await scaffoldVerification({
@@ -1566,7 +1589,7 @@ async function scaffolder (options) {
1566
1589
  projectType,
1567
1590
  testFilenamePattern: verificationResults.testFilenamePattern
1568
1591
  }),
1569
- scaffoldCodeStyle({projectRoot, projectType, dialect, configs, vcs, configureLinting})
1592
+ scaffoldCodeStyle({projectRoot, projectType, configs, vcs, configureLinting})
1570
1593
  ]);
1571
1594
  const projectTypePluginResults = await scaffoldProjectTypePlugin({
1572
1595
  projectRoot,