@contentful/create-contentful-app 1.8.10 → 1.9.1
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/includeAppAction.js +20 -8
- package/lib/includeDeliveryFunction.js +63 -0
- package/lib/index.js +8 -1
- package/lib/template.js +25 -2
- package/lib/utils/file.js +46 -0
- package/lib/utils/package.js +24 -0
- package/lib/utils.js +2 -0
- package/package.json +21 -9
package/lib/includeAppAction.js
CHANGED
|
@@ -14,11 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.promptIncludeActionInTemplate = exports.cloneAppAction = void 0;
|
|
16
16
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
-
const
|
|
17
|
+
const promises_1 = require("fs/promises");
|
|
18
18
|
const path_1 = require("path");
|
|
19
19
|
const constants_1 = require("./constants");
|
|
20
20
|
const degit_1 = __importDefault(require("degit"));
|
|
21
21
|
const logger_1 = require("./logger");
|
|
22
|
+
const package_1 = require("./utils/package");
|
|
23
|
+
const file_1 = require("./utils/file");
|
|
24
|
+
const addBuildCommand = (0, package_1.getAddBuildCommandFn)({
|
|
25
|
+
name: 'build:actions',
|
|
26
|
+
command: 'node build-actions.js',
|
|
27
|
+
});
|
|
22
28
|
function cloneAppAction(destination, templateIsTypescript) {
|
|
23
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
30
|
try {
|
|
@@ -29,19 +35,25 @@ function cloneAppAction(destination, templateIsTypescript) {
|
|
|
29
35
|
const d = yield (0, degit_1.default)(templateSource, { mode: 'tar', cache: false });
|
|
30
36
|
yield d.clone(appActionDirectoryPath);
|
|
31
37
|
// move the manifest from the actions folder to the root folder
|
|
32
|
-
(0,
|
|
38
|
+
const writeAppManifest = yield (0, file_1.mergeJsonIntoFile)({
|
|
39
|
+
source: `${appActionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
40
|
+
destination: `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
41
|
+
});
|
|
33
42
|
// move the build file from the actions folder to the root folder
|
|
34
|
-
(0,
|
|
43
|
+
const copyBuildFile = yield (0, promises_1.rename)(`${appActionDirectoryPath}/build-actions.js`, `${destination}/build-actions.js`);
|
|
35
44
|
// modify package.json build commands
|
|
36
45
|
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
37
|
-
const packageJsonExists = (0,
|
|
46
|
+
const packageJsonExists = yield (0, file_1.exists)(packageJsonLocation);
|
|
38
47
|
if (!packageJsonExists) {
|
|
39
|
-
console.error(
|
|
48
|
+
console.error(`Failed to add app action build commands: ${packageJsonLocation} does not exist.`);
|
|
40
49
|
return;
|
|
41
50
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
const writeBuildCommand = yield (0, file_1.mergeJsonIntoFile)({
|
|
52
|
+
source: `${appActionDirectoryPath}/package.json`,
|
|
53
|
+
destination: packageJsonLocation,
|
|
54
|
+
mergeFn: addBuildCommand,
|
|
55
|
+
});
|
|
56
|
+
yield Promise.all([writeAppManifest, copyBuildFile, writeBuildCommand]);
|
|
45
57
|
}
|
|
46
58
|
catch (e) {
|
|
47
59
|
console.log(e);
|
|
@@ -0,0 +1,63 @@
|
|
|
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.cloneDeliveryFunction = void 0;
|
|
16
|
+
const promises_1 = require("fs/promises");
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
const degit_1 = __importDefault(require("degit"));
|
|
20
|
+
const logger_1 = require("./logger");
|
|
21
|
+
const file_1 = require("./utils/file");
|
|
22
|
+
const package_1 = require("./utils/package");
|
|
23
|
+
const addBuildCommand = (0, package_1.getAddBuildCommandFn)({
|
|
24
|
+
name: 'build:delivery-functions',
|
|
25
|
+
command: 'node build-delivery-functions.js',
|
|
26
|
+
});
|
|
27
|
+
function cloneDeliveryFunction(destination, templateIsTypescript) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
console.log((0, logger_1.highlight)('---- Cloning hosted delivery function.'));
|
|
31
|
+
// Clone the delivery function template to the created directory under the folder 'actions'
|
|
32
|
+
const templateSource = (0, path_1.join)('contentful/apps/examples/hosted-delivery-function-templates', templateIsTypescript ? 'typescript' : 'javascript');
|
|
33
|
+
const deliveryFunctionDirectoryPath = (0, path_1.resolve)(`${destination}/delivery-functions`);
|
|
34
|
+
const d = yield (0, degit_1.default)(templateSource, { mode: 'tar', cache: false });
|
|
35
|
+
yield d.clone(deliveryFunctionDirectoryPath);
|
|
36
|
+
// merge the manifest from the template folder to the root folder
|
|
37
|
+
const writeAppManifest = (0, file_1.mergeJsonIntoFile)({
|
|
38
|
+
source: `${deliveryFunctionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
39
|
+
destination: `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`,
|
|
40
|
+
});
|
|
41
|
+
// move the build file from the actions folder to the root folder
|
|
42
|
+
const copyBuildFile = (0, promises_1.rename)(`${deliveryFunctionDirectoryPath}/build-delivery-functions.js`, `${destination}/build-delivery-functions.js`);
|
|
43
|
+
// modify package.json build commands
|
|
44
|
+
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
45
|
+
const packageJsonExists = yield (0, file_1.exists)(packageJsonLocation);
|
|
46
|
+
if (!packageJsonExists) {
|
|
47
|
+
console.error(`Failed to add delivery function build commands: ${packageJsonLocation} does not exist.`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const writeBuildCommand = (0, file_1.mergeJsonIntoFile)({
|
|
51
|
+
source: `${deliveryFunctionDirectoryPath}/package.json`,
|
|
52
|
+
destination: packageJsonLocation,
|
|
53
|
+
mergeFn: addBuildCommand,
|
|
54
|
+
});
|
|
55
|
+
yield Promise.all([writeAppManifest, copyBuildFile, writeBuildCommand]);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error(e);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.cloneDeliveryFunction = cloneDeliveryFunction;
|
package/lib/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const constants_1 = require("./constants");
|
|
|
28
28
|
const getTemplateSource_1 = require("./getTemplateSource");
|
|
29
29
|
const analytics_1 = require("./analytics");
|
|
30
30
|
const includeAppAction_1 = require("./includeAppAction");
|
|
31
|
+
const includeDeliveryFunction_1 = require("./includeDeliveryFunction");
|
|
31
32
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
32
33
|
function successMessage(folder, useYarn) {
|
|
33
34
|
console.log(`
|
|
@@ -108,7 +109,12 @@ function initProject(appName, options) {
|
|
|
108
109
|
});
|
|
109
110
|
yield (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
|
|
110
111
|
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
|
|
111
|
-
(0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.typescript);
|
|
112
|
+
yield (0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.typescript);
|
|
113
|
+
}
|
|
114
|
+
if (!isInteractive &&
|
|
115
|
+
(0, utils_1.isContentfulTemplate)(templateSource) &&
|
|
116
|
+
normalizedOptions.deliveryFunction) {
|
|
117
|
+
yield (0, includeDeliveryFunction_1.cloneDeliveryFunction)(fullAppFolder, !!normalizedOptions.typescript);
|
|
112
118
|
}
|
|
113
119
|
updatePackageName(fullAppFolder);
|
|
114
120
|
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
@@ -154,6 +160,7 @@ function initProject(appName, options) {
|
|
|
154
160
|
`format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
|
|
155
161
|
].join('\n'))
|
|
156
162
|
.option('-a, --action', 'include a hosted app action in the ts or js template')
|
|
163
|
+
.option('-d, --delivery-function', 'include a hosted delivery function template (EAP only, contact monet@contentful.com if interested)')
|
|
157
164
|
.action(initProject);
|
|
158
165
|
yield commander_1.program.parseAsync();
|
|
159
166
|
});
|
package/lib/template.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -16,7 +39,7 @@ exports.cloneTemplateIn = void 0;
|
|
|
16
39
|
const path_1 = require("path");
|
|
17
40
|
const fs_1 = require("fs");
|
|
18
41
|
const degit_1 = __importDefault(require("degit"));
|
|
19
|
-
const
|
|
42
|
+
const rimraf = __importStar(require("rimraf"));
|
|
20
43
|
const logger_1 = require("./logger");
|
|
21
44
|
const utils_1 = require("./utils");
|
|
22
45
|
function clone(source, destination) {
|
|
@@ -62,7 +85,7 @@ function cloneTemplateIn(destination, source) {
|
|
|
62
85
|
}
|
|
63
86
|
catch (e) {
|
|
64
87
|
// cleanup in case of invalid example
|
|
65
|
-
|
|
88
|
+
rimraf.sync(destination);
|
|
66
89
|
throw e;
|
|
67
90
|
}
|
|
68
91
|
cleanUp(destination);
|
|
@@ -0,0 +1,46 @@
|
|
|
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.exists = exports.mergeJsonIntoFile = exports.getJsonData = void 0;
|
|
16
|
+
const merge_options_1 = __importDefault(require("merge-options"));
|
|
17
|
+
const promises_1 = require("fs/promises");
|
|
18
|
+
const path_1 = require("path");
|
|
19
|
+
function getJsonData(path) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
if (!path) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const normalizedPath = (0, path_1.resolve)(path);
|
|
25
|
+
if (!(yield exists(normalizedPath))) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return JSON.parse(yield (0, promises_1.readFile)(normalizedPath, { encoding: 'utf-8' }));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.getJsonData = getJsonData;
|
|
32
|
+
function mergeJsonIntoFile({ source, destination, mergeFn = merge_options_1.default.bind({ concatArrays: false }), }) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const sourceJson = yield getJsonData(source);
|
|
35
|
+
const destinationJson = yield getJsonData(destination);
|
|
36
|
+
const mergedJson = mergeFn(destinationJson, sourceJson);
|
|
37
|
+
yield (0, promises_1.writeFile)((0, path_1.resolve)(destination), JSON.stringify(mergedJson, null, ' '));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.mergeJsonIntoFile = mergeJsonIntoFile;
|
|
41
|
+
function exists(path) {
|
|
42
|
+
return (0, promises_1.access)(path)
|
|
43
|
+
.then(() => true)
|
|
44
|
+
.catch(() => false);
|
|
45
|
+
}
|
|
46
|
+
exports.exists = exists;
|
|
@@ -0,0 +1,24 @@
|
|
|
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.getAddBuildCommandFn = void 0;
|
|
7
|
+
const merge_options_1 = __importDefault(require("merge-options"));
|
|
8
|
+
function getAddBuildCommandFn({ name, command }) {
|
|
9
|
+
return (packageJson, additionalProperties) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
let buildCommand = (_b = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.scripts) === null || _a === void 0 ? void 0 : _a.build) !== null && _b !== void 0 ? _b : '';
|
|
12
|
+
const triggerCommand = `npm run ${name}`;
|
|
13
|
+
if (buildCommand === '') {
|
|
14
|
+
buildCommand = triggerCommand;
|
|
15
|
+
}
|
|
16
|
+
else if (!buildCommand.split(/\s*&+\s*/).includes(triggerCommand)) {
|
|
17
|
+
buildCommand += ` && ${triggerCommand}`;
|
|
18
|
+
}
|
|
19
|
+
return (0, merge_options_1.default)({}, packageJson, additionalProperties, {
|
|
20
|
+
scripts: { [name]: command, build: buildCommand },
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.getAddBuildCommandFn = getAddBuildCommandFn;
|
package/lib/utils.js
CHANGED
|
@@ -56,12 +56,14 @@ function normalizeOptions(options) {
|
|
|
56
56
|
delete normalizedOptions.typescript;
|
|
57
57
|
delete normalizedOptions.javascript;
|
|
58
58
|
delete normalizedOptions.action;
|
|
59
|
+
delete normalizedOptions.deliveryFunction;
|
|
59
60
|
}
|
|
60
61
|
if (normalizedOptions.example) {
|
|
61
62
|
fallbackOption = '--example';
|
|
62
63
|
delete normalizedOptions.typescript;
|
|
63
64
|
delete normalizedOptions.javascript;
|
|
64
65
|
delete normalizedOptions.action;
|
|
66
|
+
delete normalizedOptions.deliveryFunction;
|
|
65
67
|
}
|
|
66
68
|
if (normalizedOptions.typescript) {
|
|
67
69
|
fallbackOption = '--typescript';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -32,15 +32,17 @@
|
|
|
32
32
|
"lint": "eslint ./src",
|
|
33
33
|
"lint:fix": "npm run lint -- --fix",
|
|
34
34
|
"pre-commit": "lint-staged",
|
|
35
|
-
"build": "tsc"
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"test": "mocha 'test/**/*.spec.{js,ts}'"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@contentful/app-scripts": "1.
|
|
39
|
+
"@contentful/app-scripts": "1.12.0",
|
|
39
40
|
"analytics-node": "^6.2.0",
|
|
40
41
|
"chalk": "4.1.2",
|
|
41
|
-
"commander": "
|
|
42
|
+
"commander": "11.0.0",
|
|
42
43
|
"degit": "2.8.4",
|
|
43
|
-
"inquirer": "8.2.
|
|
44
|
+
"inquirer": "8.2.6",
|
|
45
|
+
"merge-options": "^3.0.4",
|
|
44
46
|
"node-fetch": "2.6.7",
|
|
45
47
|
"rimraf": "5.0.1",
|
|
46
48
|
"tildify": "2.0.0",
|
|
@@ -57,17 +59,27 @@
|
|
|
57
59
|
"access": "public"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
|
-
"@tsconfig/node16": "1.
|
|
62
|
+
"@tsconfig/node16": "16.1.1",
|
|
61
63
|
"@types/analytics-node": "^3.1.9",
|
|
64
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
62
65
|
"@types/chalk": "2.2.0",
|
|
63
66
|
"@types/degit": "2.8.3",
|
|
64
67
|
"@types/inquirer": "8.2.1",
|
|
65
|
-
"@types/
|
|
68
|
+
"@types/mocha": "^10.0.1",
|
|
69
|
+
"@types/node": "14.18.55",
|
|
66
70
|
"@types/node-fetch": "^2.6.2",
|
|
67
71
|
"@types/rimraf": "3.0.2",
|
|
72
|
+
"@types/sinon": "^10.0.16",
|
|
73
|
+
"@types/sinon-chai": "^3.2.9",
|
|
68
74
|
"@types/tildify": "2.0.2",
|
|
69
75
|
"@types/validate-npm-package-name": "4.0.0",
|
|
70
|
-
"
|
|
76
|
+
"chai": "^4.3.7",
|
|
77
|
+
"chai-as-promised": "^7.1.1",
|
|
78
|
+
"contentful-management": "10.40.0",
|
|
79
|
+
"mocha": "^10.2.0",
|
|
80
|
+
"sinon": "^15.2.0",
|
|
81
|
+
"sinon-chai": "^3.7.0",
|
|
82
|
+
"ts-node": "^10.9.1"
|
|
71
83
|
},
|
|
72
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "e6ee977c9fc8db111bcd36c8caa1550f4829afb6"
|
|
73
85
|
}
|