@contentful/create-contentful-app 2.1.10 → 2.2.0-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/README.md +5 -4
- package/lib/getTemplateSource.js +1 -2
- package/lib/index.js +24 -9
- package/lib/template.js +1 -0
- package/lib/utils.js +58 -8
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -30,6 +30,9 @@ npx create-contentful-app <app-name>
|
|
|
30
30
|
# npm
|
|
31
31
|
npm init contentful-app <app-name>
|
|
32
32
|
|
|
33
|
+
# pnpm
|
|
34
|
+
pnpm init contentful-app <app-name>
|
|
35
|
+
|
|
33
36
|
# Yarn
|
|
34
37
|
yarn create contentful-app <app-name>
|
|
35
38
|
```
|
|
@@ -38,11 +41,9 @@ yarn create contentful-app <app-name>
|
|
|
38
41
|
|
|
39
42
|
### Package Manager
|
|
40
43
|
|
|
41
|
-
`--npm` or `--yarn`
|
|
42
|
-
|
|
43
|
-
Use npm or Yarn to manage dependencies. If omitted, defaults to the manager used to run `create-contentful-app`.
|
|
44
|
+
`--npm` or `--pnpm` or `--yarn`
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
Use npm, pnpm, or Yarn to manage dependencies. If omitted, or if more than one flag is passed, will default to the manager used to run `create-contentful-app`.
|
|
46
47
|
|
|
47
48
|
### Template
|
|
48
49
|
|
package/lib/getTemplateSource.js
CHANGED
|
@@ -49,8 +49,7 @@ 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
|
|
53
|
-
.filter((template) => !constants_1.IGNORED_EXAMPLE_FOLDERS.includes(template));
|
|
52
|
+
const filteredTemplates = availableTemplates.filter((template) => !constants_1.IGNORED_EXAMPLE_FOLDERS.includes(template));
|
|
54
53
|
console.log(availableTemplates.length, filteredTemplates.length);
|
|
55
54
|
// ask user to select a template from the available examples
|
|
56
55
|
const { example } = await inquirer_1.default.prompt([
|
package/lib/index.js
CHANGED
|
@@ -21,14 +21,24 @@ const analytics_1 = require("./analytics");
|
|
|
21
21
|
const app_scripts_1 = require("@contentful/app-scripts");
|
|
22
22
|
const fs_2 = __importDefault(require("fs"));
|
|
23
23
|
const DEFAULT_APP_NAME = 'contentful-app';
|
|
24
|
-
function successMessage(folder,
|
|
24
|
+
function successMessage(folder, packageManager) {
|
|
25
|
+
let command = '';
|
|
26
|
+
if (packageManager === 'yarn') {
|
|
27
|
+
command = 'yarn create-app-definition';
|
|
28
|
+
}
|
|
29
|
+
else if (packageManager === 'pnpm') {
|
|
30
|
+
command = 'pnpm create-app-definition';
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
command = 'npm run create-app-definition';
|
|
34
|
+
}
|
|
25
35
|
console.log(`
|
|
26
36
|
${(0, logger_1.success)('Success!')} Created a new Contentful app in ${(0, logger_1.highlight)((0, tildify_1.default)(folder))}.`);
|
|
27
37
|
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)('---- Next Steps'));
|
|
28
38
|
console.log(`Now create an app definition for your app by running
|
|
29
39
|
|
|
30
40
|
${(0, logger_1.code)(`cd ${(0, tildify_1.default)(folder)}`)}
|
|
31
|
-
${(0, logger_1.code)(
|
|
41
|
+
${(0, logger_1.code)(command)}
|
|
32
42
|
|
|
33
43
|
or you can create it manually in web app:
|
|
34
44
|
${(0, logger_1.highlight)(constants_1.CREATE_APP_DEFINITION_GUIDE_URL)}
|
|
@@ -36,7 +46,7 @@ ${(0, logger_1.success)('Success!')} Created a new Contentful app in ${(0, logge
|
|
|
36
46
|
console.log(`Then kick it off by running
|
|
37
47
|
|
|
38
48
|
${(0, logger_1.code)(`cd ${(0, tildify_1.default)(folder)}`)}
|
|
39
|
-
${(0, logger_1.code)(`${
|
|
49
|
+
${(0, logger_1.code)(`${packageManager} start`)}
|
|
40
50
|
`);
|
|
41
51
|
}
|
|
42
52
|
function updatePackageName(appFolder) {
|
|
@@ -79,6 +89,8 @@ async function validateAppName(appName) {
|
|
|
79
89
|
}
|
|
80
90
|
async function initProject(appName, options) {
|
|
81
91
|
const normalizedOptions = (0, utils_1.normalizeOptions)(options);
|
|
92
|
+
const activePackageManager = (0, utils_1.detectActivePackageManager)();
|
|
93
|
+
const packageManager = (0, utils_1.getNormalizedPackageManager)(normalizedOptions, activePackageManager);
|
|
82
94
|
try {
|
|
83
95
|
appName = await validateAppName(appName);
|
|
84
96
|
const fullAppFolder = (0, path_1.resolve)(process.cwd(), appName);
|
|
@@ -90,15 +102,17 @@ async function initProject(appName, options) {
|
|
|
90
102
|
await addAppExample(fullAppFolder);
|
|
91
103
|
}
|
|
92
104
|
updatePackageName(fullAppFolder);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (useYarn) {
|
|
105
|
+
(0, logger_1.wrapInBlanks)((0, logger_1.highlight)(`---- Installing the dependencies for your app (using ${chalk_1.default.cyan(packageManager)})...`));
|
|
106
|
+
if (packageManager === 'yarn') {
|
|
96
107
|
await (0, utils_1.exec)('yarn', [], { cwd: fullAppFolder });
|
|
97
108
|
}
|
|
109
|
+
else if (packageManager === 'pnpm') {
|
|
110
|
+
await (0, utils_1.exec)('pnpm', ['install'], { cwd: fullAppFolder });
|
|
111
|
+
}
|
|
98
112
|
else {
|
|
99
113
|
await (0, utils_1.exec)('npm', ['install', '--no-audit', '--no-fund'], { cwd: fullAppFolder });
|
|
100
114
|
}
|
|
101
|
-
successMessage(fullAppFolder,
|
|
115
|
+
successMessage(fullAppFolder, packageManager);
|
|
102
116
|
}
|
|
103
117
|
catch (err) {
|
|
104
118
|
(0, logger_1.error)(`Failed to create ${(0, logger_1.highlight)(chalk_1.default.cyan(appName))}`, err);
|
|
@@ -113,7 +127,7 @@ async function initProject(appName, options) {
|
|
|
113
127
|
const templateSource = await (0, getTemplateSource_1.getTemplateSource)(options);
|
|
114
128
|
(0, analytics_1.track)({
|
|
115
129
|
template: templateSource,
|
|
116
|
-
manager:
|
|
130
|
+
manager: packageManager,
|
|
117
131
|
interactive: isInteractive,
|
|
118
132
|
});
|
|
119
133
|
await (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
|
|
@@ -147,7 +161,7 @@ async function initProject(appName, options) {
|
|
|
147
161
|
example: normalizedOptions.function,
|
|
148
162
|
language: normalizedOptions.javascript ? 'javascript' : 'typescript',
|
|
149
163
|
name: functionName,
|
|
150
|
-
keepPackageJson: normalizedOptions.skipUi === true
|
|
164
|
+
keepPackageJson: normalizedOptions.skipUi === true,
|
|
151
165
|
});
|
|
152
166
|
}
|
|
153
167
|
}
|
|
@@ -168,6 +182,7 @@ async function initProject(appName, options) {
|
|
|
168
182
|
].join('\n'))
|
|
169
183
|
.argument('[app-name]', 'app name')
|
|
170
184
|
.option('--npm', 'use npm')
|
|
185
|
+
.option('--pnpm', 'use pnpm')
|
|
171
186
|
.option('--yarn', 'use Yarn')
|
|
172
187
|
.option('-ts, --typescript', 'use TypeScript template (default)')
|
|
173
188
|
.option('-js, --javascript', 'use JavaScript template')
|
package/lib/template.js
CHANGED
|
@@ -62,6 +62,7 @@ function validate(destination) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
function cleanUp(destination) {
|
|
65
|
+
(0, utils_1.rmIfExists)((0, path_1.resolve)(destination, 'pnpm-lock.json'));
|
|
65
66
|
(0, utils_1.rmIfExists)((0, path_1.resolve)(destination, 'package-lock.json'));
|
|
66
67
|
(0, utils_1.rmIfExists)((0, path_1.resolve)(destination, 'yarn.lock'));
|
|
67
68
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isContentfulTemplate = exports.normalizeOptions = exports.
|
|
3
|
+
exports.isContentfulTemplate = exports.normalizeOptions = exports.getNormalizedPackageManager = exports.detectActivePackageManager = exports.rmIfExists = exports.exec = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -28,25 +28,75 @@ function rmIfExists(path) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.rmIfExists = rmIfExists;
|
|
31
|
-
function
|
|
31
|
+
function detectActivePackageManager() {
|
|
32
|
+
if ((0, fs_1.existsSync)('pnpm-lock.yaml'))
|
|
33
|
+
return 'pnpm';
|
|
34
|
+
if ((0, fs_1.existsSync)('yarn.lock'))
|
|
35
|
+
return 'yarn';
|
|
36
|
+
if ((0, fs_1.existsSync)('package-lock.json'))
|
|
37
|
+
return 'npm';
|
|
38
|
+
(0, logger_1.warn)('No lock files found, we will try to detect the active package manager from package.json.');
|
|
39
|
+
try {
|
|
40
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)('package.json', 'utf8'));
|
|
41
|
+
if (pkg.packageManager?.startsWith('pnpm'))
|
|
42
|
+
return 'pnpm';
|
|
43
|
+
if (pkg.packageManager?.startsWith('yarn'))
|
|
44
|
+
return 'yarn';
|
|
45
|
+
if (pkg.packageManager?.startsWith('npm'))
|
|
46
|
+
return 'npm';
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
(0, logger_1.warn)(`Unable to determine active package manager from package.json. We will try to detect it from npm_execpath.`);
|
|
50
|
+
}
|
|
32
51
|
switch ((0, path_1.basename)(process.env.npm_execpath || '')) {
|
|
33
52
|
case 'yarn.js':
|
|
34
53
|
return 'yarn';
|
|
54
|
+
case 'pnpm.cjs':
|
|
55
|
+
return 'pnpm';
|
|
35
56
|
case 'npx-cli.js':
|
|
36
57
|
case 'npm-cli.js':
|
|
37
58
|
default:
|
|
38
59
|
return 'npm';
|
|
39
60
|
}
|
|
40
61
|
}
|
|
41
|
-
exports.
|
|
62
|
+
exports.detectActivePackageManager = detectActivePackageManager;
|
|
63
|
+
// By the time this function is called, the options have already been normalized
|
|
64
|
+
// so we would not need to consider multiple package manager flags at once
|
|
65
|
+
function getNormalizedPackageManager(options, activePackageManager) {
|
|
66
|
+
// Prefer to get the package manager from options
|
|
67
|
+
if (options.pnpm) {
|
|
68
|
+
return 'pnpm';
|
|
69
|
+
}
|
|
70
|
+
else if (options.yarn) {
|
|
71
|
+
return 'yarn';
|
|
72
|
+
}
|
|
73
|
+
else if (options.npm) {
|
|
74
|
+
return 'npm';
|
|
75
|
+
}
|
|
76
|
+
// Fallback to active package manager
|
|
77
|
+
return activePackageManager;
|
|
78
|
+
}
|
|
79
|
+
exports.getNormalizedPackageManager = getNormalizedPackageManager;
|
|
42
80
|
function normalizeOptions(options) {
|
|
43
81
|
const normalizedOptions = { ...options };
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
82
|
+
const selectedPackageManagers = [
|
|
83
|
+
['npm', normalizedOptions.npm],
|
|
84
|
+
['pnpm', normalizedOptions.pnpm],
|
|
85
|
+
['yarn', normalizedOptions.yarn],
|
|
86
|
+
].filter(([, n]) => n);
|
|
87
|
+
const activePackageManager = detectActivePackageManager();
|
|
88
|
+
if (selectedPackageManagers.length > 1) {
|
|
89
|
+
(0, logger_1.warn)(`Too many package manager flags were provided, we will use ${(0, logger_1.choice)(`--${activePackageManager}`)}.`);
|
|
90
|
+
// Delete all package manager options
|
|
91
|
+
selectedPackageManagers.forEach(([packageManager]) => {
|
|
92
|
+
delete normalizedOptions[packageManager];
|
|
93
|
+
});
|
|
94
|
+
// Select active package manager
|
|
95
|
+
normalizedOptions[activePackageManager] = true;
|
|
47
96
|
}
|
|
48
|
-
|
|
49
|
-
|
|
97
|
+
// No package manager flags were provided, use active package manager
|
|
98
|
+
if (selectedPackageManagers.length === 0) {
|
|
99
|
+
normalizedOptions[activePackageManager] = true;
|
|
50
100
|
}
|
|
51
101
|
let fallbackOption = '--typescript';
|
|
52
102
|
const currentMutuallyExclusiveOptions = MUTUALLY_EXCLUSIVE_OPTIONS.filter((option) => normalizedOptions[option]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/create-contentful-app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.0",
|
|
4
4
|
"description": "A template for building Contentful Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentful",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"test": "mocha 'test/**/*.spec.{js,ts}'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@contentful/app-scripts": "2.5.
|
|
39
|
+
"@contentful/app-scripts": "^2.5.5",
|
|
40
40
|
"@segment/analytics-node": "^2.2.0",
|
|
41
41
|
"chalk": "4.1.2",
|
|
42
42
|
"commander": "12.1.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"rimraf": "5.0.8",
|
|
47
47
|
"tiged": "^2.12.7",
|
|
48
48
|
"tildify": "2.0.0",
|
|
49
|
-
"validate-npm-package-name": "6.0.
|
|
49
|
+
"validate-npm-package-name": "6.0.2"
|
|
50
50
|
},
|
|
51
51
|
"bugs": {
|
|
52
52
|
"url": "https://github.com/contentful/create-contentful-app/issues"
|
|
@@ -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.
|
|
77
|
+
"contentful-management": "11.54.4",
|
|
78
78
|
"mocha": "^11.2.2",
|
|
79
|
-
"sinon": "^
|
|
79
|
+
"sinon": "^21.0.0",
|
|
80
80
|
"sinon-chai": "^3.7.0",
|
|
81
81
|
"ts-node": "^10.9.2"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "ddcb3e2c17676bf74bcfe1e048eca9bdfc9480f7"
|
|
84
84
|
}
|