@magnolia/cli-jumpstart-plugin 1.0.0-preview.5 → 1.0.0-preview.6

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 CHANGED
@@ -43,7 +43,7 @@ magnolia-cli jumpstart --template "headless/minimal-headless-spa-demos/dx-core"
43
43
 
44
44
  **Project templates list:**
45
45
 
46
- The **jumpstart** plugin relies on a list of predefined project templates stored in an external [repository](https://git.magnolia-cms.com/projects/SERVICES/repos/cli-project-templates/raw/projectTemplates.json).
46
+ The **jumpstart** plugin relies on a list of predefined project templates stored in an external [repository](https://bitbucket.org/magnolia-cms/cli-project-templates/raw/HEAD/projectTemplates.json).
47
47
  You can specify your own project templates list with the *--project-templates-path* command:
48
48
 
49
49
  ```bash
@@ -20,6 +20,8 @@ export default class JumpstartPlugin extends PluginTemplate {
20
20
  promptTemplateSelection(templates: Array<Template>, names?: string[]): Promise<TemplateWithoutChildren | undefined>;
21
21
  findTemplateByIdentifier(identifier: string): TemplateWithoutChildren | undefined;
22
22
  chooseTemplate(options: PluginOptions): Promise<void>;
23
+ private isFlag;
24
+ private checkFlagsArguments;
23
25
  init(winstonLogger: Logger): Promise<void>;
24
26
  start(options: PluginOptions): Promise<void>;
25
27
  stop(): Promise<void>;
@@ -119,7 +119,7 @@ export default class JumpstartPlugin extends PluginTemplate {
119
119
  this.projectTemplates = requireFn(path.resolve(options.projectTemplatesPath)).projectTemplates;
120
120
  }
121
121
  else {
122
- const res = yield axios.get("https://bitbucket.org/magnolia-cms/project-templates/raw/HEAD/projectTemplates.json");
122
+ const res = yield axios.get("https://bitbucket.org/magnolia-cms/cli-project-templates/raw/HEAD/projectTemplates.json");
123
123
  this.projectTemplates = res.data.projectTemplates;
124
124
  }
125
125
  }
@@ -193,6 +193,19 @@ export default class JumpstartPlugin extends PluginTemplate {
193
193
  }
194
194
  });
195
195
  }
196
+ isFlag(value) {
197
+ return this.options.some(it => it.long === value || it.short === value);
198
+ }
199
+ checkFlagsArguments(options) {
200
+ Object.keys(options).forEach(key => {
201
+ const value = options[key];
202
+ if (this.isFlag(value)) {
203
+ const optionLong = "--" + key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
204
+ const option = this.options.find(it => it.long === optionLong);
205
+ throw new Error(i18nInstance.t('error-option-param-is-flag', { option: option === null || option === void 0 ? void 0 : option.flags, value: value }));
206
+ }
207
+ });
208
+ }
196
209
  init(winstonLogger) {
197
210
  return __awaiter(this, void 0, void 0, function* () {
198
211
  logger = winstonLogger;
@@ -201,6 +214,7 @@ export default class JumpstartPlugin extends PluginTemplate {
201
214
  start(options) {
202
215
  return __awaiter(this, void 0, void 0, function* () {
203
216
  logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-jumpstart_started"));
217
+ this.checkFlagsArguments(options);
204
218
  yield this.setProjectTemplates(options);
205
219
  yield this.chooseTemplate(options);
206
220
  });
@@ -108,7 +108,7 @@ function createMgnlConfigFile() {
108
108
  : '';
109
109
  const mgnlConfigSufix = `
110
110
  // Here you can add plugins you want to use with MGNL CLI
111
- commands: []
111
+ plugins: []
112
112
  };`;
113
113
  const mgnlConfigContent = mgnlConfigPrefix + logger + mgnlConfigSufix;
114
114
  writeConfigContent(mgnlConfigContent);
@@ -117,7 +117,7 @@ function createSimpleMgnlConfigFile() {
117
117
  const mgnlConfigContent = `
118
118
  export default {
119
119
  // Here you can add plugins you want to use with MGNL CLI
120
- commands: []
120
+ plugins: []
121
121
  };`;
122
122
  writeConfigContent(mgnlConfigContent);
123
123
  }
@@ -85,7 +85,7 @@ export const downloadBundle = (bundle, credentials, dest, options) => __awaiter(
85
85
  }
86
86
  });
87
87
  export const getDownloadUrl = (bundle, credentials, options) => __awaiter(void 0, void 0, void 0, function* () {
88
- var _a, _b, _c;
88
+ var _a, _b, _c, _d, _e;
89
89
  const opts = {
90
90
  method: 'get',
91
91
  responseType: 'json',
@@ -105,9 +105,13 @@ export const getDownloadUrl = (bundle, credentials, options) => __awaiter(void 0
105
105
  }
106
106
  if (options.magnoliaVersion) {
107
107
  bundle.version = options.magnoliaVersion;
108
+ if (bundle.version.startsWith('6.3') && bundle.alternative) {
109
+ url.searchParams.set('maven.groupId', bundle.alternative.groupId);
110
+ url.searchParams.set('maven.artifactId', bundle.alternative.artifactId);
111
+ }
108
112
  }
109
113
  if (bundle.version.toLowerCase() !== "latest" && bundle.version.toLowerCase() !== "alpha" && bundle.version.toLowerCase() !== "beta") {
110
- url.searchParams.set('maven.baseVersion', bundle.version);
114
+ url.searchParams.set('maven.baseVersion', options.snapshot ? bundle.version + "-SNAPSHOT" : bundle.version);
111
115
  }
112
116
  }
113
117
  const response = yield axios.get(url.toString(), opts);
@@ -137,6 +141,7 @@ export const getDownloadUrl = (bundle, credentials, options) => __awaiter(void 0
137
141
  if (!item) {
138
142
  throw new Error(i18nInstance.t('error-download-no-artifact-available', { version: bundle.version, interpolation: { escapeValue: false } }));
139
143
  }
144
+ bundle.version = (_e = (_d = item === null || item === void 0 ? void 0 : item.maven2) === null || _d === void 0 ? void 0 : _d.version) !== null && _e !== void 0 ? _e : bundle.version;
140
145
  let downloadUrl = item.downloadUrl;
141
146
  downloadUrl = downloadUrl === null || downloadUrl === void 0 ? void 0 : downloadUrl.split('/magnolia.');
142
147
  downloadUrl = downloadUrl && `${downloadUrl[0]}/${params.get('repository')}${item.path}`;
@@ -153,7 +158,7 @@ export const getDownloadUrl = (bundle, credentials, options) => __awaiter(void 0
153
158
  }
154
159
  });
155
160
  export const selectTag = (url, credentials) => __awaiter(void 0, void 0, void 0, function* () {
156
- var _d;
161
+ var _f;
157
162
  const opts = {
158
163
  method: 'get',
159
164
  headers: {
@@ -164,7 +169,7 @@ export const selectTag = (url, credentials) => __awaiter(void 0, void 0, void 0,
164
169
  opts.auth = credentials;
165
170
  }
166
171
  const res = yield axios.get(url, opts);
167
- if (!((_d = res.data) === null || _d === void 0 ? void 0 : _d.values) || res.data.values.length <= 0) {
172
+ if (!((_f = res.data) === null || _f === void 0 ? void 0 : _f.values) || res.data.values.length <= 0) {
168
173
  throw new Error(i18nInstance.t("error-download-no-tags"));
169
174
  }
170
175
  const { tag } = yield inquirer
@@ -14,6 +14,7 @@ import fs from "fs-extra";
14
14
  import { PostCommands } from "../types/types.js";
15
15
  import url from "url";
16
16
  import { i18nInstance, logger } from "../jumpstart-plugin.js";
17
+ import { handleMicroprofileConfig } from "./handleMicroprofileConfig.js";
17
18
  export const extract = (bundle, file, command) => __awaiter(void 0, void 0, void 0, function* () {
18
19
  var _a;
19
20
  logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t("info-extract-extracting"));
@@ -37,6 +38,7 @@ export const extract = (bundle, file, command) => __awaiter(void 0, void 0, void
37
38
  sourceFolder = firstDir ? path.join(unzipFolder, firstDir) : unzipFolder;
38
39
  }
39
40
  fs.copySync(sourceFolder, dest, { overwrite: true });
41
+ yield handleMicroprofileConfig(bundle, dest);
40
42
  }
41
43
  fs.rmSync(unzipFolder, { recursive: true, force: true });
42
44
  fs.rmSync(path.dirname(file), { recursive: true, force: true });
@@ -0,0 +1,3 @@
1
+ import { Bundle } from "../types/types";
2
+ export declare const handleMicroprofileConfig: (bundle: Bundle, dest: string) => Promise<void>;
3
+ export declare function convertObjectToProperties(obj: any): any[];
@@ -0,0 +1,61 @@
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";
11
+ import path from "path";
12
+ import { getMicroprofileConfigLocation } from "./helper.js";
13
+ import { i18nInstance, logger } from "../jumpstart-plugin.js";
14
+ export const handleMicroprofileConfig = (bundle, dest) => __awaiter(void 0, void 0, void 0, function* () {
15
+ var _a;
16
+ if (!((_a = bundle.version) === null || _a === void 0 ? void 0 : _a.startsWith("6.3")))
17
+ return;
18
+ const tomcatPath = path.join(path.resolve(dest), '../../');
19
+ const webappName = path.basename(dest);
20
+ const pathToMicroprofileConfig = getMicroprofileConfigLocation(tomcatPath, webappName);
21
+ processMicroprofileConfigFile(pathToMicroprofileConfig);
22
+ });
23
+ export function convertObjectToProperties(obj) {
24
+ const props = [];
25
+ Object.keys(obj).forEach((key) => {
26
+ const val = obj[key];
27
+ if (val && typeof val === 'object' && !Array.isArray(val)) {
28
+ const children = convertObjectToProperties(val);
29
+ for (const child of children) {
30
+ props.push(key + '.' + child);
31
+ }
32
+ }
33
+ else {
34
+ props.push(key + '=' + val);
35
+ }
36
+ });
37
+ return props;
38
+ }
39
+ function createMicroprofileConfigFile(file) {
40
+ const microprofileConfig = {
41
+ magnolia: {
42
+ publishing: {
43
+ 'receivers[0]': {
44
+ name: 'magnoliaPublic8080',
45
+ url: 'http://localhost:8080/magnoliaPublic',
46
+ enabled: true
47
+ }
48
+ }
49
+ }
50
+ };
51
+ logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t('create-microprofile--info-creating-file', { file }));
52
+ return fs.writeFileSync(file, convertObjectToProperties(microprofileConfig).join('\n'), 'utf8');
53
+ }
54
+ function processMicroprofileConfigFile(file) {
55
+ if (fs.existsSync(file)) {
56
+ logger === null || logger === void 0 ? void 0 : logger.info(i18nInstance.t('create-microprofile--info-file-exists-skipping'));
57
+ }
58
+ else {
59
+ createMicroprofileConfigFile(file);
60
+ }
61
+ }
@@ -10,3 +10,5 @@ export declare const isValidURL: (str: string) => boolean;
10
10
  export declare const extractRepoName: (gitUrl: string) => string | null;
11
11
  export declare const determinePackageManager: (baseDirectory?: string) => "yarn" | "npm";
12
12
  export declare const askForCredentials: () => Promise<Credentials>;
13
+ export declare function getWebAppConfigDefaultFolderLocation(tomcatFolder: string, instance: string): string;
14
+ export declare function getMicroprofileConfigLocation(tomcatFolder: string, instance: string): string;
@@ -235,3 +235,9 @@ export const askForCredentials = () => __awaiter(void 0, void 0, void 0, functio
235
235
  }
236
236
  ]);
237
237
  });
238
+ export function getWebAppConfigDefaultFolderLocation(tomcatFolder, instance) {
239
+ return path.join(tomcatFolder, 'webapps', instance, 'WEB-INF', 'config', 'default');
240
+ }
241
+ export function getMicroprofileConfigLocation(tomcatFolder, instance) {
242
+ return path.join(getWebAppConfigDefaultFolderLocation(tomcatFolder, instance), 'microprofile-config.properties');
243
+ }
@@ -60,6 +60,7 @@
60
60
  "error-helper-webapp-props-update-error": "An error occurred while updating 'magnolia.properties': {{errorMsg}}",
61
61
  "error-helper-lm-not-found": "light-modules was not found",
62
62
  "error-helper-fail-to-install-package": "Failed to install {{packageName}}",
63
+ "error-option-param-is-flag": "option \"{{option}}\" argument missing. Provided value: \"{{value}}\" is a flag",
63
64
 
64
65
  "ora-updating-mgnl-config": "Updating mgnl.config.js",
65
66
  "ora-adding-shared-vars": "Adding variables to mgnl.config.js",
@@ -69,5 +70,8 @@
69
70
  "ora-creating-pj": "Creating package.json",
70
71
  "ora-installing-package": "Installing {{packageName}}",
71
72
 
72
- "install-plugin-with-args-text": "\twith following args: {{pluginArgs}}\n"
73
+ "install-plugin-with-args-text": "\twith following args: {{pluginArgs}}\n",
74
+
75
+ "create-microprofile--info-file-exists-skipping": "File microprofile-config.properties already exists. Skipping...",
76
+ "create-microprofile--info-creating-file": "Creating microprofile-config.properties at {{file}}"
73
77
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magnolia/cli-jumpstart-plugin",
3
- "version": "1.0.0-preview.5",
3
+ "version": "1.0.0-preview.6",
4
4
  "description": "Plugin to set up new projects using predefined templates and bundles. Easily select and configure project templates, and let the plugin handle bundle downloads, extraction, and post-command execution.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,6 +13,10 @@ export interface Bundle {
13
13
  downloadDest?: string;
14
14
  name?: string;
15
15
  version?: string;
16
+ alternative: {
17
+ groupId: string;
18
+ artifactId: string;
19
+ };
16
20
  }
17
21
  export interface TemplateBase {
18
22
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magnolia/cli-jumpstart-plugin",
3
- "version": "1.0.0-preview.5",
3
+ "version": "1.0.0-preview.6",
4
4
  "description": "Plugin to set up new projects using predefined templates and bundles. Easily select and configure project templates, and let the plugin handle bundle downloads, extraction, and post-command execution.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {