@contentful/create-contentful-app 1.8.0 → 1.8.2

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.
@@ -17,37 +17,39 @@ const inquirer_1 = __importDefault(require("inquirer"));
17
17
  const fs_1 = require("fs");
18
18
  const path_1 = require("path");
19
19
  const constants_1 = require("./constants");
20
- function cloneAppAction(templateIsTypescript, destination) {
21
- const actionPath = (0, path_1.resolve)(templateIsTypescript
22
- ? 'src/app-actions/typescript/index.ts'
23
- : 'src/app-actions/javascript/index.js');
24
- const manifestPath = (0, path_1.resolve)(templateIsTypescript
25
- ? `src/app-actions/typescript/${constants_1.CONTENTFUL_APP_MANIFEST}`
26
- : `src/app-actions/javascript/${constants_1.CONTENTFUL_APP_MANIFEST}`);
27
- // write the action
28
- const appAction = (0, fs_1.readFileSync)(actionPath, { encoding: 'utf-8' }).toString();
29
- const appActionDirectoryPath = `${destination}/actions`;
30
- (0, fs_1.mkdirSync)(appActionDirectoryPath);
31
- (0, fs_1.writeFileSync)(`${appActionDirectoryPath}/example${templateIsTypescript ? '.ts' : '.js'}`, appAction);
32
- // write the manifest
33
- const manifest = JSON.parse((0, fs_1.readFileSync)(manifestPath, { encoding: 'utf-8' }));
34
- (0, fs_1.writeFileSync)(`${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`, JSON.stringify(manifest));
35
- // write the build file if necessary
36
- if (!templateIsTypescript) {
37
- const buildFilePath = 'src/app-actions/javascript/build-actions.js';
38
- const buildFile = (0, fs_1.readFileSync)(buildFilePath, { encoding: 'utf-8' }).toString();
39
- (0, fs_1.writeFileSync)(`${destination}/build-actions.js`, buildFile);
40
- }
41
- // modify package.json build commands
42
- const packageJsonLocation = `${destination}/package.json`;
43
- const packageJsonExists = (0, fs_1.existsSync)(packageJsonLocation);
44
- if (!packageJsonExists) {
45
- console.error('Failed to add app action build commands.');
46
- return;
47
- }
48
- const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonLocation, { encoding: 'utf-8' }));
49
- const updatedPackageJson = Object.assign(Object.assign({}, packageJson), { scripts: Object.assign(Object.assign({}, packageJson.scripts), { 'build-actions': `${templateIsTypescript ? 'tsc actions/*.ts --outDir build/actions' : 'node build-actions.js'}`, build: `${packageJson.scripts.build} && npm run build-actions` }) });
50
- (0, fs_1.writeFileSync)(packageJsonLocation, JSON.stringify(updatedPackageJson, null, ' '));
20
+ const degit_1 = __importDefault(require("degit"));
21
+ const logger_1 = require("./logger");
22
+ function cloneAppAction(destination, templateIsTypescript) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ try {
25
+ console.log((0, logger_1.highlight)('---- Cloning hosted app action.'));
26
+ // Clone the app actions template to the created directory under the folder 'actions'
27
+ const templateSource = (0, path_1.join)('contentful/apps/examples/hosted-app-action-templates', templateIsTypescript ? 'typescript' : 'javascript');
28
+ const appActionDirectoryPath = (0, path_1.resolve)(`${destination}/actions`);
29
+ const d = yield (0, degit_1.default)(templateSource, { mode: 'tar', cache: false });
30
+ yield d.clone(appActionDirectoryPath);
31
+ // move the manifest from the actions folder to the root folder
32
+ (0, fs_1.renameSync)(`${appActionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`, `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`);
33
+ // move the build file from the actions folder to the root folder, if necessary
34
+ if (!templateIsTypescript) {
35
+ (0, fs_1.renameSync)(`${appActionDirectoryPath}/build-actions.js`, `${destination}/build-actions.js`);
36
+ }
37
+ // modify package.json build commands
38
+ const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
39
+ const packageJsonExists = (0, fs_1.existsSync)(packageJsonLocation);
40
+ if (!packageJsonExists) {
41
+ console.error('Failed to add app action build commands.');
42
+ return;
43
+ }
44
+ const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonLocation, { encoding: 'utf-8' }));
45
+ const updatedPackageJson = Object.assign(Object.assign({}, packageJson), { scripts: Object.assign(Object.assign({}, packageJson.scripts), { 'build-actions': `${templateIsTypescript ? 'tsc actions/*.ts --outDir build/actions' : 'node build-actions.js'}`, build: `${packageJson.scripts.build} && npm run build-actions` }) });
46
+ (0, fs_1.writeFileSync)(packageJsonLocation, JSON.stringify(updatedPackageJson, null, ' '));
47
+ }
48
+ catch (e) {
49
+ console.log(e);
50
+ process.exit(1);
51
+ }
52
+ });
51
53
  }
52
54
  exports.cloneAppAction = cloneAppAction;
53
55
  const promptIncludeActionInTemplate = ({ fullAppFolder, templateSource, }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -62,7 +64,7 @@ const promptIncludeActionInTemplate = ({ fullAppFolder, templateSource, }) => __
62
64
  // put app action into the template
63
65
  if (includeAppAction) {
64
66
  const templateIsTypescript = templateSource.includes('typescript');
65
- cloneAppAction(templateIsTypescript, fullAppFolder);
67
+ cloneAppAction(fullAppFolder, templateIsTypescript);
66
68
  }
67
69
  });
68
70
  exports.promptIncludeActionInTemplate = promptIncludeActionInTemplate;
package/lib/index.js CHANGED
@@ -107,12 +107,8 @@ function initProject(appName, options) {
107
107
  interactive: isInteractive,
108
108
  });
109
109
  yield (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
110
- // Ask to include a hosted app action if the user has selected a template
111
- if (isInteractive && (0, utils_1.isContentfulTemplate)(templateSource)) {
112
- yield (0, includeAppAction_1.promptIncludeActionInTemplate)({ fullAppFolder, templateSource });
113
- }
114
110
  if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
115
- (0, includeAppAction_1.cloneAppAction)(!!normalizedOptions.typescript, fullAppFolder);
111
+ (0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.typescript);
116
112
  }
117
113
  updatePackageName(fullAppFolder);
118
114
  const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
@@ -157,7 +153,7 @@ function initProject(appName, options) {
157
153
  `provide a template by its source repository.`,
158
154
  `format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
159
155
  ].join('\n'))
160
- .option('-a, --action', 'include a hosted app action in your app')
156
+ .option('-a, --action', 'include a hosted app action in the ts or js template')
161
157
  .action(initProject);
162
158
  yield commander_1.program.parseAsync();
163
159
  });
package/lib/template.js CHANGED
@@ -46,7 +46,7 @@ function validate(destination) {
46
46
  JSON.parse((0, fs_1.readFileSync)(packageJSONLocation, 'utf-8'));
47
47
  }
48
48
  catch (e) {
49
- throw new Error(`Invalid template: invalid "${packageJSONLocation}".`);
49
+ throw new Error(`Invalid template: invalid ${packageJSONLocation}.`);
50
50
  }
51
51
  }
52
52
  function cleanUp(destination) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/create-contentful-app",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "A template for building Contentful Apps",
5
5
  "keywords": [
6
6
  "contentful",
@@ -69,5 +69,5 @@
69
69
  "@types/validate-npm-package-name": "4.0.0",
70
70
  "contentful-management": "10.32.0"
71
71
  },
72
- "gitHead": "8904c6715a206de6298692d331c478a7bb90126e"
72
+ "gitHead": "f79e7a9fbde908b671d26e783ffeafd3d96a81e9"
73
73
  }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.handler = (payload) => __awaiter(void 0, void 0, void 0, function* () {
13
- const { parameters } = payload;
14
- const response = {
15
- message: `Hello from your hosted app action. I received the following message as a paramater: ${JSON.stringify(parameters.message)} `,
16
- };
17
- return response;
18
- });