@magnolia/cli-jumpstart-plugin 1.0.0-preview.3 → 1.0.0-preview.5
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/LICENSE.txt +27 -0
- package/README.md +94 -4
- package/dist/jumpstart-plugin.d.ts +8 -5
- package/dist/jumpstart-plugin.js +54 -58
- package/dist/lib/config-helper.d.ts +3 -2
- package/dist/lib/config-helper.js +109 -120
- package/dist/lib/download.d.ts +3 -3
- package/dist/lib/download.js +79 -18
- package/dist/lib/extensions.d.ts +5 -0
- package/dist/lib/extensions.js +125 -0
- package/dist/lib/extract.js +12 -4
- package/dist/lib/helper.d.ts +5 -3
- package/dist/lib/helper.js +101 -18
- package/dist/lib/install.js +4 -4
- package/dist/lib/locales/en/translation.json +73 -0
- package/dist/lib/pj-helper.js +10 -10
- package/dist/package.json +15 -6
- package/dist/types/types.d.ts +17 -18
- package/dist/types/types.js +1 -0
- package/package.json +15 -6
|
@@ -10,26 +10,69 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import fs from "fs-extra";
|
|
11
11
|
import parser from "@babel/parser";
|
|
12
12
|
import t from "@babel/types";
|
|
13
|
+
const generate = _generate.default;
|
|
14
|
+
const traverse = _traverse.default;
|
|
13
15
|
import beautifyModule from "js-beautify";
|
|
14
16
|
import path from "path";
|
|
15
|
-
import { determinePackageManager,
|
|
17
|
+
import { determinePackageManager, installPackage } from "./helper.js";
|
|
16
18
|
import ora from "ora";
|
|
17
|
-
import { logger } from "../jumpstart-plugin.js";
|
|
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";
|
|
18
24
|
const { js_beautify } = beautifyModule;
|
|
19
25
|
const BEAUTIFY_OPTIONS = {
|
|
20
26
|
indent_size: 2,
|
|
21
27
|
end_with_newline: true,
|
|
22
28
|
max_preserve_newlines: 2,
|
|
23
29
|
keep_array_indentation: false,
|
|
24
|
-
preserve_newlines: true
|
|
30
|
+
preserve_newlines: true,
|
|
31
|
+
wrap_line_length: 1
|
|
25
32
|
};
|
|
26
33
|
const getLocalConfigPath = () => path.join(process.cwd(), 'mgnl.config.js');
|
|
27
34
|
const getPackageConfigPath = () => path.join(process.cwd(), 'node_modules/@magnolia/cli/mgnl.config.js');
|
|
35
|
+
export const installAdditionalPlugins = (plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const pm = determinePackageManager();
|
|
37
|
+
const addPluginExists = yield execa(pm, 'run mgnl -s -- add-plugin -v'.split(' '), { cwd: process.cwd() });
|
|
38
|
+
if (addPluginExists.exitCode !== 0 || !addPluginExists.stdout.match(/(\d.)+(\d).*/)) {
|
|
39
|
+
logger.warn(i18nInstance.t("warn-config-h-no-add-plugin"));
|
|
40
|
+
let installPluginsText = "";
|
|
41
|
+
plugins.forEach(plugin => {
|
|
42
|
+
installPluginsText = `${installPluginsText} - ${plugin.plugin}\n`;
|
|
43
|
+
if (plugin.pluginArgs) {
|
|
44
|
+
installPluginsText = `${installPluginsText}${i18nInstance.t("install-plugin-with-args-text", { pluginArgs: JSON5.stringify(plugin.pluginArgs) })}`;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
logger.warn(i18nInstance.t("warn-config-h-install-plugins-manually", { installPluginsText: installPluginsText }));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const plugin of plugins) {
|
|
51
|
+
try {
|
|
52
|
+
const addPluginArgs = `run mgnl -s -- add-plugin ${plugin.plugin}`.split(' ');
|
|
53
|
+
try {
|
|
54
|
+
if (plugin.pluginArgs !== undefined && plugin.pluginArgs !== 'undefined' && plugin.pluginArgs !== '') {
|
|
55
|
+
addPluginArgs.push(JSON5.stringify(JSON5.parse(JSON5.stringify(plugin.pluginArgs))));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
logger.warn(i18nInstance.t('warn-config-h-error-cannot-parse-plugin-args', { pluginArgs: plugin.pluginArgs }));
|
|
60
|
+
}
|
|
61
|
+
yield execa(pm, addPluginArgs, {
|
|
62
|
+
stdio: 'inherit',
|
|
63
|
+
cwd: process.cwd()
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
logger.error(i18nInstance.t('error-config-h-while-add-plugin', { plugin: plugin }));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
28
71
|
export const handleMGNLConfigFile = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
72
|
let isMgnlCliInstalled = true;
|
|
30
73
|
if (!fs.existsSync(getPackageConfigPath())) {
|
|
31
74
|
isMgnlCliInstalled = yield installPackage(determinePackageManager(), "@magnolia/cli@preview");
|
|
32
|
-
logger === null || logger === void 0 ? void 0 : logger.warn(
|
|
75
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(i18nInstance.t('warn-config-h-could-not-install-cli'));
|
|
33
76
|
}
|
|
34
77
|
if (isMgnlCliInstalled && fs.existsSync(getLocalConfigPath())) {
|
|
35
78
|
handleExistingConfigFile();
|
|
@@ -44,18 +87,6 @@ export const handleMGNLConfigFile = () => __awaiter(void 0, void 0, void 0, func
|
|
|
44
87
|
// the mgnl.config.js exist, do not do anything
|
|
45
88
|
}
|
|
46
89
|
});
|
|
47
|
-
export const installAndConfigPlugins = (plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
const localConfig = parseConfigFile(getLocalConfigPath());
|
|
49
|
-
if (!localConfig)
|
|
50
|
-
return;
|
|
51
|
-
const missingPlugins = findMissingPlugins(plugins, localConfig);
|
|
52
|
-
if (missingPlugins.length === 0)
|
|
53
|
-
return;
|
|
54
|
-
logger === null || logger === void 0 ? void 0 : logger.info(`Will attempt to install missing plugins`);
|
|
55
|
-
const installedPlugins = yield installPlugins(missingPlugins);
|
|
56
|
-
const pluginsConfig = createCustomConfigForPlugins(installedPlugins);
|
|
57
|
-
updateLocalConfig(pluginsConfig, localConfig);
|
|
58
|
-
});
|
|
59
90
|
const handleExistingConfigFile = () => {
|
|
60
91
|
const localConfigContent = fs.readFileSync(getLocalConfigPath(), "utf8");
|
|
61
92
|
const packageConfigContent = fs.readFileSync(getPackageConfigPath(), "utf8");
|
|
@@ -100,122 +131,80 @@ const extractLoggerConfig = (content) => {
|
|
|
100
131
|
const loggerRegex = /(logger\s*:\s*{[^}]*})/s;
|
|
101
132
|
return loggerRegex.exec(content);
|
|
102
133
|
};
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
let packageName = plugin.name;
|
|
106
|
-
return !config.imports.some(customImport => customImport.importedNames === packageName);
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
const installPlugins = (plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
-
const packageManager = determinePackageManager();
|
|
111
|
-
let installedPlugins = [];
|
|
112
|
-
for (const plugin of plugins) {
|
|
113
|
-
const installed = yield installPackage(packageManager, plugin.installReference, plugin.name);
|
|
114
|
-
if (installed)
|
|
115
|
-
installedPlugins.push(plugin);
|
|
116
|
-
}
|
|
117
|
-
return installedPlugins;
|
|
118
|
-
});
|
|
119
|
-
const createCustomConfigForPlugins = (plugins) => {
|
|
120
|
-
const defaultConfig = { configContent: "", imports: [], commands: [] };
|
|
121
|
-
plugins.forEach(plugin => {
|
|
122
|
-
let importSource;
|
|
123
|
-
if (isValidURL(plugin.installReference)) {
|
|
124
|
-
importSource = extractRepoName(plugin.installReference);
|
|
125
|
-
}
|
|
126
|
-
if (!importSource) {
|
|
127
|
-
importSource = plugin.installReference;
|
|
128
|
-
}
|
|
129
|
-
defaultConfig.imports.push({ importedNames: plugin.name, importSource: importSource });
|
|
130
|
-
defaultConfig.commands.push({ commandName: plugin.name });
|
|
131
|
-
});
|
|
132
|
-
return defaultConfig;
|
|
133
|
-
};
|
|
134
|
-
const parseConfigFile = (configPath) => {
|
|
135
|
-
let configContent;
|
|
136
|
-
try {
|
|
137
|
-
configContent = fs.readFileSync(configPath, 'utf-8');
|
|
138
|
-
}
|
|
139
|
-
catch (e) {
|
|
140
|
-
logger === null || logger === void 0 ? void 0 : logger.error(`Couldn't read ${configPath}`);
|
|
141
|
-
console.error(e);
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
let parsedConfig;
|
|
134
|
+
const writeConfigContent = (content) => {
|
|
135
|
+
const spinner = ora().start(i18nInstance.t("ora-updating-mgnl-config"));
|
|
145
136
|
try {
|
|
146
|
-
|
|
137
|
+
fs.writeFileSync(getLocalConfigPath(), js_beautify(content.trim(), BEAUTIFY_OPTIONS), 'utf-8');
|
|
147
138
|
}
|
|
148
139
|
catch (e) {
|
|
149
|
-
|
|
140
|
+
spinner.stop();
|
|
141
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-config-h-while-updating-mgnl-config"));
|
|
150
142
|
console.error(e);
|
|
151
|
-
return null;
|
|
152
143
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const { imports, commands } = extractImportsAndCommands(parsedConfig);
|
|
156
|
-
return { configContent, imports, commands };
|
|
144
|
+
spinner.stop();
|
|
145
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-config-h-mgnl-config-updated"));
|
|
157
146
|
};
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
147
|
+
export const addConfigProps = (vars) => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
|
+
const spinner = ora().start(i18nInstance.t("ora-adding-shared-vars"));
|
|
149
|
+
try {
|
|
150
|
+
const filePath = getLocalConfigPath();
|
|
151
|
+
let content = fs.readFileSync(filePath, 'utf-8');
|
|
152
|
+
const valueToAstNode = (value) => {
|
|
153
|
+
if (typeof value === 'string') {
|
|
154
|
+
return t.stringLiteral(value);
|
|
155
|
+
}
|
|
156
|
+
else if (typeof value === 'boolean') {
|
|
157
|
+
return t.booleanLiteral(value);
|
|
158
|
+
}
|
|
159
|
+
else if (typeof value === 'number') {
|
|
160
|
+
return t.numericLiteral(value);
|
|
161
|
+
}
|
|
162
|
+
else if (Array.isArray(value)) {
|
|
163
|
+
return t.arrayExpression(value.map(item => valueToAstNode(item)));
|
|
164
|
+
}
|
|
165
|
+
else if (typeof value === 'object') {
|
|
166
|
+
return t.objectExpression(Object.entries(value).map(([key, val]) => t.objectProperty(t.isValidIdentifier(key)
|
|
167
|
+
? t.identifier(key)
|
|
168
|
+
: t.stringLiteral(key), valueToAstNode(val))));
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new TypeError('Unsupported type');
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const ast = parser.parse(content, {
|
|
175
|
+
sourceType: 'module',
|
|
176
|
+
plugins: ['typescript'], // if you're using TypeScript
|
|
177
|
+
attachComment: true
|
|
178
|
+
});
|
|
179
|
+
let modificationsMade = false;
|
|
180
|
+
traverse(ast, {
|
|
181
|
+
ExportDefaultDeclaration({ node }) {
|
|
182
|
+
if (t.isObjectExpression(node.declaration)) {
|
|
183
|
+
// Check each required property to see if it exists in the declaration
|
|
184
|
+
Object.entries(vars).forEach(([key, value]) => {
|
|
185
|
+
let propExists = node.declaration.properties.some((property) => t.isObjectProperty(property) &&
|
|
186
|
+
((t.isIdentifier(property.key) && property.key.name === key) ||
|
|
187
|
+
(t.isStringLiteral(property.key) && property.key.value === key)));
|
|
188
|
+
if (!propExists) {
|
|
189
|
+
// If the property doesn't exist, add it
|
|
190
|
+
node.declaration.properties.push(t.objectProperty(t.isValidIdentifier(key)
|
|
191
|
+
? t.identifier(key) : t.stringLiteral(key), valueToAstNode(value)));
|
|
192
|
+
modificationsMade = true;
|
|
174
193
|
}
|
|
175
194
|
});
|
|
176
195
|
}
|
|
177
|
-
}
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
if (modificationsMade) {
|
|
199
|
+
const output = generate(ast, {}, content);
|
|
200
|
+
fs.writeFileSync(getLocalConfigPath(), js_beautify(output.code.trim(), BEAUTIFY_OPTIONS), 'utf-8');
|
|
201
|
+
spinner.stop();
|
|
202
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-config-h-mgnl-vars-added"));
|
|
178
203
|
}
|
|
179
|
-
});
|
|
180
|
-
return { imports, commands };
|
|
181
|
-
};
|
|
182
|
-
const updateLocalConfig = (defaultConfig, localConfig) => {
|
|
183
|
-
const getMissingItems = (defaultItems, customItems, comparator) => {
|
|
184
|
-
return defaultItems.filter(defaultItem => !customItems.some(customItem => comparator(defaultItem, customItem)));
|
|
185
|
-
};
|
|
186
|
-
const mergeImports = (customImports, missingImports) => {
|
|
187
|
-
return customImports.concat(missingImports)
|
|
188
|
-
.map(i => `import ${i.importedNames} from "${i.importSource}";`).join('\n');
|
|
189
|
-
};
|
|
190
|
-
const missingImports = getMissingItems(defaultConfig.imports, localConfig.imports, (a, b) => a.importSource === b.importSource);
|
|
191
|
-
const missingCommands = getMissingItems(defaultConfig.commands, localConfig.commands, (a, b) => a.commandName === b.commandName);
|
|
192
|
-
const mergedImports = mergeImports(localConfig.imports, missingImports);
|
|
193
|
-
const updatedConfigContent = mergeCommandsWithConfigContent(localConfig.configContent, missingCommands);
|
|
194
|
-
writeToLocalConfigFile(mergedImports, updatedConfigContent);
|
|
195
|
-
};
|
|
196
|
-
const mergeCommandsWithConfigContent = (configContent, missingCommands) => {
|
|
197
|
-
const missingCommandsStr = missingCommands.map(c => `new ${c.commandName}()`).join(',\n');
|
|
198
|
-
const commandsPattern = /(commands\s*:\s*\[)([^\]]*?)(,\s*)?(\])/;
|
|
199
|
-
return configContent.replace(commandsPattern, (match, p1, p2, p3, p4) => {
|
|
200
|
-
const separator = (p2.trim() !== "" && missingCommandsStr.trim() !== "") ? "," : "";
|
|
201
|
-
return `${p1}${p2}${separator}${missingCommandsStr}${p4}`;
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
const writeToLocalConfigFile = (mergedImports, updatedConfigContent) => {
|
|
205
|
-
const importPattern = /import .* from ['"].*['"];\s*/g;
|
|
206
|
-
const configContentWithImports = `${mergedImports}\n\n${updatedConfigContent.replace(importPattern, '')}`;
|
|
207
|
-
writeConfigContent(configContentWithImports);
|
|
208
|
-
};
|
|
209
|
-
const writeConfigContent = (content) => {
|
|
210
|
-
const spinner = ora().start(`Updating mgnl.config.js`);
|
|
211
|
-
try {
|
|
212
|
-
fs.writeFileSync(getLocalConfigPath(), js_beautify(content.trim(), BEAUTIFY_OPTIONS), 'utf-8');
|
|
213
204
|
}
|
|
214
205
|
catch (e) {
|
|
215
206
|
spinner.stop();
|
|
216
|
-
logger === null || logger === void 0 ? void 0 : logger.error(
|
|
207
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-config-h-while-adding-vars"));
|
|
217
208
|
console.error(e);
|
|
218
209
|
}
|
|
219
|
-
|
|
220
|
-
logger === null || logger === void 0 ? void 0 : logger.info('mgnl.config.js updated');
|
|
221
|
-
};
|
|
210
|
+
});
|
package/dist/lib/download.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bundle, Credentials } from "../types/types.js";
|
|
2
|
-
export declare const downloadBundle: (bundle: Bundle, credentials: Credentials, dest: string | undefined) => Promise<string>;
|
|
3
|
-
export declare const getDownloadUrl: (bundle: Bundle, credentials: Credentials) => Promise<string>;
|
|
1
|
+
import { Bundle, Credentials, PluginOptions } from "../types/types.js";
|
|
2
|
+
export declare const downloadBundle: (bundle: Bundle, credentials: Credentials, dest: string | undefined, options: PluginOptions) => Promise<string>;
|
|
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>;
|
package/dist/lib/download.js
CHANGED
|
@@ -12,17 +12,20 @@ import fs from "fs-extra";
|
|
|
12
12
|
import axios from "axios";
|
|
13
13
|
import ProgressBar from "progress";
|
|
14
14
|
import inquirer from "inquirer";
|
|
15
|
-
import { logger } from "../jumpstart-plugin.js";
|
|
16
|
-
export const downloadBundle = (bundle, credentials, dest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
import { i18nInstance, logger } from "../jumpstart-plugin.js";
|
|
16
|
+
export const downloadBundle = (bundle, credentials, dest, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
try {
|
|
18
18
|
let url = bundle.url;
|
|
19
19
|
const downloadDest = dest ? dest : "./download-" + new Date().getTime();
|
|
20
20
|
let downloadUrl;
|
|
21
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-download-preparing", {
|
|
22
|
+
url
|
|
23
|
+
}));
|
|
21
24
|
if (path.parse(url).name === "tags") {
|
|
22
25
|
downloadUrl = yield selectTag(url, credentials);
|
|
23
26
|
}
|
|
24
27
|
else if (url.includes('https://nexus.magnolia-cms.com/service/rest/v1/search')) {
|
|
25
|
-
downloadUrl = yield getDownloadUrl(bundle, credentials);
|
|
28
|
+
downloadUrl = yield getDownloadUrl(bundle, credentials, options);
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
28
31
|
downloadUrl = url;
|
|
@@ -31,7 +34,7 @@ export const downloadBundle = (bundle, credentials, dest) => __awaiter(void 0, v
|
|
|
31
34
|
method: 'get',
|
|
32
35
|
responseType: 'stream',
|
|
33
36
|
};
|
|
34
|
-
if (credentials) {
|
|
37
|
+
if (credentials && credentials.username && credentials.password) {
|
|
35
38
|
opts.auth = credentials;
|
|
36
39
|
}
|
|
37
40
|
if (downloadDest) {
|
|
@@ -39,8 +42,16 @@ export const downloadBundle = (bundle, credentials, dest) => __awaiter(void 0, v
|
|
|
39
42
|
}
|
|
40
43
|
const tempDownload = path.join(downloadDest, bundle.name ? bundle.name : 'temp-' + new Date().getTime());
|
|
41
44
|
const target = fs.createWriteStream(tempDownload);
|
|
42
|
-
logger === null || logger === void 0 ? void 0 : logger.info("
|
|
45
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-download-starting", {
|
|
46
|
+
downloadUrl: downloadUrl
|
|
47
|
+
}));
|
|
43
48
|
const res = yield axios.get(downloadUrl, opts);
|
|
49
|
+
if (res.status !== 200) {
|
|
50
|
+
throw new Error(i18nInstance.t("info-download-status-error", {
|
|
51
|
+
downloadUrl: downloadUrl,
|
|
52
|
+
status: res.status
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
44
55
|
if (res.headers['content-length']) {
|
|
45
56
|
const len = parseInt(res.headers['content-length'], 10);
|
|
46
57
|
const bar = new ProgressBar('Downloading [:bar] :percent :etas', {
|
|
@@ -54,21 +65,27 @@ export const downloadBundle = (bundle, credentials, dest) => __awaiter(void 0, v
|
|
|
54
65
|
});
|
|
55
66
|
}
|
|
56
67
|
res.data.pipe(target);
|
|
57
|
-
res.data.on('error', (error) => {
|
|
58
|
-
throw new Error(error);
|
|
59
|
-
});
|
|
60
68
|
return new Promise((resolve) => {
|
|
61
|
-
|
|
62
|
-
logger === null || logger === void 0 ? void 0 : logger.info("
|
|
69
|
+
target.on('finish', () => {
|
|
70
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-download-finished"));
|
|
63
71
|
resolve(path.join('.', tempDownload));
|
|
64
72
|
});
|
|
73
|
+
target.on('error', (error) => {
|
|
74
|
+
target.close();
|
|
75
|
+
throw new Error(error);
|
|
76
|
+
});
|
|
77
|
+
res.data.on('error', (error) => {
|
|
78
|
+
target.close();
|
|
79
|
+
throw new Error(error);
|
|
80
|
+
});
|
|
65
81
|
});
|
|
66
82
|
}
|
|
67
83
|
catch (error) {
|
|
68
84
|
throw new Error(error);
|
|
69
85
|
}
|
|
70
86
|
});
|
|
71
|
-
export const getDownloadUrl = (bundle, credentials) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
export const getDownloadUrl = (bundle, credentials, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
var _a, _b, _c;
|
|
72
89
|
const opts = {
|
|
73
90
|
method: 'get',
|
|
74
91
|
responseType: 'json',
|
|
@@ -80,19 +97,63 @@ export const getDownloadUrl = (bundle, credentials) => __awaiter(void 0, void 0,
|
|
|
80
97
|
opts.auth = credentials;
|
|
81
98
|
}
|
|
82
99
|
try {
|
|
83
|
-
const
|
|
100
|
+
const url = new URL(bundle.url);
|
|
101
|
+
url.searchParams.set('prerelease', "false");
|
|
102
|
+
if (bundle.version) {
|
|
103
|
+
if (options.snapshot || bundle.version.toLowerCase().includes("snapshot")) {
|
|
104
|
+
url.searchParams.set('prerelease', "true");
|
|
105
|
+
}
|
|
106
|
+
if (options.magnoliaVersion) {
|
|
107
|
+
bundle.version = options.magnoliaVersion;
|
|
108
|
+
}
|
|
109
|
+
if (bundle.version.toLowerCase() !== "latest" && bundle.version.toLowerCase() !== "alpha" && bundle.version.toLowerCase() !== "beta") {
|
|
110
|
+
url.searchParams.set('maven.baseVersion', bundle.version);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const response = yield axios.get(url.toString(), opts);
|
|
84
114
|
const params = new URLSearchParams(bundle.url.split("?")[1]);
|
|
85
|
-
let
|
|
115
|
+
let item = response.data.items[0];
|
|
116
|
+
if (((_a = bundle.version) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "latest") {
|
|
117
|
+
item = response.data.items.find((item) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const itemVersion = (_a = item === null || item === void 0 ? void 0 : item.maven2) === null || _a === void 0 ? void 0 : _a.version;
|
|
120
|
+
return !(itemVersion === null || itemVersion === void 0 ? void 0 : itemVersion.includes("-alpha")) && !(itemVersion === null || itemVersion === void 0 ? void 0 : itemVersion.includes("-beta"));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else if (((_b = bundle.version) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === "alpha") {
|
|
124
|
+
item = response.data.items.find((item) => {
|
|
125
|
+
var _a;
|
|
126
|
+
const itemVersion = (_a = item === null || item === void 0 ? void 0 : item.maven2) === null || _a === void 0 ? void 0 : _a.version;
|
|
127
|
+
return itemVersion === null || itemVersion === void 0 ? void 0 : itemVersion.includes("-alpha");
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else if (((_c = bundle.version) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === "beta") {
|
|
131
|
+
item = response.data.items.find((item) => {
|
|
132
|
+
var _a;
|
|
133
|
+
const itemVersion = (_a = item === null || item === void 0 ? void 0 : item.maven2) === null || _a === void 0 ? void 0 : _a.version;
|
|
134
|
+
return itemVersion === null || itemVersion === void 0 ? void 0 : itemVersion.includes("-beta");
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (!item) {
|
|
138
|
+
throw new Error(i18nInstance.t('error-download-no-artifact-available', { version: bundle.version, interpolation: { escapeValue: false } }));
|
|
139
|
+
}
|
|
140
|
+
let downloadUrl = item.downloadUrl;
|
|
86
141
|
downloadUrl = downloadUrl === null || downloadUrl === void 0 ? void 0 : downloadUrl.split('/magnolia.');
|
|
87
|
-
downloadUrl = downloadUrl && `${downloadUrl[0]}/${params.get('repository')}
|
|
142
|
+
downloadUrl = downloadUrl && `${downloadUrl[0]}/${params.get('repository')}${item.path}`;
|
|
88
143
|
return downloadUrl;
|
|
89
144
|
}
|
|
90
145
|
catch (error) {
|
|
91
|
-
|
|
146
|
+
if (error.code === 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY') {
|
|
147
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-download-problem-accessing-url", {
|
|
148
|
+
url: bundle.url
|
|
149
|
+
}));
|
|
150
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-download-unable-to-get-local-issuer-certificate"));
|
|
151
|
+
}
|
|
152
|
+
throw new Error(error.message);
|
|
92
153
|
}
|
|
93
154
|
});
|
|
94
155
|
export const selectTag = (url, credentials) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
-
var
|
|
156
|
+
var _d;
|
|
96
157
|
const opts = {
|
|
97
158
|
method: 'get',
|
|
98
159
|
headers: {
|
|
@@ -103,8 +164,8 @@ export const selectTag = (url, credentials) => __awaiter(void 0, void 0, void 0,
|
|
|
103
164
|
opts.auth = credentials;
|
|
104
165
|
}
|
|
105
166
|
const res = yield axios.get(url, opts);
|
|
106
|
-
if (!((
|
|
107
|
-
throw new Error("
|
|
167
|
+
if (!((_d = res.data) === null || _d === void 0 ? void 0 : _d.values) || res.data.values.length <= 0) {
|
|
168
|
+
throw new Error(i18nInstance.t("error-download-no-tags"));
|
|
108
169
|
}
|
|
109
170
|
const { tag } = yield inquirer
|
|
110
171
|
.prompt([
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const evaluateCustomPrompts: (extensionsPath: string) => Promise<{
|
|
2
|
+
answers: import("inquirer").Answers;
|
|
3
|
+
executePostCommands: (context: any) => Promise<void>;
|
|
4
|
+
} | undefined>;
|
|
5
|
+
export declare const compileCustomPrompts: (answers: any, pattern?: string) => Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import fs from "fs-extra";
|
|
11
|
+
import path from "path";
|
|
12
|
+
import inquirer from "inquirer";
|
|
13
|
+
import { execa } from "execa";
|
|
14
|
+
import { parse } from 'yaml';
|
|
15
|
+
import { i18nInstance, logger } from "../jumpstart-plugin.js";
|
|
16
|
+
import ora from "ora";
|
|
17
|
+
import { determinePackageManager } from "./helper.js";
|
|
18
|
+
import { pathToFileURL } from "url";
|
|
19
|
+
import { globSync } from "glob";
|
|
20
|
+
import _ from "underscore";
|
|
21
|
+
function pause(milliSeconds) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
resolve();
|
|
26
|
+
}, milliSeconds);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function callExtensionFunction(func_1, context_1, name_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (func, context, name, delay = 200, retry = 0, maxRetry = 0) {
|
|
32
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-extensions-calling-fn", {
|
|
33
|
+
name: name
|
|
34
|
+
}));
|
|
35
|
+
try {
|
|
36
|
+
yield func(context);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (retry === maxRetry) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-extensions-calling-fn-retry", {
|
|
43
|
+
name: name,
|
|
44
|
+
retry: retry,
|
|
45
|
+
maxRetry: maxRetry,
|
|
46
|
+
delay: delay
|
|
47
|
+
}));
|
|
48
|
+
yield pause(delay);
|
|
49
|
+
yield callExtensionFunction(func, context, name, delay, retry + 1, maxRetry);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function executePostCommands() {
|
|
54
|
+
return __awaiter(this, arguments, void 0, function* (cmds = [], extensions, context) {
|
|
55
|
+
for (let cmd of cmds) {
|
|
56
|
+
const func = extensions[cmd.function];
|
|
57
|
+
if (func) {
|
|
58
|
+
try {
|
|
59
|
+
yield callExtensionFunction(func, context, cmd.function, cmd.delay, 0, cmd.retry);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-extensions-fn-not-found", {
|
|
67
|
+
function: cmd.function
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// evaluate the given yaml file and create cli prompts out of it, return the answers
|
|
74
|
+
export const evaluateCustomPrompts = (extensionsPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
if (!fs.existsSync(extensionsPath)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const doc = parse(fs.readFileSync(extensionsPath, 'utf8'));
|
|
79
|
+
const baseDir = path.parse(extensionsPath).dir;
|
|
80
|
+
const packageJson = path.join(baseDir, 'package.json');
|
|
81
|
+
if (fs.existsSync(packageJson)) {
|
|
82
|
+
const npmISpinner = ora().start(i18nInstance.t("ora-installing-ext-dep"));
|
|
83
|
+
const packageManager = determinePackageManager(baseDir);
|
|
84
|
+
try {
|
|
85
|
+
yield execa(packageManager, ["install"], {
|
|
86
|
+
buffer: true,
|
|
87
|
+
cwd: baseDir
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
npmISpinner.stop();
|
|
92
|
+
logger === null || logger === void 0 ? void 0 : logger.error(i18nInstance.t("error-extensions-install-fail", {
|
|
93
|
+
packageManager: packageManager
|
|
94
|
+
}));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
npmISpinner.stop();
|
|
98
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-extensions-install-done"));
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const extensions = doc.extend ? yield import(pathToFileURL(path.join(baseDir, doc.extend)).href) : null;
|
|
102
|
+
return {
|
|
103
|
+
answers: doc.prompts ? yield inquirer.prompt(doc.prompts) : {},
|
|
104
|
+
executePostCommands: (context) => __awaiter(void 0, void 0, void 0, function* () { var _a; return yield executePostCommands((_a = doc === null || doc === void 0 ? void 0 : doc.commands) === null || _a === void 0 ? void 0 : _a.post, extensions, context); })
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
export const compileCustomPrompts = (answers_1, ...args_1) => __awaiter(void 0, [answers_1, ...args_1], void 0, function* (answers, pattern = '**/**/**/*.{yaml,tsx,ts,js,jsx,vue,md,json}') {
|
|
112
|
+
const init = globSync(pattern, { ignore: 'node_modules/**' }).map(itm => path.join(process.cwd(), itm));
|
|
113
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(process.cwd(), './package.json'), 'utf8'));
|
|
114
|
+
pkg.answers = answers;
|
|
115
|
+
for (const item of init) {
|
|
116
|
+
try {
|
|
117
|
+
const file = fs.readFileSync(item, 'utf8');
|
|
118
|
+
const doc = _.template(file)(pkg);
|
|
119
|
+
fs.outputFileSync(item, doc, 'utf8');
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
package/dist/lib/extract.js
CHANGED
|
@@ -13,10 +13,10 @@ import walk from "walk";
|
|
|
13
13
|
import fs from "fs-extra";
|
|
14
14
|
import { PostCommands } from "../types/types.js";
|
|
15
15
|
import url from "url";
|
|
16
|
-
import { logger } from "../jumpstart-plugin.js";
|
|
16
|
+
import { i18nInstance, logger } from "../jumpstart-plugin.js";
|
|
17
17
|
export const extract = (bundle, file, command) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
var _a;
|
|
19
|
-
logger === null || logger === void 0 ? void 0 : logger.info(
|
|
19
|
+
logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-extract-extracting"));
|
|
20
20
|
const { dest = "./", type } = bundle;
|
|
21
21
|
const unzipFolder = "temp-" + new Date().getTime();
|
|
22
22
|
yield decompress(file, unzipFolder);
|
|
@@ -28,7 +28,15 @@ export const extract = (bundle, file, command) => __awaiter(void 0, void 0, void
|
|
|
28
28
|
yield extractApacheTomcat(dest, unzipFolder);
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
|
|
31
|
+
let sourceFolder = unzipFolder;
|
|
32
|
+
if (command === PostCommands.ExtractAndUnfold) {
|
|
33
|
+
const firstDir = fs.readdirSync(unzipFolder).find(item => {
|
|
34
|
+
const itemPath = path.join(unzipFolder, item);
|
|
35
|
+
return fs.statSync(itemPath).isDirectory();
|
|
36
|
+
});
|
|
37
|
+
sourceFolder = firstDir ? path.join(unzipFolder, firstDir) : unzipFolder;
|
|
38
|
+
}
|
|
39
|
+
fs.copySync(sourceFolder, dest, { overwrite: true });
|
|
32
40
|
}
|
|
33
41
|
fs.rmSync(unzipFolder, { recursive: true, force: true });
|
|
34
42
|
fs.rmSync(path.dirname(file), { recursive: true, force: true });
|
|
@@ -48,7 +56,7 @@ export const findExtractedApacheTomcatDir = (p) => {
|
|
|
48
56
|
next();
|
|
49
57
|
});
|
|
50
58
|
walker.on('end', function () {
|
|
51
|
-
return reject(new Error("apache-tomcat
|
|
59
|
+
return reject(new Error(i18nInstance.t("error-extract-apache-tomcat-not-found")));
|
|
52
60
|
});
|
|
53
61
|
});
|
|
54
62
|
};
|
package/dist/lib/helper.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Credentials } from "../types/types.js";
|
|
2
|
+
import { i18n } from "i18next";
|
|
3
|
+
export declare function initI18n(pluginName: string, namespace?: string): i18n;
|
|
2
4
|
export declare const handleLightModulesFolder: () => Promise<void>;
|
|
3
5
|
export declare const findLightModulesFolder: (p: string) => Promise<unknown>;
|
|
4
6
|
export declare const findWebAppsList: (apacheTomcatPath: string) => string[];
|
|
5
|
-
export declare const installAdditionalPlugins: (plugins: Array<PluginRequirement>) => Promise<void>;
|
|
6
7
|
export declare const initializeNodeProject: () => Promise<void>;
|
|
7
|
-
export declare const installPackage: (packageManager: string, packageReference: string, packageName?: string) => Promise<boolean>;
|
|
8
|
+
export declare const installPackage: (packageManager: string, packageReference: string, packageName?: string, credentials?: Credentials) => Promise<boolean>;
|
|
8
9
|
export declare const isValidURL: (str: string) => boolean;
|
|
9
10
|
export declare const extractRepoName: (gitUrl: string) => string | null;
|
|
10
11
|
export declare const determinePackageManager: (baseDirectory?: string) => "yarn" | "npm";
|
|
12
|
+
export declare const askForCredentials: () => Promise<Credentials>;
|