@magnolia/cli-jumpstart-plugin 1.0.1 → 1.0.3
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/CHANGELOG.md +15 -0
- package/README.md +3 -3
- package/dist/jumpstart-plugin.d.ts +2 -2
- package/dist/jumpstart-plugin.js +49 -39
- package/dist/lib/config-helper.d.ts +1 -1
- package/dist/lib/config-helper.js +71 -48
- package/dist/lib/download.d.ts +1 -1
- package/dist/lib/download.js +104 -71
- package/dist/lib/extensions.d.ts +3 -1
- package/dist/lib/extensions.js +36 -48
- package/dist/lib/extract.d.ts +1 -1
- package/dist/lib/extract.js +54 -38
- package/dist/lib/handleMicroprofileConfig.d.ts +1 -1
- package/dist/lib/handleMicroprofileConfig.js +9 -9
- package/dist/lib/helper.d.ts +3 -1
- package/dist/lib/helper.js +80 -46
- package/dist/lib/install.d.ts +1 -1
- package/dist/lib/install.js +10 -7
- package/dist/lib/locales/en/translation.json +85 -76
- package/dist/lib/pj-helper.js +34 -24
- package/dist/package.json +75 -57
- package/package.json +75 -57
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.3 (2025-03-17)
|
|
4
|
+
* Add lightModulesPath to mgnl.config.js ([MGNLCLI-255](https://magnolia-cms.atlassian.net/browse/MGNLCLI-255))
|
|
5
|
+
* Place bundle to correct place when no postCommand is defined ([MGNLCLI-276](https://magnolia-cms.atlassian.net/browse/MGNLCLI-276))
|
|
6
|
+
* Add depcheck to husky ([MGNLCLI-289](https://magnolia-cms.atlassian.net/browse/MGNLCLI-289))
|
|
7
|
+
* Enhance tests with various templates configuration and flags ([MGNLCLI-304](https://magnolia-cms.atlassian.net/browse/MGNLCLI-304))
|
|
8
|
+
* Explore supporting both ESM and CommonJS in our packages ([MGNLCLI-313](https://magnolia-cms.atlassian.net/browse/MGNLCLI-313))
|
|
9
|
+
* Failed to download war with MGNL CLI 5 ([MGNLCLI-327](https://magnolia-cms.atlassian.net/browse/MGNLCLI-327))
|
|
10
|
+
* Mgnl CLI doesn't work in CN ([MGNLCLI-322](https://magnolia-cms.atlassian.net/browse/MGNLCLI-322))
|
|
11
|
+
* Address deprecated packages ([MGNLCLI-320](https://magnolia-cms.atlassian.net/browse/MGNLCLI-320))
|
|
12
|
+
* Add note that project will be created in current working directory ([MGNLCLI-335](https://magnolia-cms.atlassian.net/browse/MGNLCLI-335))
|
|
13
|
+
* Highlight when light modules are found during jumpstart ([MGNLCLI-337](https://magnolia-cms.atlassian.net/browse/MGNLCLI-337))
|
|
14
|
+
|
|
15
|
+
## 1.0.2 (2024-10-15)
|
|
16
|
+
* use alternative groupId and artifactId for latest magnolia version ([MGNLCLI-303](https://magnolia-cms.atlassian.net/browse/MGNLCLI-303))
|
|
17
|
+
|
|
3
18
|
## 1.0.1 (2024-10-15)
|
|
4
19
|
* use @5 version of @magnolia/cli ([MGNLCLI-302](https://magnolia-cms.atlassian.net/browse/MGNLCLI-302))
|
|
5
20
|
|
package/README.md
CHANGED
|
@@ -19,19 +19,19 @@ Within the Magnolia CLI plugin system, this plugin is pre-installed and ready to
|
|
|
19
19
|
### Examples
|
|
20
20
|
#### Jumpstart a project
|
|
21
21
|
```bash
|
|
22
|
-
npx @magnolia/cli jumpstart
|
|
22
|
+
npx @magnolia/cli@latest jumpstart
|
|
23
23
|
```
|
|
24
24
|
This command will prompt you with a list of available templates to choose from. Once you select a template, the CLI will download and configure the project with the latest Magnolia version (or with version associated with that template)
|
|
25
25
|
|
|
26
26
|
#### Jumpstart a project with specific template
|
|
27
27
|
```bash
|
|
28
|
-
npx @magnolia/cli jumpstart --template "standard-webapps/magnolia-community-webapp"
|
|
28
|
+
npx @magnolia/cli@latest jumpstart --template "standard-webapps/magnolia-community-webapp"
|
|
29
29
|
```
|
|
30
30
|
This command will start downloading and configuring project based on "standard-webapps/magnolia-community-webapp" template with latest Magnolia version.
|
|
31
31
|
|
|
32
32
|
#### Jumpstart a project with specific template and specific magnolia version
|
|
33
33
|
```bash
|
|
34
|
-
npx @magnolia/cli jumpstart --template "standard-webapps/magnolia-community-webapp" --magnolia "6.2.11"
|
|
34
|
+
npx @magnolia/cli@latest jumpstart --template "standard-webapps/magnolia-community-webapp" --magnolia "6.2.11"
|
|
35
35
|
```
|
|
36
36
|
This command will start downloading and configuring project based on "standard-webapps/magnolia-community-webapp" template with 6.2.11 Magnolia version.
|
|
37
37
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginTemplate } from '@magnolia/cli-plugin-template';
|
|
2
2
|
import { Option } from 'commander';
|
|
3
|
-
import { PluginOptions, Template, Bundle, TemplateWithoutChildren, Credentials } from
|
|
4
|
-
import { Logger } from
|
|
3
|
+
import { PluginOptions, Template, Bundle, TemplateWithoutChildren, Credentials } from './types/types.js';
|
|
4
|
+
import { Logger } from 'winston';
|
|
5
5
|
export declare let logger: Logger;
|
|
6
6
|
export declare let i18nInstance: {
|
|
7
7
|
t(key: string, options?: any): string;
|
package/dist/jumpstart-plugin.js
CHANGED
|
@@ -13,50 +13,57 @@ import { createRequire } from 'module';
|
|
|
13
13
|
const requireFn = createRequire(import.meta.url);
|
|
14
14
|
const pkg = requireFn('./package.json');
|
|
15
15
|
import inquirer from 'inquirer';
|
|
16
|
-
import axios from
|
|
17
|
-
import { extract } from
|
|
18
|
-
import { downloadBundle } from
|
|
19
|
-
import { PostCommands } from
|
|
20
|
-
import { installDependencies } from
|
|
21
|
-
import path from
|
|
22
|
-
import { askForCredentials, handleLightModulesFolder, initializeNodeProject } from
|
|
23
|
-
import { compileCustomPrompts, evaluateCustomPrompts } from
|
|
24
|
-
import { addConfigProps } from
|
|
25
|
-
import { installAdditionalPlugins } from
|
|
26
|
-
import { checkFlagsValue, CreateError } from
|
|
27
|
-
import { initI18n } from
|
|
28
|
-
import { fileURLToPath } from
|
|
16
|
+
import axios from 'axios';
|
|
17
|
+
import { extract } from './lib/extract.js';
|
|
18
|
+
import { downloadBundle } from './lib/download.js';
|
|
19
|
+
import { PostCommands, } from './types/types.js';
|
|
20
|
+
import { installDependencies } from './lib/install.js';
|
|
21
|
+
import path from 'path';
|
|
22
|
+
import { askForCredentials, copyDownloadedFile, handleLightModulesFolder, handleLightModulesPathInTemplate, initializeNodeProject, } from './lib/helper.js';
|
|
23
|
+
import { compileCustomPrompts, evaluateCustomPrompts, } from './lib/extensions.js';
|
|
24
|
+
import { addConfigProps } from './lib/config-helper.js';
|
|
25
|
+
import { installAdditionalPlugins } from './lib/config-helper.js';
|
|
26
|
+
import { checkFlagsValue, CreateError, prependNumbersToChoices, } from '@magnolia/cli-helper/general-utils';
|
|
27
|
+
import { initI18n } from '@magnolia/cli-helper/i18n';
|
|
28
|
+
import { fileURLToPath } from 'url';
|
|
29
29
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
30
|
-
const extensionsPath = path.resolve(
|
|
30
|
+
const extensionsPath = path.resolve('./extensions/extension.yaml');
|
|
31
31
|
export let logger;
|
|
32
32
|
export let i18nInstance = {
|
|
33
|
-
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
t(key, options) {
|
|
35
|
+
return key;
|
|
36
|
+
},
|
|
34
37
|
};
|
|
35
38
|
export default class JumpstartPlugin extends PluginTemplate {
|
|
36
39
|
constructor() {
|
|
37
40
|
super();
|
|
38
|
-
this.name =
|
|
41
|
+
this.name = 'jumpstart';
|
|
39
42
|
this.version = pkg.version;
|
|
40
|
-
this.usage =
|
|
41
|
-
i18nInstance = initI18n(this.name,
|
|
43
|
+
this.usage = '[options]';
|
|
44
|
+
i18nInstance = initI18n(this.name, 'translation', path.join(__dirname, 'lib/locales'));
|
|
42
45
|
this.description = i18nInstance.t('description');
|
|
43
46
|
this.options = [
|
|
44
47
|
new Option('-m, --magnolia <version>', i18nInstance.t('option-magnolia-description')),
|
|
45
48
|
new Option('-s, --snapshot', i18nInstance.t('option-snapshot-description')),
|
|
46
|
-
new Option('-t, --template <name>', i18nInstance.t(
|
|
47
|
-
new Option('-pt, --project-templates <source>', i18nInstance.t(
|
|
49
|
+
new Option('-t, --template <name>', i18nInstance.t('option-template-description')),
|
|
50
|
+
new Option('-pt, --project-templates <source>', i18nInstance.t('option-projectTemplates-description')),
|
|
48
51
|
];
|
|
49
52
|
}
|
|
50
53
|
executePostCommands(bundle, file) {
|
|
51
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
|
|
55
|
+
const isCopied = copyDownloadedFile(bundle, file);
|
|
56
|
+
if (!bundle.postCommand) {
|
|
53
57
|
return;
|
|
58
|
+
}
|
|
54
59
|
for (const command of bundle.postCommand) {
|
|
55
60
|
switch (command) {
|
|
56
61
|
case PostCommands.Extract:
|
|
57
62
|
case PostCommands.ExtractAndOverride:
|
|
58
63
|
case PostCommands.ExtractAndUnfold:
|
|
59
|
-
|
|
64
|
+
if (!isCopied) {
|
|
65
|
+
yield extract(bundle, file, command);
|
|
66
|
+
}
|
|
60
67
|
break;
|
|
61
68
|
case PostCommands.NpmInstall:
|
|
62
69
|
case PostCommands.YarnInstall:
|
|
@@ -86,7 +93,7 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
95
|
catch (e) {
|
|
89
|
-
|
|
96
|
+
throw new CreateError(e.message);
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
99
|
yield handleLightModulesFolder();
|
|
@@ -94,6 +101,7 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
94
101
|
if (template.plugins) {
|
|
95
102
|
yield installAdditionalPlugins(template.plugins);
|
|
96
103
|
}
|
|
104
|
+
yield handleLightModulesPathInTemplate(template);
|
|
97
105
|
if (template.configVars) {
|
|
98
106
|
yield addConfigProps(template.configVars);
|
|
99
107
|
}
|
|
@@ -111,27 +119,28 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
111
119
|
var _a;
|
|
112
120
|
let errorMsg;
|
|
113
121
|
try {
|
|
114
|
-
if ((_a = options.projectTemplates) === null || _a === void 0 ? void 0 : _a.startsWith(
|
|
115
|
-
errorMsg = i18nInstance.t(
|
|
122
|
+
if ((_a = options.projectTemplates) === null || _a === void 0 ? void 0 : _a.startsWith('http', 0)) {
|
|
123
|
+
errorMsg = i18nInstance.t('error-no-projectTemplates-from-url', { url: options.projectTemplates });
|
|
116
124
|
const res = yield axios.get(options.projectTemplates);
|
|
117
125
|
this.projectTemplates = res.data.projectTemplates;
|
|
118
126
|
}
|
|
119
127
|
else if (options.projectTemplates) {
|
|
120
|
-
errorMsg = i18nInstance.t(
|
|
128
|
+
errorMsg = i18nInstance.t('error-no-projectTemplates-from-path', { path: options.projectTemplates });
|
|
121
129
|
this.projectTemplates = requireFn(path.resolve(options.projectTemplates)).projectTemplates;
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
|
-
errorMsg = i18nInstance.t(
|
|
125
|
-
const res = yield axios.get(
|
|
132
|
+
errorMsg = i18nInstance.t('error-no-projectTemplates-from-default');
|
|
133
|
+
const res = yield axios.get('https://bitbucket.org/magnolia-cms/cli-project-templates/raw/HEAD/projectTemplates.json');
|
|
126
134
|
this.projectTemplates = res.data.projectTemplates;
|
|
127
135
|
}
|
|
128
136
|
}
|
|
129
137
|
catch (e) {
|
|
130
138
|
if (errorMsg) {
|
|
131
|
-
throw new CreateError(errorMsg);
|
|
139
|
+
throw new CreateError(errorMsg + `\n${e.message}`);
|
|
132
140
|
}
|
|
133
141
|
else {
|
|
134
|
-
|
|
142
|
+
// eslint-disable-next-line no-console
|
|
143
|
+
console.error(i18nInstance.t('error-while-getting-projectTemplates'));
|
|
135
144
|
throw e;
|
|
136
145
|
}
|
|
137
146
|
}
|
|
@@ -142,19 +151,19 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
142
151
|
if (!templates || !templates.length) {
|
|
143
152
|
return;
|
|
144
153
|
}
|
|
145
|
-
const choices = templates.map(template => {
|
|
154
|
+
const choices = templates.map((template) => {
|
|
146
155
|
return {
|
|
147
|
-
name: `${template.name}${template.description ? ` (${template.description})` :
|
|
148
|
-
value: template
|
|
156
|
+
name: `${template.name}${template.description ? ` (${template.description})` : ''}`,
|
|
157
|
+
value: template,
|
|
149
158
|
};
|
|
150
159
|
});
|
|
151
160
|
const { template } = yield inquirer.prompt([
|
|
152
161
|
{
|
|
153
|
-
type: '
|
|
162
|
+
type: 'list',
|
|
154
163
|
name: 'template',
|
|
155
164
|
message: i18nInstance.t('inquirer-prompt-choose-template'),
|
|
156
|
-
choices: choices
|
|
157
|
-
}
|
|
165
|
+
choices: prependNumbersToChoices(choices),
|
|
166
|
+
},
|
|
158
167
|
]);
|
|
159
168
|
if (template.name) {
|
|
160
169
|
names.push(template.name);
|
|
@@ -163,7 +172,7 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
163
172
|
return this.promptTemplateSelection(template.children, names);
|
|
164
173
|
}
|
|
165
174
|
if (template.bundles || template.plugins) {
|
|
166
|
-
return Object.assign(Object.assign({}, template), { name: names.join(
|
|
175
|
+
return Object.assign(Object.assign({}, template), { name: names.join('/') });
|
|
167
176
|
}
|
|
168
177
|
});
|
|
169
178
|
}
|
|
@@ -191,8 +200,8 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
191
200
|
return;
|
|
192
201
|
}
|
|
193
202
|
else {
|
|
194
|
-
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t(
|
|
195
|
-
template: options.template
|
|
203
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t('info-template-not-found', {
|
|
204
|
+
template: options.template,
|
|
196
205
|
}));
|
|
197
206
|
}
|
|
198
207
|
}
|
|
@@ -210,6 +219,7 @@ export default class JumpstartPlugin extends PluginTemplate {
|
|
|
210
219
|
start(options) {
|
|
211
220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
221
|
checkFlagsValue(this.options, options);
|
|
222
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t('info-will-be-in-cwd'));
|
|
213
223
|
yield this.setProjectTemplates(options);
|
|
214
224
|
yield this.chooseTemplate(options);
|
|
215
225
|
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t('info-project-downloaded'));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginRequirement } from
|
|
1
|
+
import { PluginRequirement } from '../types/types.js';
|
|
2
2
|
export declare const installAdditionalPlugins: (plugins: Array<PluginRequirement>) => Promise<void>;
|
|
3
3
|
export declare const handleMGNLConfigFile: () => Promise<void>;
|
|
4
4
|
export declare const addConfigProps: (vars: any) => Promise<void>;
|
|
@@ -7,49 +7,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import fs from
|
|
11
|
-
import parser from
|
|
12
|
-
import t from
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import parser from '@babel/parser';
|
|
12
|
+
import t from '@babel/types';
|
|
13
13
|
const generate = _generate.default;
|
|
14
14
|
const traverse = _traverse.default;
|
|
15
|
-
import beautifyModule from
|
|
16
|
-
import path from
|
|
17
|
-
import { determinePackageManager, installCLI } from
|
|
18
|
-
import ora from
|
|
19
|
-
import { i18nInstance, logger } from
|
|
20
|
-
import _generate from
|
|
21
|
-
import _traverse from
|
|
22
|
-
import { execa } from
|
|
23
|
-
import JSON5 from
|
|
24
|
-
import { BEAUTIFY_OPTIONS } from
|
|
15
|
+
import beautifyModule from 'js-beautify';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import { determinePackageManager, installCLI } from './helper.js';
|
|
18
|
+
import ora from 'ora';
|
|
19
|
+
import { i18nInstance, logger } from '../jumpstart-plugin.js';
|
|
20
|
+
import _generate from '@babel/generator';
|
|
21
|
+
import _traverse from '@babel/traverse';
|
|
22
|
+
import { execa } from 'execa';
|
|
23
|
+
import JSON5 from 'json5';
|
|
24
|
+
import { BEAUTIFY_OPTIONS } from '@magnolia/cli-helper/general-utils';
|
|
25
25
|
const { js_beautify } = beautifyModule;
|
|
26
|
-
|
|
26
|
+
import { getMgnlConfigPath } from '@magnolia/cli-helper/config';
|
|
27
27
|
const getPackageConfigPath = () => path.join(process.cwd(), 'node_modules/@magnolia/cli/mgnl.config.js');
|
|
28
28
|
export const installAdditionalPlugins = (plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
|
|
29
|
+
const spinner = ora().start(i18nInstance.t('ora-start-checking-add-plugin'));
|
|
30
30
|
let showManualInstallMsg = false;
|
|
31
31
|
const pm = determinePackageManager();
|
|
32
32
|
try {
|
|
33
33
|
const addPluginExists = yield execa(pm, 'run mgnl -s -- add-plugin -v'.split(' '), { cwd: process.cwd() });
|
|
34
|
-
if (addPluginExists.exitCode !== 0 ||
|
|
35
|
-
|
|
34
|
+
if (addPluginExists.exitCode !== 0 ||
|
|
35
|
+
!addPluginExists.stdout.match(/(\d.)+(\d).*/)) {
|
|
36
|
+
spinner.warn(i18nInstance.t('ora-warn-no-add-plugin'));
|
|
36
37
|
showManualInstallMsg = true;
|
|
37
38
|
}
|
|
38
39
|
spinner.stop();
|
|
39
40
|
}
|
|
40
41
|
catch (e) {
|
|
41
42
|
showManualInstallMsg = true;
|
|
42
|
-
spinner.fail(i18nInstance.t(
|
|
43
|
+
spinner.fail(i18nInstance.t('ora-fail-while-add-plugin-check', {
|
|
44
|
+
errorMsg: e.message,
|
|
45
|
+
}));
|
|
43
46
|
}
|
|
44
47
|
if (showManualInstallMsg) {
|
|
45
|
-
let installPluginsText =
|
|
46
|
-
plugins.forEach(plugin => {
|
|
48
|
+
let installPluginsText = '';
|
|
49
|
+
plugins.forEach((plugin) => {
|
|
47
50
|
installPluginsText = `${installPluginsText} - ${plugin.plugin}\n`;
|
|
48
51
|
if (plugin.pluginArgs) {
|
|
49
|
-
installPluginsText = `${installPluginsText}${i18nInstance.t(
|
|
52
|
+
installPluginsText = `${installPluginsText}${i18nInstance.t('text-install-plugin-with-args', { pluginArgs: JSON5.stringify(plugin.pluginArgs) })}`;
|
|
50
53
|
}
|
|
51
54
|
});
|
|
52
|
-
logger === null || logger === void 0 ? void 0 : logger.warn(i18nInstance.t(
|
|
55
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(i18nInstance.t('warn-install-plugins-manually', {
|
|
56
|
+
installPluginsText: installPluginsText,
|
|
57
|
+
}));
|
|
53
58
|
return;
|
|
54
59
|
}
|
|
55
60
|
for (const plugin of plugins) {
|
|
@@ -57,23 +62,32 @@ export const installAdditionalPlugins = (plugins) => __awaiter(void 0, void 0, v
|
|
|
57
62
|
let argsMsg;
|
|
58
63
|
const addPluginArgs = `run mgnl -s -- add-plugin ${plugin.plugin}`.split(' ');
|
|
59
64
|
try {
|
|
60
|
-
if (plugin.pluginArgs !== undefined &&
|
|
65
|
+
if (plugin.pluginArgs !== undefined &&
|
|
66
|
+
plugin.pluginArgs !== 'undefined' &&
|
|
67
|
+
plugin.pluginArgs !== '') {
|
|
61
68
|
addPluginArgs.push(JSON5.stringify(JSON5.parse(JSON5.stringify(plugin.pluginArgs))));
|
|
62
69
|
}
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63
71
|
}
|
|
64
72
|
catch (e) {
|
|
65
|
-
argsMsg = i18nInstance.t('warn-cannot-parse-plugin-args', {
|
|
73
|
+
argsMsg = i18nInstance.t('warn-cannot-parse-plugin-args', {
|
|
74
|
+
pluginArgs: plugin.pluginArgs,
|
|
75
|
+
plugin: plugin.plugin,
|
|
76
|
+
});
|
|
66
77
|
}
|
|
67
78
|
yield execa(pm, addPluginArgs, {
|
|
68
79
|
stdio: 'inherit',
|
|
69
|
-
cwd: process.cwd()
|
|
80
|
+
cwd: process.cwd(),
|
|
70
81
|
});
|
|
71
82
|
if (argsMsg) {
|
|
72
83
|
logger === null || logger === void 0 ? void 0 : logger.warn(argsMsg);
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
catch (e) {
|
|
76
|
-
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t('error-while-add-plugin', {
|
|
87
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t('error-while-add-plugin', {
|
|
88
|
+
plugin: plugin.plugin,
|
|
89
|
+
errorMsg: e.message,
|
|
90
|
+
}));
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
});
|
|
@@ -83,7 +97,7 @@ export const handleMGNLConfigFile = () => __awaiter(void 0, void 0, void 0, func
|
|
|
83
97
|
isMgnlCliInstalled = yield installCLI();
|
|
84
98
|
}
|
|
85
99
|
if (isMgnlCliInstalled) {
|
|
86
|
-
if (fs.existsSync(
|
|
100
|
+
if (fs.existsSync(getMgnlConfigPath())) {
|
|
87
101
|
handleExistingConfigFile();
|
|
88
102
|
}
|
|
89
103
|
else {
|
|
@@ -91,22 +105,22 @@ export const handleMGNLConfigFile = () => __awaiter(void 0, void 0, void 0, func
|
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
else {
|
|
94
|
-
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t(
|
|
108
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t('error-mgnl-cli-not-installed'));
|
|
95
109
|
}
|
|
96
110
|
});
|
|
97
111
|
const handleExistingConfigFile = () => {
|
|
98
|
-
const localConfigContent = fs.readFileSync(
|
|
99
|
-
const packageConfigContent = fs.readFileSync(getPackageConfigPath(),
|
|
112
|
+
const localConfigContent = fs.readFileSync(getMgnlConfigPath(), 'utf8');
|
|
113
|
+
const packageConfigContent = fs.readFileSync(getPackageConfigPath(), 'utf8');
|
|
100
114
|
const localLoggerConfig = extractLoggerConfig(localConfigContent);
|
|
101
115
|
const globalLoggerConfig = extractLoggerConfig(packageConfigContent);
|
|
102
|
-
if (!localLoggerConfig &&
|
|
116
|
+
if (!localLoggerConfig && globalLoggerConfig && globalLoggerConfig[1]) {
|
|
103
117
|
const loggerContent = getLoggerContent(globalLoggerConfig[1]);
|
|
104
118
|
const newLocalConfigContent = localConfigContent.replace(/(export\s+default\s+\{)/, `$1${loggerContent}`);
|
|
105
119
|
writeConfigContent(newLocalConfigContent, false);
|
|
106
120
|
}
|
|
107
121
|
};
|
|
108
122
|
function createMgnlConfigFile() {
|
|
109
|
-
const packageConfigContent = fs.readFileSync(getPackageConfigPath(),
|
|
123
|
+
const packageConfigContent = fs.readFileSync(getPackageConfigPath(), 'utf8');
|
|
110
124
|
const loggerConfig = extractLoggerConfig(packageConfigContent);
|
|
111
125
|
const mgnlConfigPrefix = `
|
|
112
126
|
export default {`;
|
|
@@ -131,20 +145,26 @@ const extractLoggerConfig = (content) => {
|
|
|
131
145
|
return loggerRegex.exec(content);
|
|
132
146
|
};
|
|
133
147
|
const writeConfigContent = (content, creating) => {
|
|
134
|
-
const spinner = ora().start(i18nInstance.t(creating
|
|
148
|
+
const spinner = ora().start(i18nInstance.t(creating
|
|
149
|
+
? 'ora-start-creating-config'
|
|
150
|
+
: 'ora-start-updating-config'));
|
|
135
151
|
try {
|
|
136
|
-
fs.writeFileSync(
|
|
137
|
-
spinner.succeed(i18nInstance.t(creating
|
|
152
|
+
fs.writeFileSync(getMgnlConfigPath(), js_beautify(content.trim(), BEAUTIFY_OPTIONS), 'utf-8');
|
|
153
|
+
spinner.succeed(i18nInstance.t(creating
|
|
154
|
+
? 'ora-succeed-config-created'
|
|
155
|
+
: 'ora-succeed-config-updated'));
|
|
138
156
|
}
|
|
139
157
|
catch (e) {
|
|
140
|
-
spinner.fail(i18nInstance.t(creating
|
|
158
|
+
spinner.fail(i18nInstance.t(creating
|
|
159
|
+
? 'ora-fail-creating-config'
|
|
160
|
+
: 'ora-fail-updating-config', { errorMsg: e.message }));
|
|
141
161
|
}
|
|
142
162
|
};
|
|
143
163
|
export const addConfigProps = (vars) => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
-
const spinner = ora().start(i18nInstance.t(
|
|
164
|
+
const spinner = ora().start(i18nInstance.t('ora-start-adding-shared-vars'));
|
|
145
165
|
try {
|
|
146
|
-
const filePath =
|
|
147
|
-
|
|
166
|
+
const filePath = getMgnlConfigPath();
|
|
167
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
148
168
|
const valueToAstNode = (value) => {
|
|
149
169
|
if (typeof value === 'string') {
|
|
150
170
|
return t.stringLiteral(value);
|
|
@@ -156,7 +176,7 @@ export const addConfigProps = (vars) => __awaiter(void 0, void 0, void 0, functi
|
|
|
156
176
|
return t.numericLiteral(value);
|
|
157
177
|
}
|
|
158
178
|
else if (Array.isArray(value)) {
|
|
159
|
-
return t.arrayExpression(value.map(item => valueToAstNode(item)));
|
|
179
|
+
return t.arrayExpression(value.map((item) => valueToAstNode(item)));
|
|
160
180
|
}
|
|
161
181
|
else if (typeof value === 'object') {
|
|
162
182
|
return t.objectExpression(Object.entries(value).map(([key, val]) => t.objectProperty(t.isValidIdentifier(key)
|
|
@@ -170,7 +190,7 @@ export const addConfigProps = (vars) => __awaiter(void 0, void 0, void 0, functi
|
|
|
170
190
|
const ast = parser.parse(content, {
|
|
171
191
|
sourceType: 'module',
|
|
172
192
|
plugins: ['typescript'], // if you're using TypeScript
|
|
173
|
-
attachComment: true
|
|
193
|
+
attachComment: true,
|
|
174
194
|
});
|
|
175
195
|
let modificationsMade = false;
|
|
176
196
|
traverse(ast, {
|
|
@@ -178,13 +198,16 @@ export const addConfigProps = (vars) => __awaiter(void 0, void 0, void 0, functi
|
|
|
178
198
|
if (t.isObjectExpression(node.declaration)) {
|
|
179
199
|
// Check each required property to see if it exists in the declaration
|
|
180
200
|
Object.entries(vars).forEach(([key, value]) => {
|
|
181
|
-
|
|
182
|
-
((t.isIdentifier(property.key) &&
|
|
183
|
-
|
|
201
|
+
const propExists = node.declaration.properties.some((property) => t.isObjectProperty(property) &&
|
|
202
|
+
((t.isIdentifier(property.key) &&
|
|
203
|
+
property.key.name === key) ||
|
|
204
|
+
(t.isStringLiteral(property.key) &&
|
|
205
|
+
property.key.value === key)));
|
|
184
206
|
if (!propExists) {
|
|
185
207
|
// If the property doesn't exist, add it
|
|
186
208
|
node.declaration.properties.push(t.objectProperty(t.isValidIdentifier(key)
|
|
187
|
-
? t.identifier(key)
|
|
209
|
+
? t.identifier(key)
|
|
210
|
+
: t.stringLiteral(key), valueToAstNode(value)));
|
|
188
211
|
modificationsMade = true;
|
|
189
212
|
}
|
|
190
213
|
});
|
|
@@ -193,11 +216,11 @@ export const addConfigProps = (vars) => __awaiter(void 0, void 0, void 0, functi
|
|
|
193
216
|
});
|
|
194
217
|
if (modificationsMade) {
|
|
195
218
|
const output = generate(ast, {}, content);
|
|
196
|
-
fs.writeFileSync(
|
|
197
|
-
spinner.succeed(i18nInstance.t(
|
|
219
|
+
fs.writeFileSync(getMgnlConfigPath(), js_beautify(output.code.trim(), BEAUTIFY_OPTIONS), 'utf-8');
|
|
220
|
+
spinner.succeed(i18nInstance.t('ora-succeed-shared-vars-added'));
|
|
198
221
|
}
|
|
199
222
|
}
|
|
200
223
|
catch (e) {
|
|
201
|
-
spinner.fail(i18nInstance.t(
|
|
224
|
+
spinner.fail(i18nInstance.t('error-while-adding-vars', { errorMsg: e.message }));
|
|
202
225
|
}
|
|
203
226
|
});
|
package/dist/lib/download.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bundle, Credentials, PluginOptions } from
|
|
1
|
+
import { Bundle, Credentials, PluginOptions } from '../types/types.js';
|
|
2
2
|
export declare const downloadBundle: (bundle: Bundle, credentials: Credentials, dest: string | undefined, options: PluginOptions) => Promise<string>;
|
|
3
3
|
export declare const getDownloadUrl: (bundle: Bundle, credentials: Credentials, options: PluginOptions) => Promise<string>;
|
|
4
4
|
export declare const selectTag: (url: string, credentials: Credentials) => Promise<string>;
|