@form8ion/javascript 8.3.0 → 8.6.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
  }),
@@ -478,13 +472,15 @@ function sortPackageProperties (packageContents) {
478
472
  'keywords',
479
473
  'runkitExampleFilename',
480
474
  'exports',
475
+ 'bin',
481
476
  'main',
482
477
  'module',
483
478
  'types',
484
- 'files',
485
- 'publishConfig',
486
479
  'sideEffects',
487
480
  'scripts',
481
+ 'files',
482
+ 'publishConfig',
483
+ 'config',
488
484
  'dependencies',
489
485
  'devDependencies',
490
486
  'peerDependencies'
@@ -713,14 +709,14 @@ function buildDialectChoices ({babelPreset, typescript}) {
713
709
  ];
714
710
  }
715
711
 
716
- function projectIsPackage(answers) {
717
- return javascriptCore.projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
718
- }
719
-
720
712
  function projectIsCLI(answers) {
721
713
  return javascriptCore.projectTypes.CLI === answers[questionNames$1.PROJECT_TYPE];
722
714
  }
723
715
 
716
+ function projectIsPackage(answers) {
717
+ return javascriptCore.projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
718
+ }
719
+
724
720
  function projectIsApplication(answers) {
725
721
  return javascriptCore.projectTypes.APPLICATION === answers[questionNames$1.PROJECT_TYPE];
726
722
  }
@@ -812,6 +808,7 @@ async function prompt(
812
808
  [questionNames$1.AUTHOR_EMAIL]: authorEmail,
813
809
  [questionNames$1.AUTHOR_URL]: authorUrl,
814
810
  [questionNames$1.CONFIGURE_LINTING]: configureLinting,
811
+ [questionNames$1.PROVIDE_EXAMPLE]: provideExample,
815
812
  [questionNames$1.PACKAGE_MANAGER]: packageManager,
816
813
  [questionNames$1.DIALECT]: dialect
817
814
  } = await overridablePrompts.prompt([
@@ -869,6 +866,12 @@ async function prompt(
869
866
  type: 'confirm',
870
867
  when: lintingPromptShouldBePresented
871
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
+ },
872
875
  {
873
876
  name: questionNames$1.HOST,
874
877
  type: 'list',
@@ -887,6 +890,7 @@ async function prompt(
887
890
  nodeVersionCategory,
888
891
  author: {name: authorName, email: authorEmail, url: authorUrl},
889
892
  configureLinting: false !== configureLinting,
893
+ provideExample,
890
894
  packageManager,
891
895
  dialect
892
896
  };
@@ -1017,7 +1021,7 @@ function getInstallationCommand(packageManager) {
1017
1021
  );
1018
1022
  }
1019
1023
 
1020
- function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility}) {
1024
+ function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility, provideExample}) {
1021
1025
  return {
1022
1026
  usage: `### Installation
1023
1027
  ${'Private' === visibility ? `
@@ -1027,11 +1031,14 @@ access to private packages under \`@${scope}\`
1027
1031
  }
1028
1032
  \`\`\`sh
1029
1033
  $ ${getInstallationCommand(packageManager)} ${packageName}
1030
- \`\`\`
1034
+ \`\`\`${provideExample
1035
+ ? `
1031
1036
 
1032
1037
  ### Example
1033
1038
 
1034
1039
  run \`${buildDocumentationCommand(packageManager)}\` to inject the usage example`
1040
+ : ''
1041
+ }`
1035
1042
  };
1036
1043
  }
1037
1044
 
@@ -1081,10 +1088,12 @@ async function createExample(projectRoot, projectName) {
1081
1088
  );
1082
1089
  }
1083
1090
 
1084
- async function buildDetailsForCommonJsProject({projectRoot, projectName}) {
1091
+ async function buildDetailsForCommonJsProject({projectRoot, projectName, provideExample}) {
1085
1092
  await Promise.all([
1086
1093
  touch__default["default"](`${projectRoot}/index.js`),
1087
- 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()
1088
1097
  ]);
1089
1098
 
1090
1099
  return {};
@@ -1097,16 +1106,17 @@ async function buildDetails ({
1097
1106
  packageName,
1098
1107
  packageBundlers,
1099
1108
  dialect,
1109
+ provideExample,
1100
1110
  decisions
1101
1111
  }) {
1102
- if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
1112
+ if (javascriptCore.dialects.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName, provideExample});
1103
1113
 
1104
1114
  const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
1105
1115
 
1106
1116
  const pathToCreatedSrcDirectory = await makeDir__default["default"](`${projectRoot}/src`);
1107
1117
  const [bundlerResults] = await Promise.all([
1108
1118
  javascriptCore.scaffoldChoice(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: javascriptCore.projectTypes.PACKAGE}),
1109
- await createExample(projectRoot, projectName),
1119
+ provideExample ? await createExample(projectRoot, projectName) : Promise.resolve,
1110
1120
  touch__default["default"](`${pathToCreatedSrcDirectory}/index.js`)
1111
1121
  ]);
1112
1122
 
@@ -1118,7 +1128,8 @@ async function buildDetails ({
1118
1128
  clean: `rimraf ./${defaultBuildDirectory$2}`,
1119
1129
  prebuild: 'run-s clean',
1120
1130
  build: 'npm-run-all --print-label --parallel build:*',
1121
- prepack: 'run-s build'
1131
+ prepack: 'run-s build',
1132
+ ...provideExample && {'pregenerate:md': 'run-s build'}
1122
1133
  },
1123
1134
  vcsIgnore: {directories: [`/${defaultBuildDirectory$2}/`]},
1124
1135
  buildDirectory: defaultBuildDirectory$2,
@@ -1147,12 +1158,22 @@ async function scaffoldPackageType ({
1147
1158
  packageBundlers,
1148
1159
  decisions,
1149
1160
  dialect,
1161
+ provideExample,
1150
1162
  publishRegistry
1151
1163
  }) {
1152
1164
  cliMessages.info('Scaffolding Package Details');
1153
1165
 
1154
1166
  const [detailsForBuild] = await Promise.all([
1155
- 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
+ }),
1156
1177
  javascriptCore.mergeIntoExistingPackageJson({
1157
1178
  projectRoot,
1158
1179
  config: {
@@ -1191,7 +1212,7 @@ async function scaffoldPackageType ({
1191
1212
 
1192
1213
  return deepmerge__default["default"].all([
1193
1214
  {
1194
- documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager}),
1215
+ documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager, provideExample}),
1195
1216
  nextSteps: [
1196
1217
  {summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
1197
1218
  {summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
@@ -1289,6 +1310,7 @@ async function scaffoldProjectType ({
1289
1310
  vcs,
1290
1311
  decisions,
1291
1312
  dialect,
1313
+ provideExample,
1292
1314
  publishRegistry
1293
1315
  }) {
1294
1316
  switch (projectType) {
@@ -1304,6 +1326,7 @@ async function scaffoldProjectType ({
1304
1326
  vcs,
1305
1327
  decisions,
1306
1328
  dialect,
1329
+ provideExample,
1307
1330
  publishRegistry
1308
1331
  });
1309
1332
  case javascriptCore.projectTypes.APPLICATION:
@@ -1506,6 +1529,7 @@ async function scaffolder (options) {
1506
1529
  nodeVersionCategory,
1507
1530
  author,
1508
1531
  configureLinting,
1532
+ provideExample,
1509
1533
  packageManager,
1510
1534
  dialect
1511
1535
  } = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
@@ -1540,6 +1564,7 @@ async function scaffolder (options) {
1540
1564
  vcs,
1541
1565
  decisions,
1542
1566
  dialect,
1567
+ provideExample,
1543
1568
  publishRegistry: registries.publish
1544
1569
  });
1545
1570
  const verificationResults = await scaffoldVerification({
@@ -1564,7 +1589,7 @@ async function scaffolder (options) {
1564
1589
  projectType,
1565
1590
  testFilenamePattern: verificationResults.testFilenamePattern
1566
1591
  }),
1567
- scaffoldCodeStyle({projectRoot, projectType, dialect, configs, vcs, configureLinting})
1592
+ scaffoldCodeStyle({projectRoot, projectType, configs, vcs, configureLinting})
1568
1593
  ]);
1569
1594
  const projectTypePluginResults = await scaffoldProjectTypePlugin({
1570
1595
  projectRoot,
@@ -1593,11 +1618,11 @@ async function scaffolder (options) {
1593
1618
  commitConventionPlugin.scaffold({projectRoot, projectType, configs, pathWithinParent})
1594
1619
  ])),
1595
1620
  projectTypeResults,
1596
- projectTypePluginResults,
1597
1621
  verificationResults,
1598
1622
  codeStyleResults,
1599
1623
  npmResults,
1600
- dialectResults
1624
+ dialectResults,
1625
+ projectTypePluginResults
1601
1626
  ]);
1602
1627
 
1603
1628
  const liftResults = await lift({