@form8ion/javascript 8.4.0 → 8.7.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/lib/index.mjs CHANGED
@@ -43,6 +43,7 @@ const questionNames$1 = {
43
43
  AUTHOR_URL: 'authorUrl',
44
44
  HOST: 'host',
45
45
  CONFIGURE_LINTING: 'configureLint',
46
+ PROVIDE_EXAMPLE: 'provideExample',
46
47
  DIALECT: 'dialect'
47
48
  };
48
49
 
@@ -158,7 +159,7 @@ async function scaffoldUnitTesting ({projectRoot, frameworks, decisions, visibil
158
159
  ]);
159
160
  }
160
161
 
161
- async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect}) {
162
+ async function scaffoldRemark ({config, projectRoot, projectType, vcs}) {
162
163
  await write$1({
163
164
  format: fileTypes.JSON,
164
165
  path: projectRoot,
@@ -188,19 +189,13 @@ async function scaffoldRemark ({config, projectRoot, projectType, vcs, dialect})
188
189
  'generate:md': 'remark . --output'
189
190
  }
190
191
  },
191
- {
192
- ...projectTypes.PACKAGE === projectType && {
193
- devDependencies: ['remark-usage'],
194
- ...dialects$1.COMMON_JS !== dialect && {scripts: {'pregenerate:md': 'run-s build'}}
195
- }
196
- }
192
+ {...projectTypes.PACKAGE === projectType && {devDependencies: ['remark-usage']}}
197
193
  );
198
194
  }
199
195
 
200
196
  async function scaffoldCodeStyle ({
201
197
  projectRoot,
202
198
  projectType,
203
- dialect,
204
199
  configs,
205
200
  vcs,
206
201
  configureLinting
@@ -212,7 +207,6 @@ async function scaffoldCodeStyle ({
212
207
  scaffoldRemark({
213
208
  projectRoot,
214
209
  projectType,
215
- dialect,
216
210
  vcs,
217
211
  config: configs.remark || '@form8ion/remark-lint-preset'
218
212
  }),
@@ -435,9 +429,11 @@ function sortPackageProperties (packageContents) {
435
429
  'type',
436
430
  'engines',
437
431
  'author',
432
+ 'contributors',
438
433
  'repository',
439
434
  'bugs',
440
435
  'homepage',
436
+ 'funding',
441
437
  'keywords',
442
438
  'runkitExampleFilename',
443
439
  'exports',
@@ -678,14 +674,14 @@ function buildDialectChoices ({babelPreset, typescript}) {
678
674
  ];
679
675
  }
680
676
 
681
- function projectIsPackage(answers) {
682
- return projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
683
- }
684
-
685
677
  function projectIsCLI(answers) {
686
678
  return projectTypes.CLI === answers[questionNames$1.PROJECT_TYPE];
687
679
  }
688
680
 
681
+ function projectIsPackage(answers) {
682
+ return projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
683
+ }
684
+
689
685
  function projectIsApplication(answers) {
690
686
  return projectTypes.APPLICATION === answers[questionNames$1.PROJECT_TYPE];
691
687
  }
@@ -777,6 +773,7 @@ async function prompt(
777
773
  [questionNames$1.AUTHOR_EMAIL]: authorEmail,
778
774
  [questionNames$1.AUTHOR_URL]: authorUrl,
779
775
  [questionNames$1.CONFIGURE_LINTING]: configureLinting,
776
+ [questionNames$1.PROVIDE_EXAMPLE]: provideExample,
780
777
  [questionNames$1.PACKAGE_MANAGER]: packageManager,
781
778
  [questionNames$1.DIALECT]: dialect
782
779
  } = await prompt$1([
@@ -834,6 +831,12 @@ async function prompt(
834
831
  type: 'confirm',
835
832
  when: lintingPromptShouldBePresented
836
833
  },
834
+ {
835
+ name: questionNames$1.PROVIDE_EXAMPLE,
836
+ message: 'Should an example be provided in the README?',
837
+ type: 'confirm',
838
+ when: projectIsPackage
839
+ },
837
840
  {
838
841
  name: questionNames$1.HOST,
839
842
  type: 'list',
@@ -852,6 +855,7 @@ async function prompt(
852
855
  nodeVersionCategory,
853
856
  author: {name: authorName, email: authorEmail, url: authorUrl},
854
857
  configureLinting: false !== configureLinting,
858
+ provideExample,
855
859
  packageManager,
856
860
  dialect
857
861
  };
@@ -982,7 +986,7 @@ function getInstallationCommand(packageManager) {
982
986
  );
983
987
  }
984
988
 
985
- function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility}) {
989
+ function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility, provideExample}) {
986
990
  return {
987
991
  usage: `### Installation
988
992
  ${'Private' === visibility ? `
@@ -992,11 +996,14 @@ access to private packages under \`@${scope}\`
992
996
  }
993
997
  \`\`\`sh
994
998
  $ ${getInstallationCommand(packageManager)} ${packageName}
995
- \`\`\`
999
+ \`\`\`${provideExample
1000
+ ? `
996
1001
 
997
1002
  ### Example
998
1003
 
999
1004
  run \`${buildDocumentationCommand(packageManager)}\` to inject the usage example`
1005
+ : ''
1006
+ }`
1000
1007
  };
1001
1008
  }
1002
1009
 
@@ -1046,10 +1053,12 @@ async function createExample(projectRoot, projectName) {
1046
1053
  );
1047
1054
  }
1048
1055
 
1049
- async function buildDetailsForCommonJsProject({projectRoot, projectName}) {
1056
+ async function buildDetailsForCommonJsProject({projectRoot, projectName, provideExample}) {
1050
1057
  await Promise.all([
1051
1058
  touch(`${projectRoot}/index.js`),
1052
- promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase(projectName)} = require('.');\n`)
1059
+ provideExample
1060
+ ? promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase(projectName)} = require('.');\n`)
1061
+ : Promise.resolve()
1053
1062
  ]);
1054
1063
 
1055
1064
  return {};
@@ -1062,16 +1071,17 @@ async function buildDetails ({
1062
1071
  packageName,
1063
1072
  packageBundlers,
1064
1073
  dialect,
1074
+ provideExample,
1065
1075
  decisions
1066
1076
  }) {
1067
- if (dialects$1.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
1077
+ if (dialects$1.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName, provideExample});
1068
1078
 
1069
1079
  const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
1070
1080
 
1071
1081
  const pathToCreatedSrcDirectory = await makeDir(`${projectRoot}/src`);
1072
1082
  const [bundlerResults] = await Promise.all([
1073
1083
  scaffoldChoice(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: projectTypes.PACKAGE}),
1074
- await createExample(projectRoot, projectName),
1084
+ provideExample ? await createExample(projectRoot, projectName) : Promise.resolve,
1075
1085
  touch(`${pathToCreatedSrcDirectory}/index.js`)
1076
1086
  ]);
1077
1087
 
@@ -1083,7 +1093,8 @@ async function buildDetails ({
1083
1093
  clean: `rimraf ./${defaultBuildDirectory$2}`,
1084
1094
  prebuild: 'run-s clean',
1085
1095
  build: 'npm-run-all --print-label --parallel build:*',
1086
- prepack: 'run-s build'
1096
+ prepack: 'run-s build',
1097
+ ...provideExample && {'pregenerate:md': 'run-s build'}
1087
1098
  },
1088
1099
  vcsIgnore: {directories: [`/${defaultBuildDirectory$2}/`]},
1089
1100
  buildDirectory: defaultBuildDirectory$2,
@@ -1112,12 +1123,22 @@ async function scaffoldPackageType ({
1112
1123
  packageBundlers,
1113
1124
  decisions,
1114
1125
  dialect,
1126
+ provideExample,
1115
1127
  publishRegistry
1116
1128
  }) {
1117
1129
  info('Scaffolding Package Details');
1118
1130
 
1119
1131
  const [detailsForBuild] = await Promise.all([
1120
- buildDetails({projectRoot, projectName, packageBundlers, visibility, packageName, dialect, decisions}),
1132
+ buildDetails({
1133
+ projectRoot,
1134
+ projectName,
1135
+ packageBundlers,
1136
+ visibility,
1137
+ packageName,
1138
+ dialect,
1139
+ provideExample,
1140
+ decisions
1141
+ }),
1121
1142
  mergeIntoExistingPackageJson({
1122
1143
  projectRoot,
1123
1144
  config: {
@@ -1156,7 +1177,7 @@ async function scaffoldPackageType ({
1156
1177
 
1157
1178
  return deepmerge.all([
1158
1179
  {
1159
- documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager}),
1180
+ documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager, provideExample}),
1160
1181
  nextSteps: [
1161
1182
  {summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
1162
1183
  {summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
@@ -1254,6 +1275,7 @@ async function scaffoldProjectType ({
1254
1275
  vcs,
1255
1276
  decisions,
1256
1277
  dialect,
1278
+ provideExample,
1257
1279
  publishRegistry
1258
1280
  }) {
1259
1281
  switch (projectType) {
@@ -1269,6 +1291,7 @@ async function scaffoldProjectType ({
1269
1291
  vcs,
1270
1292
  decisions,
1271
1293
  dialect,
1294
+ provideExample,
1272
1295
  publishRegistry
1273
1296
  });
1274
1297
  case projectTypes.APPLICATION:
@@ -1471,6 +1494,7 @@ async function scaffolder (options) {
1471
1494
  nodeVersionCategory,
1472
1495
  author,
1473
1496
  configureLinting,
1497
+ provideExample,
1474
1498
  packageManager,
1475
1499
  dialect
1476
1500
  } = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
@@ -1505,6 +1529,7 @@ async function scaffolder (options) {
1505
1529
  vcs,
1506
1530
  decisions,
1507
1531
  dialect,
1532
+ provideExample,
1508
1533
  publishRegistry: registries.publish
1509
1534
  });
1510
1535
  const verificationResults = await scaffoldVerification({
@@ -1529,7 +1554,7 @@ async function scaffolder (options) {
1529
1554
  projectType,
1530
1555
  testFilenamePattern: verificationResults.testFilenamePattern
1531
1556
  }),
1532
- scaffoldCodeStyle({projectRoot, projectType, dialect, configs, vcs, configureLinting})
1557
+ scaffoldCodeStyle({projectRoot, projectType, configs, vcs, configureLinting})
1533
1558
  ]);
1534
1559
  const projectTypePluginResults = await scaffoldProjectTypePlugin({
1535
1560
  projectRoot,
@@ -1558,11 +1583,11 @@ async function scaffolder (options) {
1558
1583
  scaffold$5({projectRoot, projectType, configs, pathWithinParent})
1559
1584
  ])),
1560
1585
  projectTypeResults,
1561
- projectTypePluginResults,
1562
1586
  verificationResults,
1563
1587
  codeStyleResults,
1564
1588
  npmResults,
1565
- dialectResults
1589
+ dialectResults,
1590
+ projectTypePluginResults
1566
1591
  ]);
1567
1592
 
1568
1593
  const liftResults = await lift({