@contentful/create-contentful-app 1.12.3 → 1.13.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.
@@ -24,12 +24,23 @@ const addBuildCommand = (0, package_1.getAddBuildCommandFn)({
24
24
  name: 'build:functions',
25
25
  command: 'node build-functions.js',
26
26
  });
27
- function cloneFunction(destination, templateIsJavascript) {
27
+ const VALID_FUNCTION_TEMPLATES_DIRS = ['templates', 'appevent-filter'];
28
+ function functionTemplateFromName(functionName) {
29
+ let dirName = functionName;
30
+ if (functionName === 'external-references')
31
+ dirName = 'templates'; // backwards compatible for the apps repo examples folder for delivery functions (external-references)
32
+ if (!VALID_FUNCTION_TEMPLATES_DIRS.includes(dirName)) {
33
+ console.error(`Invalid function template: ${functionName}. Must be one of ${VALID_FUNCTION_TEMPLATES_DIRS.join(', ')}.`);
34
+ process.exit(1);
35
+ }
36
+ return dirName;
37
+ }
38
+ function cloneFunction(destination, templateIsJavascript, functionName) {
28
39
  return __awaiter(this, void 0, void 0, function* () {
29
40
  try {
30
- console.log((0, logger_1.highlight)('---- Cloning function.'));
41
+ console.log((0, logger_1.highlight)(`---- Cloning function "${functionName}".`));
31
42
  // Clone the function template to the created directory under the folder 'actions'
32
- const templateSource = (0, path_1.join)('contentful/apps/examples/function-templates', templateIsJavascript ? 'javascript' : 'typescript');
43
+ const templateSource = (0, path_1.join)(`contentful/apps/examples/function-${functionTemplateFromName(functionName)}`, templateIsJavascript ? 'javascript' : 'typescript');
33
44
  const functionDirectoryPath = (0, path_1.resolve)(`${destination}/functions`);
34
45
  const d = (0, degit_1.default)(templateSource, { mode: 'tar', cache: false });
35
46
  yield d.clone(functionDirectoryPath);
@@ -53,7 +64,10 @@ function cloneFunction(destination, templateIsJavascript) {
53
64
  mergeFn: addBuildCommand,
54
65
  });
55
66
  yield Promise.all([writeAppManifest, copyBuildFile, writeBuildCommand]);
56
- yield d.remove(functionDirectoryPath, destination, { action: "remove", files: constants_1.IGNORED_CLONED_FILES.map(fileName => `${functionDirectoryPath}/${fileName}`) });
67
+ yield d.remove(functionDirectoryPath, destination, {
68
+ action: 'remove',
69
+ files: constants_1.IGNORED_CLONED_FILES.map((fileName) => `${functionDirectoryPath}/${fileName}`),
70
+ });
57
71
  }
58
72
  catch (e) {
59
73
  console.error(e);
package/lib/index.js CHANGED
@@ -116,7 +116,7 @@ function initProject(appName, options) {
116
116
  if (!isInteractive &&
117
117
  (0, utils_1.isContentfulTemplate)(templateSource) &&
118
118
  normalizedOptions.function) {
119
- yield (0, includeFunction_1.cloneFunction)(fullAppFolder, !!normalizedOptions.javascript);
119
+ yield (0, includeFunction_1.cloneFunction)(fullAppFolder, !!normalizedOptions.javascript, normalizedOptions.function);
120
120
  }
121
121
  updatePackageName(fullAppFolder);
122
122
  const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
@@ -162,7 +162,7 @@ function initProject(appName, options) {
162
162
  `format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
163
163
  ].join('\n'))
164
164
  .option('-a, --action', 'include a hosted app action in the ts or js template')
165
- .option('-f, --function', 'include a function template')
165
+ .option('-f, --function <function-template-name>', 'include the specified function template')
166
166
  .action(initProject);
167
167
  yield commander_1.program.parseAsync();
168
168
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/create-contentful-app",
3
- "version": "1.12.3",
3
+ "version": "1.13.0",
4
4
  "description": "A template for building Contentful Apps",
5
5
  "keywords": [
6
6
  "contentful",
@@ -81,5 +81,5 @@
81
81
  "sinon-chai": "^3.7.0",
82
82
  "ts-node": "^10.9.1"
83
83
  },
84
- "gitHead": "7576b84daf5069f42177cd8d43117f5f3c7056be"
84
+ "gitHead": "ea3442268d98eb87272b1e627b43cd2279590cbb"
85
85
  }