@contentful/create-contentful-app 2.1.6 → 2.1.7
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 +1 -0
- package/lib/index.js +45 -25
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -96,6 +96,7 @@ Options:
|
|
|
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
98
|
-f, --function <function-template-name> include the specified function template
|
|
99
|
+
--skip-ui use with --function to clone the template without a user interface (UI).
|
|
99
100
|
-h, --help shows all available CLI options
|
|
100
101
|
```
|
|
101
102
|
|
package/lib/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const constants_1 = require("./constants");
|
|
|
19
19
|
const getTemplateSource_1 = require("./getTemplateSource");
|
|
20
20
|
const analytics_1 = require("./analytics");
|
|
21
21
|
const app_scripts_1 = require("@contentful/app-scripts");
|
|
22
|
+
const fs_2 = __importDefault(require("fs"));
|
|
22
23
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
23
24
|
function successMessage(folder, useYarn) {
|
|
24
25
|
console.log(`
|
|
@@ -82,6 +83,28 @@ async function initProject(appName, options) {
|
|
|
82
83
|
appName = await validateAppName(appName);
|
|
83
84
|
const fullAppFolder = (0, path_1.resolve)(process.cwd(), appName);
|
|
84
85
|
console.log(`Creating a Contentful app in ${(0, logger_1.highlight)((0, tildify_1.default)(fullAppFolder))}.`);
|
|
86
|
+
if (normalizedOptions.function && normalizedOptions.skipUi) {
|
|
87
|
+
await addFunctionTemplate(fullAppFolder);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
await addAppExample(fullAppFolder);
|
|
91
|
+
}
|
|
92
|
+
updatePackageName(fullAppFolder);
|
|
93
|
+
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
94
|
+
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Installing the dependencies for your app (using ${chalk_1.default.cyan(useYarn ? 'yarn' : 'npm')})...`));
|
|
95
|
+
if (useYarn) {
|
|
96
|
+
await (0, utils_1.exec)('yarn', [], { cwd: fullAppFolder });
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
await (0, utils_1.exec)('npm', ['install', '--no-audit', '--no-fund'], { cwd: fullAppFolder });
|
|
100
|
+
}
|
|
101
|
+
successMessage(fullAppFolder, useYarn);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
(0, logger_1.error)(`Failed to create ${(0, logger_1.highlight)(chalk_1.default.cyan(appName))}`, err);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
async function addAppExample(fullAppFolder) {
|
|
85
108
|
const isInteractive = !normalizedOptions.example &&
|
|
86
109
|
!normalizedOptions.source &&
|
|
87
110
|
!normalizedOptions.javascript &&
|
|
@@ -100,36 +123,32 @@ async function initProject(appName, options) {
|
|
|
100
123
|
if (normalizedOptions.function === true) {
|
|
101
124
|
normalizedOptions.function = 'external-references';
|
|
102
125
|
}
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
await addFunctionTemplate(fullAppFolder);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function addFunctionTemplate(fullAppFolder) {
|
|
130
|
+
if (!fs_2.default.existsSync(fullAppFolder)) {
|
|
131
|
+
fs_2.default.mkdirSync(fullAppFolder, { recursive: true });
|
|
132
|
+
}
|
|
133
|
+
process.chdir(fullAppFolder);
|
|
134
|
+
(0, logger_1.wrapInBlanks)(`To add additional function templates to your app, use ${(0, logger_1.highlight)(chalk_1.default.green(`
|
|
105
135
|
npx @contentful/app-scripts@latest generate-function \\
|
|
106
136
|
--ci \\
|
|
107
|
-
--name <
|
|
137
|
+
--name <n> \\
|
|
108
138
|
--example <example> \\
|
|
109
139
|
--language <typescript/javascript>`))}`);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
|
|
113
|
-
await app_scripts_1.generateFunction.nonInteractive({
|
|
114
|
-
example: normalizedOptions.function,
|
|
115
|
-
language: normalizedOptions.javascript ? 'javascript' : 'typescript',
|
|
116
|
-
name: functionName,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
updatePackageName(fullAppFolder);
|
|
120
|
-
const useYarn = normalizedOptions.yarn || (0, utils_1.detectManager)() === 'yarn';
|
|
121
|
-
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Installing the dependencies for your app (using ${chalk_1.default.cyan(useYarn ? 'yarn' : 'npm')})...`));
|
|
122
|
-
if (useYarn) {
|
|
123
|
-
await (0, utils_1.exec)('yarn', [], { cwd: fullAppFolder });
|
|
140
|
+
if (typeof normalizedOptions.function !== 'string') {
|
|
141
|
+
throw new Error('Function template name is required');
|
|
124
142
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
const functionName = normalizedOptions.function
|
|
144
|
+
.toLowerCase()
|
|
145
|
+
.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
|
|
146
|
+
await app_scripts_1.generateFunction.nonInteractive({
|
|
147
|
+
example: normalizedOptions.function,
|
|
148
|
+
language: normalizedOptions.javascript ? 'javascript' : 'typescript',
|
|
149
|
+
name: functionName,
|
|
150
|
+
keepPackageJson: normalizedOptions.skipUi === true
|
|
151
|
+
});
|
|
133
152
|
}
|
|
134
153
|
}
|
|
135
154
|
(async function main() {
|
|
@@ -158,6 +177,7 @@ async function initProject(appName, options) {
|
|
|
158
177
|
`format: URL (HTTPS or SSH) or ${(0, logger_1.code)('vendor:user/repo')} (e.g., ${(0, logger_1.code)('github:user/repo')})`,
|
|
159
178
|
].join('\n'))
|
|
160
179
|
.option('-f, --function [function-template-name]', 'include the specified function template')
|
|
180
|
+
.option('--skip-ui', 'use with --function to clone the template without a user interface (UI).')
|
|
161
181
|
.action(initProject);
|
|
162
182
|
await commander_1.program.parseAsync();
|
|
163
183
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"sinon-chai": "^3.7.0",
|
|
81
81
|
"ts-node": "^10.9.2"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "e0fd9a44412b259dd0e4345eb0f78801c29d43f3"
|
|
84
84
|
}
|