@contentful/create-contentful-app 1.18.7-alpha.0 → 2.0.1-alpha.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/getTemplateSource.js +3 -1
- package/lib/index.js +16 -2
- package/package.json +3 -3
- package/lib/includeFunction.js +0 -75
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([
|
package/lib/index.js
CHANGED
|
@@ -18,7 +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
|
|
21
|
+
const app_scripts_1 = require("@contentful/app-scripts");
|
|
22
22
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
23
23
|
function successMessage(folder, useYarn) {
|
|
24
24
|
console.log(`
|
|
@@ -100,7 +100,21 @@ async function initProject(appName, options) {
|
|
|
100
100
|
if (normalizedOptions.function === true) {
|
|
101
101
|
normalizedOptions.function = 'external-references';
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
process.chdir(fullAppFolder);
|
|
104
|
+
`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
|
+
});
|
|
104
118
|
}
|
|
105
119
|
updatePackageName(fullAppFolder);
|
|
106
120
|
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1-alpha.0",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -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": "ccc4144ab5f50174d718f814c8a12304a36d1f18"
|
|
84
84
|
}
|
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;
|