@contentful/create-contentful-app 1.18.8 → 2.0.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 +0 -1
- package/lib/getTemplateSource.js +4 -2
- package/lib/index.js +17 -9
- package/lib/utils.js +0 -2
- package/package.json +5 -5
- package/lib/includeAppAction.js +0 -70
- package/lib/includeFunction.js +0 -75
package/README.md
CHANGED
|
@@ -95,7 +95,6 @@ Options:
|
|
|
95
95
|
-e, --example <example-name> bootstrap an example app from https://github.com/contentful/apps/tree/master/examples
|
|
96
96
|
-s, --source <url> provide a template by its source repository.
|
|
97
97
|
format: URL (HTTPS or SSH) or vendor:user/repo (e.g., github:user/repo)
|
|
98
|
-
-a, --actions includes a hosted app action in ts or js template
|
|
99
98
|
-f, --function <function-template-name> include the specified function template
|
|
100
99
|
-h, --help shows all available CLI options
|
|
101
100
|
```
|
package/lib/getTemplateSource.js
CHANGED
|
@@ -49,7 +49,9 @@ async function promptExampleSelection() {
|
|
|
49
49
|
// get available templates from examples
|
|
50
50
|
const availableTemplates = await (0, getGithubFolderNames_1.getGithubFolderNames)();
|
|
51
51
|
// filter out the ignored ones that are listed as templates instead of examples
|
|
52
|
-
const filteredTemplates = availableTemplates
|
|
52
|
+
const filteredTemplates = availableTemplates
|
|
53
|
+
.filter((template) => !constants_1.IGNORED_EXAMPLE_FOLDERS.includes(template))
|
|
54
|
+
.filter((template) => !template.includes('function'));
|
|
53
55
|
console.log(availableTemplates.length, filteredTemplates.length);
|
|
54
56
|
// ask user to select a template from the available examples
|
|
55
57
|
const { example } = await inquirer_1.default.prompt([
|
|
@@ -86,7 +88,7 @@ async function makeContentfulExampleSource(options) {
|
|
|
86
88
|
if (options.typescript) {
|
|
87
89
|
return selectTemplate(types_1.ContentfulExample.Typescript);
|
|
88
90
|
}
|
|
89
|
-
if (options.function
|
|
91
|
+
if (options.function) {
|
|
90
92
|
return selectTemplate(types_1.ContentfulExample.Typescript);
|
|
91
93
|
}
|
|
92
94
|
return await promptExampleSelection();
|
package/lib/index.js
CHANGED
|
@@ -18,8 +18,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
18
18
|
const constants_1 = require("./constants");
|
|
19
19
|
const getTemplateSource_1 = require("./getTemplateSource");
|
|
20
20
|
const analytics_1 = require("./analytics");
|
|
21
|
-
const
|
|
22
|
-
const includeFunction_1 = require("./includeFunction");
|
|
21
|
+
const app_scripts_1 = require("@contentful/app-scripts");
|
|
23
22
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
24
23
|
function successMessage(folder, useYarn) {
|
|
25
24
|
console.log(`
|
|
@@ -87,8 +86,7 @@ async function initProject(appName, options) {
|
|
|
87
86
|
!normalizedOptions.source &&
|
|
88
87
|
!normalizedOptions.javascript &&
|
|
89
88
|
!normalizedOptions.typescript &&
|
|
90
|
-
!normalizedOptions.function
|
|
91
|
-
!normalizedOptions.action;
|
|
89
|
+
!normalizedOptions.function;
|
|
92
90
|
const templateSource = await (0, getTemplateSource_1.getTemplateSource)(options);
|
|
93
91
|
(0, analytics_1.track)({
|
|
94
92
|
template: templateSource,
|
|
@@ -96,16 +94,27 @@ async function initProject(appName, options) {
|
|
|
96
94
|
interactive: isInteractive,
|
|
97
95
|
});
|
|
98
96
|
await (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
|
|
99
|
-
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
|
|
100
|
-
await (0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.javascript);
|
|
101
|
-
}
|
|
102
97
|
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.function) {
|
|
103
98
|
// If function flag is specified, but no function name is provided, we default to external-references
|
|
104
99
|
// for legacy support
|
|
105
100
|
if (normalizedOptions.function === true) {
|
|
106
101
|
normalizedOptions.function = 'external-references';
|
|
107
102
|
}
|
|
108
|
-
|
|
103
|
+
process.chdir(fullAppFolder);
|
|
104
|
+
(0, logger_1.wrapInBlanks)(`To add additional function templates to your app, use ${(0, logger_1.highlight)(chalk_1.default.green(`
|
|
105
|
+
npx @contentful/app-scripts@latest generate-function \\
|
|
106
|
+
--ci \\
|
|
107
|
+
--name <name> \\
|
|
108
|
+
--example <example> \\
|
|
109
|
+
--language <typescript/javascript>`))}`);
|
|
110
|
+
const functionName = normalizedOptions.function
|
|
111
|
+
.toLowerCase()
|
|
112
|
+
.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
|
|
113
|
+
await app_scripts_1.generateFunction.nonInteractive({
|
|
114
|
+
example: normalizedOptions.function,
|
|
115
|
+
language: 'typescript',
|
|
116
|
+
name: functionName,
|
|
117
|
+
});
|
|
109
118
|
}
|
|
110
119
|
updatePackageName(fullAppFolder);
|
|
111
120
|
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
@@ -148,7 +157,6 @@ async function initProject(appName, options) {
|
|
|
148
157
|
`provide a template by its source repository.`,
|
|
149
158
|
`format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
|
|
150
159
|
].join('\n'))
|
|
151
|
-
.option('-a, --action', 'include a hosted app action in the ts or js template')
|
|
152
160
|
.option('-f, --function [function-template-name]', 'include the specified function template')
|
|
153
161
|
.action(initProject);
|
|
154
162
|
await commander_1.program.parseAsync();
|
package/lib/utils.js
CHANGED
|
@@ -55,14 +55,12 @@ function normalizeOptions(options) {
|
|
|
55
55
|
delete normalizedOptions.example;
|
|
56
56
|
delete normalizedOptions.typescript;
|
|
57
57
|
delete normalizedOptions.javascript;
|
|
58
|
-
delete normalizedOptions.action;
|
|
59
58
|
delete normalizedOptions.function;
|
|
60
59
|
}
|
|
61
60
|
if (normalizedOptions.example) {
|
|
62
61
|
fallbackOption = '--example';
|
|
63
62
|
delete normalizedOptions.typescript;
|
|
64
63
|
delete normalizedOptions.javascript;
|
|
65
|
-
delete normalizedOptions.action;
|
|
66
64
|
delete normalizedOptions.function;
|
|
67
65
|
}
|
|
68
66
|
if (normalizedOptions.typescript) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"directory": "packages/contentful--create-contentful-app"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
-
"npm": ">=
|
|
17
|
+
"node": ">=18",
|
|
18
|
+
"npm": ">=9"
|
|
19
19
|
},
|
|
20
20
|
"main": "lib/index.js",
|
|
21
21
|
"lint-staged": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"create-contentful-app": "lib/index.js"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"prettier": "prettier **/*.
|
|
31
|
+
"prettier": "prettier **/*.ts --write --ignore-path .gitignore",
|
|
32
32
|
"lint": "eslint ./src",
|
|
33
33
|
"lint:fix": "npm run lint -- --fix",
|
|
34
34
|
"pre-commit": "lint-staged",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"sinon-chai": "^3.7.0",
|
|
81
81
|
"ts-node": "^10.9.2"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "d58b78ba56df989e585aae54cb297e186c8e713b"
|
|
84
84
|
}
|
package/lib/includeAppAction.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.promptIncludeActionInTemplate = exports.cloneAppAction = void 0;
|
|
7
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
-
const promises_1 = require("fs/promises");
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const constants_1 = require("./constants");
|
|
11
|
-
const tiged_1 = __importDefault(require("tiged"));
|
|
12
|
-
const logger_1 = require("./logger");
|
|
13
|
-
const package_1 = require("./utils/package");
|
|
14
|
-
const file_1 = require("./utils/file");
|
|
15
|
-
const addBuildCommand = (0, package_1.getAddBuildCommandFn)({
|
|
16
|
-
name: 'build:actions',
|
|
17
|
-
command: 'node build-actions.js',
|
|
18
|
-
});
|
|
19
|
-
async function cloneAppAction(destination, templateIsJavascript) {
|
|
20
|
-
try {
|
|
21
|
-
console.log((0, logger_1.highlight)('---- Cloning hosted app action.'));
|
|
22
|
-
// Clone the app actions template to the created directory under the folder 'actions'
|
|
23
|
-
const templateSource = (0, path_1.join)('contentful/apps/examples/hosted-app-action-templates', templateIsJavascript ? 'javascript' : 'typescript');
|
|
24
|
-
const appActionDirectoryPath = (0, path_1.resolve)(`${destination}/actions`);
|
|
25
|
-
const d = await (0, tiged_1.default)(templateSource, { mode: 'tar', disableCache: true });
|
|
26
|
-
await d.clone(appActionDirectoryPath);
|
|
27
|
-
// move the manifest from the actions folder to the root folder
|
|
28
|
-
const writeAppManifest = await (0, file_1.mergeJsonIntoFile)({
|
|
29
|
-
source: `${appActionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
30
|
-
destination: `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
31
|
-
});
|
|
32
|
-
// move the build file from the actions folder to the root folder
|
|
33
|
-
const copyBuildFile = await (0, promises_1.rename)(`${appActionDirectoryPath}/build-actions.js`, `${destination}/build-actions.js`);
|
|
34
|
-
// modify package.json build commands
|
|
35
|
-
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
36
|
-
const packageJsonExists = await (0, file_1.exists)(packageJsonLocation);
|
|
37
|
-
if (!packageJsonExists) {
|
|
38
|
-
console.error(`Failed to add app action build commands: ${packageJsonLocation} does not exist.`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const writeBuildCommand = await (0, file_1.mergeJsonIntoFile)({
|
|
42
|
-
source: `${appActionDirectoryPath}/package.json`,
|
|
43
|
-
destination: packageJsonLocation,
|
|
44
|
-
mergeFn: addBuildCommand,
|
|
45
|
-
});
|
|
46
|
-
await Promise.all([writeAppManifest, copyBuildFile, writeBuildCommand]);
|
|
47
|
-
await d.remove(appActionDirectoryPath, destination, { action: 'remove', files: constants_1.IGNORED_CLONED_FILES.map(fileName => `${appActionDirectoryPath}/${fileName}`) });
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
console.log(e);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.cloneAppAction = cloneAppAction;
|
|
55
|
-
const promptIncludeActionInTemplate = async ({ fullAppFolder, templateSource, }) => {
|
|
56
|
-
const { includeAppAction } = await inquirer_1.default.prompt([
|
|
57
|
-
{
|
|
58
|
-
name: 'includeAppAction',
|
|
59
|
-
message: 'Do you want to include a hosted app action?',
|
|
60
|
-
type: 'confirm',
|
|
61
|
-
default: false,
|
|
62
|
-
},
|
|
63
|
-
]);
|
|
64
|
-
// put app action into the template
|
|
65
|
-
if (includeAppAction) {
|
|
66
|
-
const templateIsTypescript = templateSource.includes('typescript');
|
|
67
|
-
cloneAppAction(fullAppFolder, templateIsTypescript);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
exports.promptIncludeActionInTemplate = promptIncludeActionInTemplate;
|
package/lib/includeFunction.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.cloneFunction = exports.functionTemplateFromName = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const rimraf_1 = require("rimraf");
|
|
10
|
-
const tiged_1 = __importDefault(require("tiged"));
|
|
11
|
-
const constants_1 = require("./constants");
|
|
12
|
-
const logger_1 = require("./logger");
|
|
13
|
-
const types_1 = require("./types");
|
|
14
|
-
const file_1 = require("./utils/file");
|
|
15
|
-
const package_1 = require("./utils/package");
|
|
16
|
-
// TODO: after appActions work we can change this getAddBuildCommandFn params from command -> defaultCommand as examples will have build commands
|
|
17
|
-
const addBuildCommand = (0, package_1.getAddBuildCommandFn)({
|
|
18
|
-
name: 'build:functions',
|
|
19
|
-
command: 'contentful-app-scripts build-functions --ci',
|
|
20
|
-
});
|
|
21
|
-
const VALID_FUNCTION_TEMPLATES_DIRS = [
|
|
22
|
-
'appevent-filter',
|
|
23
|
-
'appevent-handler',
|
|
24
|
-
'appevent-transformation',
|
|
25
|
-
'external-references',
|
|
26
|
-
'comment-bot',
|
|
27
|
-
];
|
|
28
|
-
function functionTemplateFromName(functionName, destination) {
|
|
29
|
-
let dirName = functionName;
|
|
30
|
-
if (!VALID_FUNCTION_TEMPLATES_DIRS.includes(dirName)) {
|
|
31
|
-
// cleanup in case of invalid example
|
|
32
|
-
rimraf_1.rimraf.sync(destination);
|
|
33
|
-
throw new types_1.InvalidTemplateError(`${chalk_1.default.red(`Invalid function template:`)} The function name ${(0, logger_1.highlight)(chalk_1.default.cyan(functionName))} is not valid. Must be one of: ${(0, logger_1.highlight)(VALID_FUNCTION_TEMPLATES_DIRS.join(', '))}.`);
|
|
34
|
-
}
|
|
35
|
-
if (functionName === 'external-references')
|
|
36
|
-
dirName = 'templates'; // backwards compatible for the apps repo examples folder for delivery functions (external-references)
|
|
37
|
-
return dirName;
|
|
38
|
-
}
|
|
39
|
-
exports.functionTemplateFromName = functionTemplateFromName;
|
|
40
|
-
async function cloneFunction(destination, templateIsJavascript, functionName) {
|
|
41
|
-
try {
|
|
42
|
-
console.log((0, logger_1.highlight)(`---- Cloning function ${chalk_1.default.cyan(functionName)}...`));
|
|
43
|
-
// Clone the function template to the created directory under the folder 'actions'
|
|
44
|
-
const templateSource = (0, path_1.join)(`contentful/apps/examples/function-${functionTemplateFromName(functionName, destination)}`, templateIsJavascript ? 'javascript' : 'typescript');
|
|
45
|
-
const functionDirectoryPath = (0, path_1.resolve)(`${destination}/functions`);
|
|
46
|
-
const d = (0, tiged_1.default)(templateSource, { mode: 'tar', disableCache: true });
|
|
47
|
-
await d.clone(functionDirectoryPath);
|
|
48
|
-
// merge the manifest from the template folder to the root folder
|
|
49
|
-
const writeAppManifest = (0, file_1.mergeJsonIntoFile)({
|
|
50
|
-
source: `${functionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
51
|
-
destination: `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
52
|
-
});
|
|
53
|
-
// modify package.json build commands
|
|
54
|
-
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
55
|
-
const packageJsonExists = await (0, file_1.exists)(packageJsonLocation);
|
|
56
|
-
if (!packageJsonExists) {
|
|
57
|
-
throw new Error(`Failed to add function build commands: ${packageJsonLocation} does not exist.`);
|
|
58
|
-
}
|
|
59
|
-
const writeBuildCommand = (0, file_1.mergeJsonIntoFile)({
|
|
60
|
-
source: `${functionDirectoryPath}/package.json`,
|
|
61
|
-
destination: packageJsonLocation,
|
|
62
|
-
mergeFn: addBuildCommand,
|
|
63
|
-
});
|
|
64
|
-
await Promise.all([writeAppManifest, writeBuildCommand]);
|
|
65
|
-
await d.remove(functionDirectoryPath, destination, {
|
|
66
|
-
action: 'remove',
|
|
67
|
-
files: constants_1.IGNORED_CLONED_FILES.map((fileName) => `${functionDirectoryPath}/${fileName}`),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
(0, logger_1.error)(`Failed to clone function ${(0, logger_1.highlight)(chalk_1.default.cyan(functionName))}`, e);
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.cloneFunction = cloneFunction;
|