@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/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
  }),
@@ -441,13 +435,15 @@ function sortPackageProperties (packageContents) {
441
435
  'keywords',
442
436
  'runkitExampleFilename',
443
437
  'exports',
438
+ 'bin',
444
439
  'main',
445
440
  'module',
446
441
  'types',
447
- 'files',
448
- 'publishConfig',
449
442
  'sideEffects',
450
443
  'scripts',
444
+ 'files',
445
+ 'publishConfig',
446
+ 'config',
451
447
  'dependencies',
452
448
  'devDependencies',
453
449
  'peerDependencies'
@@ -676,14 +672,14 @@ function buildDialectChoices ({babelPreset, typescript}) {
676
672
  ];
677
673
  }
678
674
 
679
- function projectIsPackage(answers) {
680
- return projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
681
- }
682
-
683
675
  function projectIsCLI(answers) {
684
676
  return projectTypes.CLI === answers[questionNames$1.PROJECT_TYPE];
685
677
  }
686
678
 
679
+ function projectIsPackage(answers) {
680
+ return projectTypes.PACKAGE === answers[questionNames$1.PROJECT_TYPE];
681
+ }
682
+
687
683
  function projectIsApplication(answers) {
688
684
  return projectTypes.APPLICATION === answers[questionNames$1.PROJECT_TYPE];
689
685
  }
@@ -775,6 +771,7 @@ async function prompt(
775
771
  [questionNames$1.AUTHOR_EMAIL]: authorEmail,
776
772
  [questionNames$1.AUTHOR_URL]: authorUrl,
777
773
  [questionNames$1.CONFIGURE_LINTING]: configureLinting,
774
+ [questionNames$1.PROVIDE_EXAMPLE]: provideExample,
778
775
  [questionNames$1.PACKAGE_MANAGER]: packageManager,
779
776
  [questionNames$1.DIALECT]: dialect
780
777
  } = await prompt$1([
@@ -832,6 +829,12 @@ async function prompt(
832
829
  type: 'confirm',
833
830
  when: lintingPromptShouldBePresented
834
831
  },
832
+ {
833
+ name: questionNames$1.PROVIDE_EXAMPLE,
834
+ message: 'Should an example be provided in the README?',
835
+ type: 'confirm',
836
+ when: projectIsPackage
837
+ },
835
838
  {
836
839
  name: questionNames$1.HOST,
837
840
  type: 'list',
@@ -850,6 +853,7 @@ async function prompt(
850
853
  nodeVersionCategory,
851
854
  author: {name: authorName, email: authorEmail, url: authorUrl},
852
855
  configureLinting: false !== configureLinting,
856
+ provideExample,
853
857
  packageManager,
854
858
  dialect
855
859
  };
@@ -980,7 +984,7 @@ function getInstallationCommand(packageManager) {
980
984
  );
981
985
  }
982
986
 
983
- function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility}) {
987
+ function scaffoldPackageDocumentation ({scope, packageName, packageManager, visibility, provideExample}) {
984
988
  return {
985
989
  usage: `### Installation
986
990
  ${'Private' === visibility ? `
@@ -990,11 +994,14 @@ access to private packages under \`@${scope}\`
990
994
  }
991
995
  \`\`\`sh
992
996
  $ ${getInstallationCommand(packageManager)} ${packageName}
993
- \`\`\`
997
+ \`\`\`${provideExample
998
+ ? `
994
999
 
995
1000
  ### Example
996
1001
 
997
1002
  run \`${buildDocumentationCommand(packageManager)}\` to inject the usage example`
1003
+ : ''
1004
+ }`
998
1005
  };
999
1006
  }
1000
1007
 
@@ -1044,10 +1051,12 @@ async function createExample(projectRoot, projectName) {
1044
1051
  );
1045
1052
  }
1046
1053
 
1047
- async function buildDetailsForCommonJsProject({projectRoot, projectName}) {
1054
+ async function buildDetailsForCommonJsProject({projectRoot, projectName, provideExample}) {
1048
1055
  await Promise.all([
1049
1056
  touch(`${projectRoot}/index.js`),
1050
- promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase(projectName)} = require('.');\n`)
1057
+ provideExample
1058
+ ? promises.writeFile(`${projectRoot}/example.js`, `const ${camelcase(projectName)} = require('.');\n`)
1059
+ : Promise.resolve()
1051
1060
  ]);
1052
1061
 
1053
1062
  return {};
@@ -1060,16 +1069,17 @@ async function buildDetails ({
1060
1069
  packageName,
1061
1070
  packageBundlers,
1062
1071
  dialect,
1072
+ provideExample,
1063
1073
  decisions
1064
1074
  }) {
1065
- if (dialects$1.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName});
1075
+ if (dialects$1.COMMON_JS === dialect) return buildDetailsForCommonJsProject({projectRoot, projectName, provideExample});
1066
1076
 
1067
1077
  const chosenBundler = await chooseBundler({bundlers: packageBundlers, decisions});
1068
1078
 
1069
1079
  const pathToCreatedSrcDirectory = await makeDir(`${projectRoot}/src`);
1070
1080
  const [bundlerResults] = await Promise.all([
1071
1081
  scaffoldChoice(packageBundlers, chosenBundler, {projectRoot, dialect, projectType: projectTypes.PACKAGE}),
1072
- await createExample(projectRoot, projectName),
1082
+ provideExample ? await createExample(projectRoot, projectName) : Promise.resolve,
1073
1083
  touch(`${pathToCreatedSrcDirectory}/index.js`)
1074
1084
  ]);
1075
1085
 
@@ -1081,7 +1091,8 @@ async function buildDetails ({
1081
1091
  clean: `rimraf ./${defaultBuildDirectory$2}`,
1082
1092
  prebuild: 'run-s clean',
1083
1093
  build: 'npm-run-all --print-label --parallel build:*',
1084
- prepack: 'run-s build'
1094
+ prepack: 'run-s build',
1095
+ ...provideExample && {'pregenerate:md': 'run-s build'}
1085
1096
  },
1086
1097
  vcsIgnore: {directories: [`/${defaultBuildDirectory$2}/`]},
1087
1098
  buildDirectory: defaultBuildDirectory$2,
@@ -1110,12 +1121,22 @@ async function scaffoldPackageType ({
1110
1121
  packageBundlers,
1111
1122
  decisions,
1112
1123
  dialect,
1124
+ provideExample,
1113
1125
  publishRegistry
1114
1126
  }) {
1115
1127
  info('Scaffolding Package Details');
1116
1128
 
1117
1129
  const [detailsForBuild] = await Promise.all([
1118
- buildDetails({projectRoot, projectName, packageBundlers, visibility, packageName, dialect, decisions}),
1130
+ buildDetails({
1131
+ projectRoot,
1132
+ projectName,
1133
+ packageBundlers,
1134
+ visibility,
1135
+ packageName,
1136
+ dialect,
1137
+ provideExample,
1138
+ decisions
1139
+ }),
1119
1140
  mergeIntoExistingPackageJson({
1120
1141
  projectRoot,
1121
1142
  config: {
@@ -1154,7 +1175,7 @@ async function scaffoldPackageType ({
1154
1175
 
1155
1176
  return deepmerge.all([
1156
1177
  {
1157
- documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager}),
1178
+ documentation: scaffoldPackageDocumentation({packageName, visibility, scope, packageManager, provideExample}),
1158
1179
  nextSteps: [
1159
1180
  {summary: 'Add the appropriate `save` flag to the installation instructions in the README'},
1160
1181
  {summary: 'Publish pre-release versions to npm until package is stable enough to publish v1.0.0'}
@@ -1252,6 +1273,7 @@ async function scaffoldProjectType ({
1252
1273
  vcs,
1253
1274
  decisions,
1254
1275
  dialect,
1276
+ provideExample,
1255
1277
  publishRegistry
1256
1278
  }) {
1257
1279
  switch (projectType) {
@@ -1267,6 +1289,7 @@ async function scaffoldProjectType ({
1267
1289
  vcs,
1268
1290
  decisions,
1269
1291
  dialect,
1292
+ provideExample,
1270
1293
  publishRegistry
1271
1294
  });
1272
1295
  case projectTypes.APPLICATION:
@@ -1469,6 +1492,7 @@ async function scaffolder (options) {
1469
1492
  nodeVersionCategory,
1470
1493
  author,
1471
1494
  configureLinting,
1495
+ provideExample,
1472
1496
  packageManager,
1473
1497
  dialect
1474
1498
  } = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
@@ -1503,6 +1527,7 @@ async function scaffolder (options) {
1503
1527
  vcs,
1504
1528
  decisions,
1505
1529
  dialect,
1530
+ provideExample,
1506
1531
  publishRegistry: registries.publish
1507
1532
  });
1508
1533
  const verificationResults = await scaffoldVerification({
@@ -1527,7 +1552,7 @@ async function scaffolder (options) {
1527
1552
  projectType,
1528
1553
  testFilenamePattern: verificationResults.testFilenamePattern
1529
1554
  }),
1530
- scaffoldCodeStyle({projectRoot, projectType, dialect, configs, vcs, configureLinting})
1555
+ scaffoldCodeStyle({projectRoot, projectType, configs, vcs, configureLinting})
1531
1556
  ]);
1532
1557
  const projectTypePluginResults = await scaffoldProjectTypePlugin({
1533
1558
  projectRoot,
@@ -1556,11 +1581,11 @@ async function scaffolder (options) {
1556
1581
  scaffold$5({projectRoot, projectType, configs, pathWithinParent})
1557
1582
  ])),
1558
1583
  projectTypeResults,
1559
- projectTypePluginResults,
1560
1584
  verificationResults,
1561
1585
  codeStyleResults,
1562
1586
  npmResults,
1563
- dialectResults
1587
+ dialectResults,
1588
+ projectTypePluginResults
1564
1589
  ]);
1565
1590
 
1566
1591
  const liftResults = await lift({