@contentful/create-contentful-app 1.3.78 → 1.4.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/index.js +7 -4
- package/lib/logger.js +7 -1
- package/lib/template.js +81 -13
- package/lib/utils.js +0 -3
- package/package.json +5 -3
package/lib/index.js
CHANGED
|
@@ -23,12 +23,13 @@ const tildify_1 = __importDefault(require("tildify"));
|
|
|
23
23
|
const template_1 = require("./template");
|
|
24
24
|
const utils_1 = require("./utils");
|
|
25
25
|
const logger_1 = require("./logger");
|
|
26
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
26
27
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
27
28
|
function successMessage(folder) {
|
|
28
29
|
console.log(`
|
|
29
|
-
${(0, logger_1.success)('Success!')} Created a new Contentful app in ${(0, logger_1.highlight)((0, tildify_1.default)(folder))}
|
|
30
|
-
|
|
31
|
-
Now kick it off by running
|
|
30
|
+
${(0, logger_1.success)('Success!')} Created a new Contentful app in ${(0, logger_1.highlight)((0, tildify_1.default)(folder))}.`);
|
|
31
|
+
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)('---- Next Steps'));
|
|
32
|
+
console.log(`Now kick it off by running
|
|
32
33
|
|
|
33
34
|
${(0, logger_1.code)(`cd ${(0, tildify_1.default)(folder)}`)}
|
|
34
35
|
${(0, logger_1.code)(`npm start`)}
|
|
@@ -85,7 +86,9 @@ function initProject(appName, options) {
|
|
|
85
86
|
console.log(`Creating a Contentful app in ${(0, logger_1.highlight)((0, tildify_1.default)(fullAppFolder))}.`);
|
|
86
87
|
yield (0, template_1.cloneTemplateIn)(fullAppFolder, normalizedOptions);
|
|
87
88
|
updatePackageName(fullAppFolder);
|
|
88
|
-
|
|
89
|
+
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
90
|
+
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Installing the dependencies for your app (Using ${chalk_1.default.cyan(useYarn ? 'yarn' : 'npm')})...`));
|
|
91
|
+
if (useYarn) {
|
|
89
92
|
yield (0, utils_1.exec)('yarn', [], { cwd: fullAppFolder });
|
|
90
93
|
}
|
|
91
94
|
else {
|
package/lib/logger.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.code = exports.success = exports.choice = exports.highlight = exports.error = exports.warn = void 0;
|
|
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
8
|
function warn(message) {
|
|
9
9
|
console.log(`${chalk_1.default.yellow('Warning:')} ${message}`);
|
|
@@ -25,6 +25,12 @@ function error(message, error) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.error = error;
|
|
28
|
+
function wrapInBlanks(message) {
|
|
29
|
+
console.log(' ');
|
|
30
|
+
console.log(message);
|
|
31
|
+
console.log(' ');
|
|
32
|
+
}
|
|
33
|
+
exports.wrapInBlanks = wrapInBlanks;
|
|
28
34
|
function highlight(str) {
|
|
29
35
|
return chalk_1.default.bold(str);
|
|
30
36
|
}
|
package/lib/template.js
CHANGED
|
@@ -20,26 +20,93 @@ const rimraf_1 = __importDefault(require("rimraf"));
|
|
|
20
20
|
const types_1 = require("./types");
|
|
21
21
|
const logger_1 = require("./logger");
|
|
22
22
|
const utils_1 = require("./utils");
|
|
23
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
24
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
25
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
23
26
|
const EXAMPLES_PATH = 'contentful/apps/examples/';
|
|
24
27
|
function isContentfulTemplate(url) {
|
|
25
28
|
return Object.values(types_1.ContentfulExample).some((t) => url.includes(EXAMPLES_PATH + t));
|
|
26
29
|
}
|
|
30
|
+
function getGithubFolderNames(username, repo, path) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const url = `https://api.github.com/repos/${username}/${repo}/contents/${path}`;
|
|
33
|
+
const response = yield (0, node_fetch_1.default)(url);
|
|
34
|
+
const contents = yield response.json();
|
|
35
|
+
return contents.filter((content) => content.type === "dir")
|
|
36
|
+
.map((content) => content.name);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function promptExampleSelection() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
let template = 'typescript';
|
|
42
|
+
// ask user whether to start with a blank template or use an example template
|
|
43
|
+
const { starter } = yield inquirer_1.default.prompt([
|
|
44
|
+
{
|
|
45
|
+
name: 'starter',
|
|
46
|
+
message: 'Do you want to start with an example template or use one of the blank templates?',
|
|
47
|
+
type: 'list',
|
|
48
|
+
choices: ['blank', 'example'],
|
|
49
|
+
default: 'blank',
|
|
50
|
+
},
|
|
51
|
+
]);
|
|
52
|
+
// if the user chose to use an blank template, ask which language they prefer
|
|
53
|
+
if (starter === "blank") {
|
|
54
|
+
const { language } = yield inquirer_1.default.prompt([
|
|
55
|
+
{
|
|
56
|
+
name: 'language',
|
|
57
|
+
message: 'Do you prefer Typescript or Javascript',
|
|
58
|
+
type: 'list',
|
|
59
|
+
choices: ['typescript', 'javascript'],
|
|
60
|
+
default: 'typescript',
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
template = language;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// get available templates from examples
|
|
67
|
+
const availableTemplates = yield getGithubFolderNames("contentful", "apps", "examples");
|
|
68
|
+
// ask user to select a template from the available examples
|
|
69
|
+
const { example } = yield inquirer_1.default.prompt([
|
|
70
|
+
{
|
|
71
|
+
name: 'example',
|
|
72
|
+
message: 'Select a template',
|
|
73
|
+
type: 'list',
|
|
74
|
+
choices: availableTemplates,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
template = example;
|
|
78
|
+
}
|
|
79
|
+
// return the selected template
|
|
80
|
+
return selectTemplate(template);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function selectTemplate(template) {
|
|
84
|
+
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Cloning the ${chalk_1.default.cyan(template)} template...`));
|
|
85
|
+
return EXAMPLES_PATH + template;
|
|
86
|
+
}
|
|
27
87
|
function makeContentfulExampleSource(options) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
if (options.example) {
|
|
90
|
+
return selectTemplate(options.example);
|
|
91
|
+
}
|
|
92
|
+
if (options.javascript) {
|
|
93
|
+
return selectTemplate(types_1.ContentfulExample.Javascript);
|
|
94
|
+
}
|
|
95
|
+
if (options.typescript) {
|
|
96
|
+
return selectTemplate(types_1.ContentfulExample.Typescript);
|
|
97
|
+
}
|
|
98
|
+
return yield promptExampleSelection();
|
|
99
|
+
});
|
|
35
100
|
}
|
|
36
101
|
function getTemplateSource(options) {
|
|
37
102
|
var _a;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
|
|
42
|
-
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const source = (_a = options.source) !== null && _a !== void 0 ? _a : yield makeContentfulExampleSource(options);
|
|
105
|
+
if (options.source && !isContentfulTemplate(source)) {
|
|
106
|
+
(0, logger_1.warn)(`Template at ${(0, logger_1.highlight)(source)} is not an official Contentful app template!`);
|
|
107
|
+
}
|
|
108
|
+
return source;
|
|
109
|
+
});
|
|
43
110
|
}
|
|
44
111
|
function clone(source, destination) {
|
|
45
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -77,8 +144,9 @@ function cleanUp(destination) {
|
|
|
77
144
|
}
|
|
78
145
|
function cloneTemplateIn(destination, options) {
|
|
79
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const source = getTemplateSource(options);
|
|
147
|
+
const source = yield getTemplateSource(options);
|
|
81
148
|
yield clone(source, destination);
|
|
149
|
+
console.log((0, logger_1.success)('Done!'));
|
|
82
150
|
try {
|
|
83
151
|
validate(destination);
|
|
84
152
|
}
|
package/lib/utils.js
CHANGED
|
@@ -63,9 +63,6 @@ function normalizeOptions(options) {
|
|
|
63
63
|
fallbackOption = '--typescript';
|
|
64
64
|
delete normalizedOptions.javascript;
|
|
65
65
|
}
|
|
66
|
-
if (!normalizedOptions.javascript) {
|
|
67
|
-
normalizedOptions.typescript = true;
|
|
68
|
-
}
|
|
69
66
|
if (currentMutuallyExclusiveOptions.length > 1) {
|
|
70
67
|
(0, logger_1.warn)(`Options ${(0, logger_1.highlight)('--source')}, ${(0, logger_1.highlight)('--example')}, ${(0, logger_1.highlight)('--typescript')} and ${(0, logger_1.highlight)('--javascript')} are mutually exclusive, using ${(0, logger_1.choice)(fallbackOption)}.`);
|
|
71
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -35,11 +35,12 @@
|
|
|
35
35
|
"build": "tsc"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@contentful/app-scripts": "1.5.
|
|
38
|
+
"@contentful/app-scripts": "1.5.5",
|
|
39
39
|
"chalk": "4.1.2",
|
|
40
40
|
"commander": "9.4.1",
|
|
41
41
|
"degit": "2.8.4",
|
|
42
42
|
"inquirer": "8.2.5",
|
|
43
|
+
"node-fetch": "2.6.7",
|
|
43
44
|
"rimraf": "3.0.2",
|
|
44
45
|
"tildify": "2.0.0",
|
|
45
46
|
"validate-npm-package-name": "5.0.0"
|
|
@@ -60,9 +61,10 @@
|
|
|
60
61
|
"@types/degit": "2.8.3",
|
|
61
62
|
"@types/inquirer": "8.2.1",
|
|
62
63
|
"@types/node": "14.18.35",
|
|
64
|
+
"@types/node-fetch": "^2.6.2",
|
|
63
65
|
"@types/rimraf": "3.0.2",
|
|
64
66
|
"@types/tildify": "2.0.2",
|
|
65
67
|
"@types/validate-npm-package-name": "4.0.0"
|
|
66
68
|
},
|
|
67
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "00e9dff6579274c1cb492e329161cc7bac8445e0"
|
|
68
70
|
}
|