@contentful/create-contentful-app 1.17.3 → 1.17.4
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/constants.js +2 -0
- package/lib/getGithubFolderNames.js +30 -0
- package/lib/getTemplateSource.js +16 -13
- package/lib/includeFunction.js +14 -10
- package/lib/index.js +1 -1
- package/lib/logger.js +6 -0
- package/lib/template.js +1 -1
- package/lib/types.js +7 -1
- package/package.json +3 -3
package/lib/constants.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IGNORED_CLONED_FILES = exports.CONTENTFUL_APP_MANIFEST = exports.EXAMPLES_PATH = exports.IGNORED_EXAMPLE_FOLDERS = 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
|
+
// These are the examples that are listed as templates instead of examples
|
|
7
|
+
// OR should otherwise not be included in the list of examples displayed in the interactive mode
|
|
6
8
|
exports.IGNORED_EXAMPLE_FOLDERS = [
|
|
7
9
|
'javascript',
|
|
8
10
|
'typescript',
|
|
@@ -0,0 +1,30 @@
|
|
|
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.getGithubFolderNames = exports.CONTENTFUL_APPS_EXAMPLE_FOLDER = void 0;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
exports.CONTENTFUL_APPS_EXAMPLE_FOLDER = 'https://api.github.com/repos/contentful/apps/contents/examples';
|
|
11
|
+
async function getGithubFolderNames() {
|
|
12
|
+
try {
|
|
13
|
+
const response = await (0, node_fetch_1.default)(exports.CONTENTFUL_APPS_EXAMPLE_FOLDER);
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
throw new types_1.HTTPResponseError(`${chalk_1.default.red('Error:')} Failed to fetch Contentful app templates: ${response.status} ${response.statusText}`);
|
|
16
|
+
}
|
|
17
|
+
const contents = await response.json();
|
|
18
|
+
const filteredContents = contents.filter((content) => content.type === 'dir');
|
|
19
|
+
return filteredContents.map((content) => content.name);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
if (err instanceof types_1.HTTPResponseError) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`Failed to fetch Contentful app templates: ${err}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.getGithubFolderNames = getGithubFolderNames;
|
package/lib/getTemplateSource.js
CHANGED
|
@@ -3,22 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getTemplateSource = void 0;
|
|
7
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
6
|
+
exports.getTemplateSource = exports.makeContentfulExampleSource = void 0;
|
|
8
7
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
9
|
const types_1 = require("./types");
|
|
11
10
|
const logger_1 = require("./logger");
|
|
12
11
|
const constants_1 = require("./constants");
|
|
13
12
|
const utils_1 = require("./utils");
|
|
14
|
-
const
|
|
15
|
-
async function getGithubFolderNames() {
|
|
16
|
-
const response = await (0, node_fetch_1.default)(CONTENTFUL_APPS_EXAMPLE_FOLDER);
|
|
17
|
-
const contents = await response.json();
|
|
18
|
-
return contents
|
|
19
|
-
.filter((content) => content.type === 'dir' && !constants_1.IGNORED_EXAMPLE_FOLDERS.includes(content.name))
|
|
20
|
-
.map((content) => content.name);
|
|
21
|
-
}
|
|
13
|
+
const getGithubFolderNames_1 = require("./getGithubFolderNames");
|
|
22
14
|
async function promptExampleSelection() {
|
|
23
15
|
let template = 'typescript';
|
|
24
16
|
// ask user whether to start with a blank template or use an example
|
|
@@ -55,14 +47,17 @@ async function promptExampleSelection() {
|
|
|
55
47
|
}
|
|
56
48
|
else {
|
|
57
49
|
// get available templates from examples
|
|
58
|
-
const availableTemplates = await getGithubFolderNames();
|
|
50
|
+
const availableTemplates = await (0, getGithubFolderNames_1.getGithubFolderNames)();
|
|
51
|
+
// filter out the ignored ones that are listed as templates instead of examples
|
|
52
|
+
const filteredTemplates = availableTemplates.filter((template) => !constants_1.IGNORED_EXAMPLE_FOLDERS.includes(template));
|
|
53
|
+
console.log(availableTemplates.length, filteredTemplates.length);
|
|
59
54
|
// ask user to select a template from the available examples
|
|
60
55
|
const { example } = await inquirer_1.default.prompt([
|
|
61
56
|
{
|
|
62
57
|
name: 'example',
|
|
63
58
|
message: 'Select a template',
|
|
64
59
|
type: 'list',
|
|
65
|
-
choices:
|
|
60
|
+
choices: filteredTemplates,
|
|
66
61
|
},
|
|
67
62
|
]);
|
|
68
63
|
template = example;
|
|
@@ -76,7 +71,14 @@ function selectTemplate(template) {
|
|
|
76
71
|
}
|
|
77
72
|
async function makeContentfulExampleSource(options) {
|
|
78
73
|
if (options.example) {
|
|
79
|
-
|
|
74
|
+
// check to see if the example is valid
|
|
75
|
+
const availableTemplates = await (0, getGithubFolderNames_1.getGithubFolderNames)();
|
|
76
|
+
const isValidContentfulExample = availableTemplates.includes(options.example);
|
|
77
|
+
if (!isValidContentfulExample) {
|
|
78
|
+
throw new types_1.InvalidTemplateError(`${chalk_1.default.red(`Invalid template:`)} The example name ${(0, logger_1.highlight)(chalk_1.default.cyan(options.example))} is not valid. Please use one of Contentful's public example apps from ${(0, logger_1.highlight)(`https://github.com/contentful/apps/tree/master/examples`)}. Use the ${(0, logger_1.code)(`--example`)} option followed by the example name.`);
|
|
79
|
+
}
|
|
80
|
+
const templateSource = selectTemplate(options.example);
|
|
81
|
+
return templateSource;
|
|
80
82
|
}
|
|
81
83
|
if (options.javascript) {
|
|
82
84
|
return selectTemplate(types_1.ContentfulExample.Javascript);
|
|
@@ -89,6 +91,7 @@ async function makeContentfulExampleSource(options) {
|
|
|
89
91
|
}
|
|
90
92
|
return await promptExampleSelection();
|
|
91
93
|
}
|
|
94
|
+
exports.makeContentfulExampleSource = makeContentfulExampleSource;
|
|
92
95
|
async function getTemplateSource(options) {
|
|
93
96
|
const source = options.source ?? (await makeContentfulExampleSource(options));
|
|
94
97
|
if (options.source && !(0, utils_1.isContentfulTemplate)(source)) {
|
package/lib/includeFunction.js
CHANGED
|
@@ -3,11 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.cloneFunction = void 0;
|
|
6
|
+
exports.cloneFunction = exports.functionTemplateFromName = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
8
|
const path_1 = require("path");
|
|
8
|
-
const
|
|
9
|
+
const rimraf_1 = require("rimraf");
|
|
9
10
|
const tiged_1 = __importDefault(require("tiged"));
|
|
11
|
+
const constants_1 = require("./constants");
|
|
10
12
|
const logger_1 = require("./logger");
|
|
13
|
+
const types_1 = require("./types");
|
|
11
14
|
const file_1 = require("./utils/file");
|
|
12
15
|
const package_1 = require("./utils/package");
|
|
13
16
|
// TODO: after appActions work we can change this getAddBuildCommandFn params from command -> defaultCommand as examples will have build commands
|
|
@@ -22,21 +25,23 @@ const VALID_FUNCTION_TEMPLATES_DIRS = [
|
|
|
22
25
|
'external-references',
|
|
23
26
|
'comment-bot',
|
|
24
27
|
];
|
|
25
|
-
function functionTemplateFromName(functionName) {
|
|
28
|
+
function functionTemplateFromName(functionName, destination) {
|
|
26
29
|
let dirName = functionName;
|
|
27
30
|
if (!VALID_FUNCTION_TEMPLATES_DIRS.includes(dirName)) {
|
|
28
|
-
|
|
29
|
-
|
|
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(', '))}.`);
|
|
30
34
|
}
|
|
31
35
|
if (functionName === 'external-references')
|
|
32
36
|
dirName = 'templates'; // backwards compatible for the apps repo examples folder for delivery functions (external-references)
|
|
33
37
|
return dirName;
|
|
34
38
|
}
|
|
39
|
+
exports.functionTemplateFromName = functionTemplateFromName;
|
|
35
40
|
async function cloneFunction(destination, templateIsJavascript, functionName) {
|
|
36
41
|
try {
|
|
37
|
-
console.log((0, logger_1.highlight)(`---- Cloning function
|
|
42
|
+
console.log((0, logger_1.highlight)(`---- Cloning function ${chalk_1.default.cyan(functionName)}...`));
|
|
38
43
|
// Clone the function template to the created directory under the folder 'actions'
|
|
39
|
-
const templateSource = (0, path_1.join)(`contentful/apps/examples/function-${functionTemplateFromName(functionName)}`, templateIsJavascript ? 'javascript' : 'typescript');
|
|
44
|
+
const templateSource = (0, path_1.join)(`contentful/apps/examples/function-${functionTemplateFromName(functionName, destination)}`, templateIsJavascript ? 'javascript' : 'typescript');
|
|
40
45
|
const functionDirectoryPath = (0, path_1.resolve)(`${destination}/functions`);
|
|
41
46
|
const d = (0, tiged_1.default)(templateSource, { mode: 'tar', disableCache: true });
|
|
42
47
|
await d.clone(functionDirectoryPath);
|
|
@@ -49,8 +54,7 @@ async function cloneFunction(destination, templateIsJavascript, functionName) {
|
|
|
49
54
|
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
|
|
50
55
|
const packageJsonExists = await (0, file_1.exists)(packageJsonLocation);
|
|
51
56
|
if (!packageJsonExists) {
|
|
52
|
-
|
|
53
|
-
return;
|
|
57
|
+
throw new Error(`Failed to add function build commands: ${packageJsonLocation} does not exist.`);
|
|
54
58
|
}
|
|
55
59
|
const writeBuildCommand = (0, file_1.mergeJsonIntoFile)({
|
|
56
60
|
source: `${functionDirectoryPath}/package.json`,
|
|
@@ -64,7 +68,7 @@ async function cloneFunction(destination, templateIsJavascript, functionName) {
|
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
catch (e) {
|
|
67
|
-
|
|
71
|
+
(0, logger_1.error)(`Failed to clone function ${(0, logger_1.highlight)(chalk_1.default.cyan(functionName))}`, e);
|
|
68
72
|
process.exit(1);
|
|
69
73
|
}
|
|
70
74
|
}
|
package/lib/index.js
CHANGED
|
@@ -119,7 +119,7 @@ async function initProject(appName, options) {
|
|
|
119
119
|
successMessage(fullAppFolder, useYarn);
|
|
120
120
|
}
|
|
121
121
|
catch (err) {
|
|
122
|
-
(0, logger_1.error)(`Failed to create ${appName}`, err);
|
|
122
|
+
(0, logger_1.error)(`Failed to create ${(0, logger_1.highlight)(chalk_1.default.cyan(appName))}`, err);
|
|
123
123
|
process.exit(1);
|
|
124
124
|
}
|
|
125
125
|
}
|
package/lib/logger.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.code = exports.success = exports.choice = exports.highlight = exports.wrapInBlanks = exports.error = exports.warn = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const types_1 = require("./types");
|
|
8
9
|
function warn(message) {
|
|
9
10
|
console.log(`${chalk_1.default.yellow('Warning:')} ${message}`);
|
|
10
11
|
}
|
|
@@ -14,6 +15,11 @@ function error(message, error) {
|
|
|
14
15
|
if (error === undefined) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
18
|
+
else if (error instanceof types_1.InvalidTemplateError || error instanceof types_1.HTTPResponseError) {
|
|
19
|
+
// for known errors, we just want to show the message
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(error.message);
|
|
22
|
+
}
|
|
17
23
|
else if (error instanceof Error) {
|
|
18
24
|
console.log();
|
|
19
25
|
console.log(error);
|
package/lib/template.js
CHANGED
|
@@ -67,7 +67,6 @@ function cleanUp(destination) {
|
|
|
67
67
|
}
|
|
68
68
|
async function cloneTemplateIn(destination, source) {
|
|
69
69
|
await clone(source, destination);
|
|
70
|
-
console.log((0, logger_1.success)('Done!'));
|
|
71
70
|
try {
|
|
72
71
|
validate(destination);
|
|
73
72
|
}
|
|
@@ -77,5 +76,6 @@ async function cloneTemplateIn(destination, source) {
|
|
|
77
76
|
throw e;
|
|
78
77
|
}
|
|
79
78
|
cleanUp(destination);
|
|
79
|
+
console.log((0, logger_1.success)('Done!'));
|
|
80
80
|
}
|
|
81
81
|
exports.cloneTemplateIn = cloneTemplateIn;
|
package/lib/types.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContentfulExample = void 0;
|
|
3
|
+
exports.HTTPResponseError = exports.InvalidTemplateError = exports.ContentfulExample = void 0;
|
|
4
4
|
exports.ContentfulExample = {
|
|
5
5
|
Javascript: 'javascript',
|
|
6
6
|
Typescript: 'typescript',
|
|
7
7
|
};
|
|
8
|
+
class InvalidTemplateError extends Error {
|
|
9
|
+
}
|
|
10
|
+
exports.InvalidTemplateError = InvalidTemplateError;
|
|
11
|
+
class HTTPResponseError extends Error {
|
|
12
|
+
}
|
|
13
|
+
exports.HTTPResponseError = HTTPResponseError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.4",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
"@types/validate-npm-package-name": "4.0.2",
|
|
75
75
|
"chai": "^4.3.7",
|
|
76
76
|
"chai-as-promised": "^7.1.1",
|
|
77
|
-
"contentful-management": "11.40.
|
|
77
|
+
"contentful-management": "11.40.3",
|
|
78
78
|
"mocha": "^10.2.0",
|
|
79
79
|
"sinon": "^19.0.0",
|
|
80
80
|
"sinon-chai": "^3.7.0",
|
|
81
81
|
"ts-node": "^10.9.2"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "dce83a3e18571b2f0550c3a447d07fffb1145155"
|
|
84
84
|
}
|