@contentful/create-contentful-app 1.7.16 → 1.8.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 +1 -0
- package/lib/app-actions/typescript/index.js +18 -0
- package/lib/constants.js +3 -1
- package/lib/getTemplateSource.js +3 -6
- package/lib/includeAppAction.js +68 -0
- package/lib/index.js +18 -2
- package/lib/types.js +1 -1
- package/lib/utils.js +9 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -96,6 +96,7 @@ Options:
|
|
|
96
96
|
-e, --example <example-name> bootstrap an example app from https://github.com/contentful/apps/tree/master/examples
|
|
97
97
|
-s, --source <url> provide a template by its source repository.
|
|
98
98
|
format: URL (HTTPS or SSH) or vendor:user/repo (e.g., github:user/repo)
|
|
99
|
+
-a, --actions includes a hosted app action in ts or js template
|
|
99
100
|
-h, --help shows all available CLI options
|
|
100
101
|
```
|
|
101
102
|
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
});
|
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TEMPLATES = exports.EXAMPLES_REPO_URL = exports.CREATE_APP_DEFINITION_GUIDE_URL = void 0;
|
|
3
|
+
exports.CONTENTFUL_APP_MANIFEST = exports.EXAMPLES_PATH = exports.TEMPLATES = exports.EXAMPLES_REPO_URL = exports.CREATE_APP_DEFINITION_GUIDE_URL = void 0;
|
|
4
4
|
exports.CREATE_APP_DEFINITION_GUIDE_URL = 'https://ctfl.io/app-tutorial#embed-your-app-in-the-contentful-web-app';
|
|
5
5
|
exports.EXAMPLES_REPO_URL = 'https://github.com/contentful/apps/tree/master/examples';
|
|
6
6
|
exports.TEMPLATES = ['javascript', 'typescript', 'vue', 'vite-react', 'nextjs'];
|
|
7
|
+
exports.EXAMPLES_PATH = 'contentful/apps/examples/';
|
|
8
|
+
exports.CONTENTFUL_APP_MANIFEST = 'contentful-app-manifest.json';
|
package/lib/getTemplateSource.js
CHANGED
|
@@ -19,11 +19,8 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
19
19
|
const types_1 = require("./types");
|
|
20
20
|
const logger_1 = require("./logger");
|
|
21
21
|
const constants_1 = require("./constants");
|
|
22
|
+
const utils_1 = require("./utils");
|
|
22
23
|
const CONTENTFUL_APPS_EXAMPLE_FOLDER = 'https://api.github.com/repos/contentful/apps/contents/examples';
|
|
23
|
-
const EXAMPLES_PATH = 'contentful/apps/examples/';
|
|
24
|
-
function isContentfulTemplate(url) {
|
|
25
|
-
return Object.values(types_1.ContentfulExample).some((t) => url.includes(EXAMPLES_PATH + t));
|
|
26
|
-
}
|
|
27
24
|
function getGithubFolderNames() {
|
|
28
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
26
|
const response = yield (0, node_fetch_1.default)(CONTENTFUL_APPS_EXAMPLE_FOLDER);
|
|
@@ -88,7 +85,7 @@ function promptExampleSelection() {
|
|
|
88
85
|
}
|
|
89
86
|
function selectTemplate(template) {
|
|
90
87
|
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Cloning the ${chalk_1.default.cyan(template)} template...`));
|
|
91
|
-
return EXAMPLES_PATH + template;
|
|
88
|
+
return constants_1.EXAMPLES_PATH + template;
|
|
92
89
|
}
|
|
93
90
|
function makeContentfulExampleSource(options) {
|
|
94
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -108,7 +105,7 @@ function getTemplateSource(options) {
|
|
|
108
105
|
var _a;
|
|
109
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
107
|
const source = (_a = options.source) !== null && _a !== void 0 ? _a : (yield makeContentfulExampleSource(options));
|
|
111
|
-
if (options.source && !isContentfulTemplate(source)) {
|
|
108
|
+
if (options.source && !(0, utils_1.isContentfulTemplate)(source)) {
|
|
112
109
|
(0, logger_1.warn)(`Template at ${(0, logger_1.highlight)(source)} is not an official Contentful app template!`);
|
|
113
110
|
}
|
|
114
111
|
return source;
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.promptIncludeActionInTemplate = exports.cloneAppAction = void 0;
|
|
16
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const path_1 = require("path");
|
|
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, ' '));
|
|
51
|
+
}
|
|
52
|
+
exports.cloneAppAction = cloneAppAction;
|
|
53
|
+
const promptIncludeActionInTemplate = ({ fullAppFolder, templateSource, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const { includeAppAction } = yield inquirer_1.default.prompt([
|
|
55
|
+
{
|
|
56
|
+
name: 'includeAppAction',
|
|
57
|
+
message: 'Do you want to include a hosted app action?',
|
|
58
|
+
type: 'confirm',
|
|
59
|
+
default: false,
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
// put app action into the template
|
|
63
|
+
if (includeAppAction) {
|
|
64
|
+
const templateIsTypescript = templateSource.includes('typescript');
|
|
65
|
+
cloneAppAction(templateIsTypescript, fullAppFolder);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
exports.promptIncludeActionInTemplate = promptIncludeActionInTemplate;
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
27
27
|
const constants_1 = require("./constants");
|
|
28
28
|
const getTemplateSource_1 = require("./getTemplateSource");
|
|
29
29
|
const analytics_1 = require("./analytics");
|
|
30
|
+
const includeAppAction_1 = require("./includeAppAction");
|
|
30
31
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
31
32
|
function successMessage(folder, useYarn) {
|
|
32
33
|
console.log(`
|
|
@@ -95,10 +96,24 @@ function initProject(appName, options) {
|
|
|
95
96
|
appName = yield validateAppName(appName);
|
|
96
97
|
const fullAppFolder = (0, path_1.resolve)(process.cwd(), appName);
|
|
97
98
|
console.log(`Creating a Contentful app in ${(0, logger_1.highlight)((0, tildify_1.default)(fullAppFolder))}.`);
|
|
98
|
-
const isInteractive = !normalizedOptions.example &&
|
|
99
|
+
const isInteractive = !normalizedOptions.example &&
|
|
100
|
+
!normalizedOptions.source &&
|
|
101
|
+
!normalizedOptions.javascript &&
|
|
102
|
+
!normalizedOptions.typescript;
|
|
99
103
|
const templateSource = yield (0, getTemplateSource_1.getTemplateSource)(options);
|
|
100
|
-
(0, analytics_1.track)({
|
|
104
|
+
(0, analytics_1.track)({
|
|
105
|
+
template: templateSource,
|
|
106
|
+
manager: normalizedOptions.npm ? 'npm' : 'yarn',
|
|
107
|
+
interactive: isInteractive,
|
|
108
|
+
});
|
|
101
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
|
+
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
|
|
115
|
+
(0, includeAppAction_1.cloneAppAction)(!!normalizedOptions.typescript, fullAppFolder);
|
|
116
|
+
}
|
|
102
117
|
updatePackageName(fullAppFolder);
|
|
103
118
|
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
104
119
|
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Installing the dependencies for your app (using ${chalk_1.default.cyan(useYarn ? 'yarn' : 'npm')})...`));
|
|
@@ -142,6 +157,7 @@ function initProject(appName, options) {
|
|
|
142
157
|
`provide a template by its source repository.`,
|
|
143
158
|
`format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
|
|
144
159
|
].join('\n'))
|
|
160
|
+
.option('-a, --action', 'include a hosted app action in your app')
|
|
145
161
|
.action(initProject);
|
|
146
162
|
yield commander_1.program.parseAsync();
|
|
147
163
|
});
|
package/lib/types.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeOptions = exports.detectManager = exports.rmIfExists = exports.exec = void 0;
|
|
3
|
+
exports.isContentfulTemplate = exports.normalizeOptions = exports.detectManager = exports.rmIfExists = exports.exec = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const logger_1 = require("./logger");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
8
10
|
const MUTUALLY_EXCLUSIVE_OPTIONS = ['source', 'example', 'typescript', 'javascript'];
|
|
9
11
|
function exec(command, args, options) {
|
|
10
12
|
return new Promise((resolve, reject) => {
|
|
@@ -53,11 +55,13 @@ function normalizeOptions(options) {
|
|
|
53
55
|
delete normalizedOptions.example;
|
|
54
56
|
delete normalizedOptions.typescript;
|
|
55
57
|
delete normalizedOptions.javascript;
|
|
58
|
+
delete normalizedOptions.action;
|
|
56
59
|
}
|
|
57
60
|
if (normalizedOptions.example) {
|
|
58
61
|
fallbackOption = '--example';
|
|
59
62
|
delete normalizedOptions.typescript;
|
|
60
63
|
delete normalizedOptions.javascript;
|
|
64
|
+
delete normalizedOptions.action;
|
|
61
65
|
}
|
|
62
66
|
if (normalizedOptions.typescript) {
|
|
63
67
|
fallbackOption = '--typescript';
|
|
@@ -70,3 +74,7 @@ function normalizeOptions(options) {
|
|
|
70
74
|
return normalizedOptions;
|
|
71
75
|
}
|
|
72
76
|
exports.normalizeOptions = normalizeOptions;
|
|
77
|
+
function isContentfulTemplate(url) {
|
|
78
|
+
return Object.values(types_1.ContentfulExample).some((t) => url.includes(constants_1.EXAMPLES_PATH + t));
|
|
79
|
+
}
|
|
80
|
+
exports.isContentfulTemplate = isContentfulTemplate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"build": "tsc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@contentful/app-scripts": "1.
|
|
38
|
+
"@contentful/app-scripts": "1.8.1",
|
|
39
39
|
"analytics-node": "^6.2.0",
|
|
40
40
|
"chalk": "4.1.2",
|
|
41
|
-
"commander": "10.0.
|
|
41
|
+
"commander": "10.0.1",
|
|
42
42
|
"degit": "2.8.4",
|
|
43
43
|
"inquirer": "8.2.5",
|
|
44
44
|
"node-fetch": "2.6.7",
|
|
45
|
-
"rimraf": "
|
|
45
|
+
"rimraf": "5.0.0",
|
|
46
46
|
"tildify": "2.0.0",
|
|
47
47
|
"validate-npm-package-name": "5.0.0"
|
|
48
48
|
},
|
|
@@ -62,11 +62,12 @@
|
|
|
62
62
|
"@types/chalk": "2.2.0",
|
|
63
63
|
"@types/degit": "2.8.3",
|
|
64
64
|
"@types/inquirer": "8.2.1",
|
|
65
|
-
"@types/node": "14.18.
|
|
65
|
+
"@types/node": "14.18.42",
|
|
66
66
|
"@types/node-fetch": "^2.6.2",
|
|
67
67
|
"@types/rimraf": "3.0.2",
|
|
68
68
|
"@types/tildify": "2.0.2",
|
|
69
|
-
"@types/validate-npm-package-name": "4.0.0"
|
|
69
|
+
"@types/validate-npm-package-name": "4.0.0",
|
|
70
|
+
"contentful-management": "10.32.0"
|
|
70
71
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "8904c6715a206de6298692d331c478a7bb90126e"
|
|
72
73
|
}
|