@axinom/mosaic-cli 0.33.0-rc.9 → 0.33.1
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/dist/cli/index.js +3 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/create/command.d.ts +3 -0
- package/dist/commands/create/command.js +95 -0
- package/dist/commands/create/command.js.map +1 -0
- package/dist/commands/create/createSolution.d.ts +2 -0
- package/dist/commands/create/createSolution.js +128 -0
- package/dist/commands/create/createSolution.js.map +1 -0
- package/dist/commands/create/defaultValues.d.ts +5 -0
- package/dist/commands/create/defaultValues.js +9 -0
- package/dist/commands/create/defaultValues.js.map +1 -0
- package/dist/commands/create/helpers/git.d.ts +3 -0
- package/dist/commands/create/helpers/git.js +63 -0
- package/dist/commands/create/helpers/git.js.map +1 -0
- package/dist/commands/create/helpers/logger.d.ts +18 -0
- package/dist/commands/create/helpers/logger.js +45 -0
- package/dist/commands/create/helpers/logger.js.map +1 -0
- package/dist/commands/create/helpers/types.d.ts +15 -0
- package/dist/commands/create/helpers/types.js +3 -0
- package/dist/commands/create/helpers/types.js.map +1 -0
- package/dist/commands/create/runQuestionaire.d.ts +7 -0
- package/dist/commands/create/runQuestionaire.js +87 -0
- package/dist/commands/create/runQuestionaire.js.map +1 -0
- package/package.json +11 -5
- package/src/cli/index.ts +3 -1
- package/src/commands/create/command.ts +126 -0
- package/src/commands/create/createSolution.ts +154 -0
- package/src/commands/create/defaultValues.ts +5 -0
- package/src/commands/create/helpers/git.ts +81 -0
- package/src/commands/create/helpers/logger.ts +37 -0
- package/src/commands/create/helpers/types.ts +18 -0
- package/src/commands/create/runQuestionaire.ts +96 -0
package/dist/cli/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const yargs = require("yargs");
|
|
6
6
|
const apply_templates_1 = require("../commands/apply-templates");
|
|
7
7
|
const create_extension_config_1 = require("../commands/create-extension-config");
|
|
8
|
+
const command_1 = require("../commands/create/command");
|
|
8
9
|
const get_access_token_1 = require("../commands/get-access-token");
|
|
9
10
|
const graphql_diff_1 = require("../commands/graphql-diff");
|
|
10
11
|
const hosting_1 = require("../commands/hosting");
|
|
@@ -28,7 +29,8 @@ const run = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
|
28
29
|
.command(graphql_diff_1.graphqlDiff)
|
|
29
30
|
.command(hosting_1.hosting)
|
|
30
31
|
.command(unpublish_pilet_1.unpublishPilet)
|
|
31
|
-
.command(service_1.service)
|
|
32
|
+
.command(service_1.service)
|
|
33
|
+
.command(command_1.createSolutionCommand);
|
|
32
34
|
//adding cli extensions:
|
|
33
35
|
yield Promise.all((0, create_extension_config_1.getExtensions)().map((library) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
34
36
|
try {
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,iEAA6D;AAC7D,iFAG6C;AAC7C,mEAA8D;AAC9D,2DAAuD;AACvD,iDAA8C;AAC9C,yDAAqD;AACrD,mDAA+C;AAC/C,iDAA6C;AAC7C,2EAAqE;AACrE,iDAA8C;AAC9C,iEAA6D;AAEtD,MAAM,GAAG,GAAG,GAAwB,EAAE;IAC3C,KAAK;SACF,UAAU,CAAC,QAAQ,CAAC;SACpB,GAAG,EAAE;SACL,OAAO,CAAC,gCAAc,CAAC;SACvB,OAAO,CAAC,iCAAc,CAAC;SACvB,OAAO,CAAC,wCAAiB,CAAC;SAC1B,OAAO,CAAC,gBAAM,CAAC;SACf,OAAO,CAAC,wBAAU,CAAC;SACnB,OAAO,CAAC,kBAAO,CAAC;SAChB,OAAO,CAAC,sDAA4B,CAAC;SACrC,OAAO,CAAC,0BAAW,CAAC;SACpB,OAAO,CAAC,iBAAO,CAAC;SAChB,OAAO,CAAC,gCAAc,CAAC;S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CAAC;IAEF,KAAK;SACF,aAAa,EAAE;SACf,IAAI,EAAE;SACN,MAAM,CAAC,wDAAwD,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC,CAAA,CAAC;AArCW,QAAA,GAAG,OAqCd"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSolutionCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
6
|
+
const createSolution_1 = require("./createSolution");
|
|
7
|
+
const defaultValues_1 = require("./defaultValues");
|
|
8
|
+
const logger_1 = require("./helpers/logger");
|
|
9
|
+
const runQuestionaire_1 = require("./runQuestionaire");
|
|
10
|
+
exports.createSolutionCommand = {
|
|
11
|
+
command: 'create',
|
|
12
|
+
describe: 'Creates a new Mosaic solution.',
|
|
13
|
+
builder: (yargs) => yargs
|
|
14
|
+
.positional('projectName', {
|
|
15
|
+
describe: `The name of the solution. Default: ${defaultValues_1.defaultValues.projectName}`,
|
|
16
|
+
type: 'string',
|
|
17
|
+
})
|
|
18
|
+
.positional('target', {
|
|
19
|
+
describe: `The root folder for the solution. Default: ${defaultValues_1.defaultValues.target}`,
|
|
20
|
+
type: 'string',
|
|
21
|
+
})
|
|
22
|
+
.option('default', {
|
|
23
|
+
alias: 'y',
|
|
24
|
+
describe: 'Bypass prompts and use default options',
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
})
|
|
27
|
+
.option('noGit', {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
describe: 'Do not initialize a new git repository',
|
|
30
|
+
})
|
|
31
|
+
.option('noInstall', {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
describe: 'Do not run package manager install command',
|
|
34
|
+
})
|
|
35
|
+
.option('installationType', {
|
|
36
|
+
choices: ['stable', 'experimental', 'custom'],
|
|
37
|
+
type: 'string',
|
|
38
|
+
})
|
|
39
|
+
.option('branch', {
|
|
40
|
+
type: 'string',
|
|
41
|
+
})
|
|
42
|
+
.option('debug', {
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
describe: 'Show debug logs',
|
|
45
|
+
}),
|
|
46
|
+
handler: (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
(0, logger_1.setDebug)(!!options.debug);
|
|
49
|
+
options.projectName = options._[1];
|
|
50
|
+
options.target = options._[2];
|
|
51
|
+
logger_1.logger.log('Welcome to Axinom Mosaic!');
|
|
52
|
+
logger_1.logger.log("We're going to create a new Mosaic solution for you.\n");
|
|
53
|
+
try {
|
|
54
|
+
if (options.default) {
|
|
55
|
+
yield (0, createSolution_1.createSolution)(Object.assign({ projectName: (_a = options.projectName) !== null && _a !== void 0 ? _a : defaultValues_1.defaultValues.projectName, target: (_b = options.target) !== null && _b !== void 0 ? _b : defaultValues_1.defaultValues.target, noGit: !!options.noGit, noInstall: !!options.noInstall, debug: !!options.debug, default: true }, (yield getGitReference(options))));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
logger_1.logger.log('We just need a couple more things from you before we can get started:\n');
|
|
59
|
+
const answers = yield (0, runQuestionaire_1.runQuestionaire)(options);
|
|
60
|
+
// new line
|
|
61
|
+
console.log();
|
|
62
|
+
yield (0, createSolution_1.createSolution)(Object.assign({ projectName: (_c = answers.projectName) !== null && _c !== void 0 ? _c : defaultValues_1.defaultValues.projectName, target: (_d = answers.target) !== null && _d !== void 0 ? _d : defaultValues_1.defaultValues.target, noGit: !!answers.noGit, noInstall: !!answers.noInstall, debug: !!options.debug, default: false }, (yield getGitReference(answers))));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof prompts_1.ExitPromptError) {
|
|
67
|
+
logger_1.logger.error('\nCreation of the solution was cancelled.');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
logger_1.logger.error('\nFailed to create a new Mosaic solution');
|
|
71
|
+
}
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
logger_1.logger.log('\nSuccessfully created your Mosaic solution 🎉');
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
const getGitReference = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
if (options.branch) {
|
|
79
|
+
return { gitReference: options.branch, gitReferenceType: 'heads' };
|
|
80
|
+
}
|
|
81
|
+
if (options.installationType === 'experimental') {
|
|
82
|
+
// TODO: remove the logic here and always pull `main` after branching model is switched
|
|
83
|
+
const devBranchRequest = yield fetch('https://api.github.com/repos/Axinom/mosaic-media-template/branches/dev');
|
|
84
|
+
const devBranchExists = devBranchRequest.ok;
|
|
85
|
+
const gitReference = devBranchExists ? 'dev' : 'main';
|
|
86
|
+
return { gitReference, gitReferenceType: 'heads' };
|
|
87
|
+
}
|
|
88
|
+
const lastReleaseRequest = yield fetch('https://api.github.com/repos/Axinom/mosaic-media-template/releases/latest');
|
|
89
|
+
const latestRelease = yield lastReleaseRequest.json();
|
|
90
|
+
return {
|
|
91
|
+
gitReference: latestRelease.tag_name,
|
|
92
|
+
gitReferenceType: 'tags',
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/commands/create/command.ts"],"names":[],"mappings":";;;;AAAA,+CAAoD;AAEpD,qDAAkD;AAClD,mDAAgD;AAChD,6CAAoD;AAEpD,uDAAoD;AAEvC,QAAA,qBAAqB,GAAuC;IACvE,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,gCAAgC;IAC1C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CACjB,KAAK;SACF,UAAU,CAAC,aAAa,EAAE;QACzB,QAAQ,EAAE,sCAAsC,6BAAa,CAAC,WAAW,EAAE;QAC3E,IAAI,EAAE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OAAmB,EAIlB,EAAE;IACH,IAAI,OAAO,CAAC,MAAM,EAAE;QAClB,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;KACpE;IACD,IAAI,OAAO,CAAC,gBAAgB,KAAK,cAAc,EAAE;QAC/C,uFAAuF;QACvF,MAAM,gBAAgB,GAAG,MAAM,KAAK,CAClC,wEAAwE,CACzE,CAAC;QACF,MAAM,eAAe,GAAG,gBAAgB,CAAC,EAAE,CAAC;QAC5C,MAAM,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;QAEtD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;KACpD;IAED,MAAM,kBAAkB,GAAG,MAAM,KAAK,CACpC,2EAA2E,CAC5E,CAAC;IACF,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC,IAAI,EAAE,CAAC;IAEtD,OAAO;QACL,YAAY,EAAE,aAAa,CAAC,QAAQ;QACpC,gBAAgB,EAAE,MAAM;KACzB,CAAC;AACJ,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSolution = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const simple_git_1 = require("simple-git");
|
|
9
|
+
const tar = require("tar");
|
|
10
|
+
const zlib_1 = require("zlib");
|
|
11
|
+
const git_1 = require("./helpers/git");
|
|
12
|
+
const logger = require("./helpers/logger");
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
14
|
+
const getOra = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return (yield import('ora')).default; });
|
|
15
|
+
const createSolution = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
logger.debug('CreateSolution options', JSON.stringify(options));
|
|
17
|
+
yield downloadAndUnzipTemplate(options);
|
|
18
|
+
process.chdir(options.target);
|
|
19
|
+
yield adjustSolution(options);
|
|
20
|
+
if (!options.noGit) {
|
|
21
|
+
yield initializeGit(options);
|
|
22
|
+
}
|
|
23
|
+
if (!options.noInstall) {
|
|
24
|
+
yield installDependencies(options);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.createSolution = createSolution;
|
|
28
|
+
const downloadAndUnzipTemplate = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const downloadOra = (yield getOra())('Downloading the template...');
|
|
30
|
+
downloadOra.start();
|
|
31
|
+
const url = `https://github.com/Axinom/mosaic-media-template/archive/refs/${options.gitReferenceType}/${options.gitReference}.tar.gz`;
|
|
32
|
+
const response = yield fetch(url);
|
|
33
|
+
if (response.ok) {
|
|
34
|
+
downloadOra.succeed('Template downloaded');
|
|
35
|
+
yield extractArchive(response, options);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
downloadOra.fail(`Failed to download the template ('${response.statusText}')`);
|
|
39
|
+
logger.debug(`Failed to download the template from ${url}`, JSON.stringify(response));
|
|
40
|
+
throw new Error(response.statusText);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const extractArchive = (response, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
const unzipOra = (yield getOra())('Unzipping the template...');
|
|
45
|
+
const buffer = yield response.arrayBuffer();
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const targetPath = path.resolve(options.target);
|
|
48
|
+
fs.mkdirSync(targetPath, { recursive: true });
|
|
49
|
+
const gunzip = (0, zlib_1.createGunzip)();
|
|
50
|
+
const extract = tar.extract({ cwd: targetPath, strip: 1 });
|
|
51
|
+
gunzip.on('data', (data) => extract.write(data));
|
|
52
|
+
gunzip.on('end', () => {
|
|
53
|
+
extract.end();
|
|
54
|
+
});
|
|
55
|
+
gunzip.on('error', (err) => {
|
|
56
|
+
unzipOra.fail('Failed to unzip the template');
|
|
57
|
+
logger.error(err);
|
|
58
|
+
reject(err);
|
|
59
|
+
});
|
|
60
|
+
extract.on('finish', () => {
|
|
61
|
+
unzipOra.succeed('Template extracted');
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
gunzip.write(Buffer.from(buffer));
|
|
65
|
+
gunzip.end();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
const adjustSolution = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const adjustOra = (yield getOra())('Adjusting package.json...').start();
|
|
70
|
+
try {
|
|
71
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
72
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
73
|
+
packageJson.name = options.projectName;
|
|
74
|
+
packageJson.mosaic = {
|
|
75
|
+
baseVersion: `${yield (0, git_1.getCommitId)(options)} (${options.gitReference})`,
|
|
76
|
+
};
|
|
77
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
78
|
+
adjustOra.succeed('package.json adjusted');
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
adjustOra.fail('Failed to adjust package.json');
|
|
82
|
+
logger.error(error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const initializeGit = (_options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
const gitOra = (yield getOra())('Initializing git repository...').start();
|
|
87
|
+
try {
|
|
88
|
+
const git = (0, simple_git_1.simpleGit)();
|
|
89
|
+
yield git.init().add('./*').commit('Initial commit');
|
|
90
|
+
gitOra.succeed('Git repository initialized');
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
gitOra.fail('Failed to initialize git repository');
|
|
94
|
+
logger.error(error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const installDependencies = (_options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
+
const installOra = (yield getOra())('Installing dependencies...').start();
|
|
99
|
+
try {
|
|
100
|
+
// Install dependencies
|
|
101
|
+
yield new Promise((resolve, reject) => {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
const childProcess = (0, child_process_1.exec)('yarn install');
|
|
104
|
+
(_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
105
|
+
installOra.text = `Installing dependencies: ${data.toString()}`;
|
|
106
|
+
logger.debug(data);
|
|
107
|
+
});
|
|
108
|
+
(_b = childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
109
|
+
logger.debug(data);
|
|
110
|
+
});
|
|
111
|
+
childProcess.on('close', (code) => {
|
|
112
|
+
if (code === 0) {
|
|
113
|
+
installOra.succeed('Dependencies installed');
|
|
114
|
+
resolve();
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
installOra.fail('Failed to install dependencies');
|
|
118
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
installOra.fail('Failed to install dependencies');
|
|
125
|
+
logger.error(error);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=createSolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSolution.js","sourceRoot":"","sources":["../../../src/commands/create/createSolution.ts"],"names":[],"mappings":";;;;AAAA,iDAAqC;AACrC,yBAAyB;AACzB,6BAA6B;AAC7B,2CAAuC;AACvC,2BAA2B;AAC3B,+BAAoC;AACpC,uCAA4C;AAC5C,2CAA2C;AAG3C,4EAA4E;AAC5E,MAAM,MAAM,GAAG,GAAS,EAAE,0DAAC,OAAA,CAAC,MAAM,MAAM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AAO,CAAC,wBAAwB,CAAC,CAAC;oBAC7C,OAAO,EAAE,CAAC;iBACX;qBAAM;oBACL,UAAU,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;oBAClD,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC,CAAC;iBACvD;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,UAAU,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACrB;AACH,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultValues.js","sourceRoot":"","sources":["../../../src/commands/create/defaultValues.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B,WAAW,EAAE,WAAW;IACxB,MAAM,EAAE,GAAG;IACX,gBAAgB,EAAE,QAAQ;CAC3B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCommitId = exports.getBranches = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const getBranches = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
6
|
+
const branches = [];
|
|
7
|
+
let page = 1;
|
|
8
|
+
let morePages = true;
|
|
9
|
+
while (morePages) {
|
|
10
|
+
const result = yield fetch(`https://api.github.com/repos/Axinom/mosaic-media-template/branches?per_page=100&page=${page}`);
|
|
11
|
+
if (result.status !== 200) {
|
|
12
|
+
console.warn('Failed to fetch the branches');
|
|
13
|
+
}
|
|
14
|
+
page++;
|
|
15
|
+
const data = yield result.json();
|
|
16
|
+
branches.push(...data.map((branch) => branch.name));
|
|
17
|
+
if (data.length < 100) {
|
|
18
|
+
morePages = false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const sortedBranches = branches.sort((a, b) => {
|
|
22
|
+
// first branches starting with "releases/", then "main", then "dev", then the rest
|
|
23
|
+
if (a.startsWith('releases/')) {
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
if (a === 'main') {
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
if (a === 'dev') {
|
|
30
|
+
return -1;
|
|
31
|
+
}
|
|
32
|
+
if (b.startsWith('releases/')) {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
if (b === 'main') {
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
if (b === 'dev') {
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
});
|
|
43
|
+
return sortedBranches;
|
|
44
|
+
});
|
|
45
|
+
exports.getBranches = getBranches;
|
|
46
|
+
const getCommitId = ({ gitReference, gitReferenceType, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
let url;
|
|
48
|
+
if (gitReferenceType === 'tags') {
|
|
49
|
+
url = `https://api.github.com/repos/Axinom/mosaic-media-template/git/refs/tags/${gitReference}`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
url = `https://api.github.com/repos/Axinom/mosaic-media-template/branches/${gitReference}`;
|
|
53
|
+
}
|
|
54
|
+
const result = yield fetch(url);
|
|
55
|
+
if (result.status !== 200) {
|
|
56
|
+
console.log('Failed to fetch the head of the branch', url, result.statusText);
|
|
57
|
+
return new Date().toISOString();
|
|
58
|
+
}
|
|
59
|
+
const data = yield result.json();
|
|
60
|
+
return gitReferenceType === 'tags' ? data.object.sha : data.commit.sha;
|
|
61
|
+
});
|
|
62
|
+
exports.getCommitId = getCommitId;
|
|
63
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../../src/commands/create/helpers/git.ts"],"names":[],"mappings":";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AAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACxB,CAAC,CAAA,CAAC;AAhDW,QAAA,WAAW,eAgDtB;AAEK,MAAM,WAAW,GAAG,CAAO,EAChC,YAAY,EACZ,gBAAgB,GAIjB,EAAmB,EAAE;IACpB,IAAI,GAAW,CAAC;IAEhB,IAAI,gBAAgB,KAAK,MAAM,EAAE;QAC/B,GAAG,GAAG,2EAA2E,YAAY,EAAE,CAAC;KACjG;SAAM;QACL,GAAG,GAAG,sEAAsE,YAAY,EAAE,CAAC;KAC5F;IACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAEhC,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE;QACzB,OAAO,CAAC,GAAG,CACT,wCAAwC,EACxC,GAAG,EACH,MAAM,CAAC,UAAU,CAClB,CAAC;QACF,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;KACjC;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;IAEjC,OAAO,gBAAgB,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;AACzE,CAAC,CAAA,CAAC;AA5BW,QAAA,WAAW,eA4BtB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const setDebug: (debug: boolean) => void;
|
|
2
|
+
export declare const success: (...args: any[]) => void;
|
|
3
|
+
export declare const error: (...args: any[]) => void;
|
|
4
|
+
export declare const info: (...args: any[]) => void;
|
|
5
|
+
export declare const warn: (...args: any[]) => void;
|
|
6
|
+
export declare const log: (...args: any[]) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Only logs if debug is enabled
|
|
9
|
+
*/
|
|
10
|
+
export declare const debug: (...args: any[]) => void;
|
|
11
|
+
export declare const logger: {
|
|
12
|
+
success: (...args: any[]) => void;
|
|
13
|
+
error: (...args: any[]) => void;
|
|
14
|
+
info: (...args: any[]) => void;
|
|
15
|
+
warn: (...args: any[]) => void;
|
|
16
|
+
debug: (...args: any[]) => void;
|
|
17
|
+
log: (...args: any[]) => void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = exports.debug = exports.log = exports.warn = exports.info = exports.error = exports.success = exports.setDebug = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
let isDebug = false;
|
|
6
|
+
const setDebug = (debug) => {
|
|
7
|
+
isDebug = debug;
|
|
8
|
+
};
|
|
9
|
+
exports.setDebug = setDebug;
|
|
10
|
+
const success = (...args) => {
|
|
11
|
+
console.log(chalk.green(`✅`, ...args));
|
|
12
|
+
};
|
|
13
|
+
exports.success = success;
|
|
14
|
+
const error = (...args) => {
|
|
15
|
+
console.log(chalk.red(...args));
|
|
16
|
+
};
|
|
17
|
+
exports.error = error;
|
|
18
|
+
const info = (...args) => {
|
|
19
|
+
console.log(chalk.blue(...args));
|
|
20
|
+
};
|
|
21
|
+
exports.info = info;
|
|
22
|
+
const warn = (...args) => {
|
|
23
|
+
console.log(chalk.bgYellow(...args));
|
|
24
|
+
};
|
|
25
|
+
exports.warn = warn;
|
|
26
|
+
const log = (...args) => {
|
|
27
|
+
console.log(chalk.yellow(...args));
|
|
28
|
+
};
|
|
29
|
+
exports.log = log;
|
|
30
|
+
/**
|
|
31
|
+
* Only logs if debug is enabled
|
|
32
|
+
*/
|
|
33
|
+
const debug = (...args) => {
|
|
34
|
+
isDebug && console.log(chalk.gray(...args));
|
|
35
|
+
};
|
|
36
|
+
exports.debug = debug;
|
|
37
|
+
exports.logger = {
|
|
38
|
+
success: exports.success,
|
|
39
|
+
error: exports.error,
|
|
40
|
+
info: exports.info,
|
|
41
|
+
warn: exports.warn,
|
|
42
|
+
debug: exports.debug,
|
|
43
|
+
log: exports.log,
|
|
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AAFW,QAAA,GAAG,OAEd;AACF;;GAEG;AACI,MAAM,KAAK,GAAG,CAAC,GAAG,IAAW,EAAQ,EAAE;IAC5C,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB;AAEW,QAAA,MAAM,GAAG;IACpB,OAAO,EAAP,eAAO;IACP,KAAK,EAAL,aAAK;IACL,IAAI,EAAJ,YAAI;IACJ,IAAI,EAAJ,YAAI;IACJ,KAAK,EAAL,aAAK;IACL,GAAG,EAAH,WAAG;CACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface CreateSolutionInput {
|
|
2
|
+
projectName: string;
|
|
3
|
+
target: string;
|
|
4
|
+
noGit: boolean;
|
|
5
|
+
noInstall: boolean;
|
|
6
|
+
gitReference: string;
|
|
7
|
+
gitReferenceType: string;
|
|
8
|
+
debug: boolean;
|
|
9
|
+
default: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type CliResults = Partial<Omit<CreateSolutionInput, 'gitReference' | 'gitReferenceType'>> & {
|
|
12
|
+
installationType?: string;
|
|
13
|
+
branch?: string;
|
|
14
|
+
debug?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/commands/create/helpers/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CliResults } from './helpers/types';
|
|
2
|
+
/**
|
|
3
|
+
* Runs the questionnaire to gather user input for the project creation.
|
|
4
|
+
* @param cliResults - The initial CLI results object.
|
|
5
|
+
* @returns A promise that resolves to the updated CLI results object.
|
|
6
|
+
*/
|
|
7
|
+
export declare const runQuestionaire: (cliResults: CliResults) => Promise<CliResults>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runQuestionaire = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
6
|
+
const defaultValues_1 = require("./defaultValues");
|
|
7
|
+
const git_1 = require("./helpers/git");
|
|
8
|
+
/**
|
|
9
|
+
* Runs the questionnaire to gather user input for the project creation.
|
|
10
|
+
* @param cliResults - The initial CLI results object.
|
|
11
|
+
* @returns A promise that resolves to the updated CLI results object.
|
|
12
|
+
*/
|
|
13
|
+
const runQuestionaire = (cliResults) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const project = Object.assign({}, cliResults);
|
|
15
|
+
if (project.projectName === undefined) {
|
|
16
|
+
project.projectName = yield (0, prompts_1.input)({
|
|
17
|
+
message: 'Project name',
|
|
18
|
+
default: defaultValues_1.defaultValues.projectName,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (project.target === undefined) {
|
|
22
|
+
project.target = yield (0, prompts_1.input)({
|
|
23
|
+
message: 'Target folder',
|
|
24
|
+
default: defaultValues_1.defaultValues.target,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (project.installationType === undefined) {
|
|
28
|
+
project.installationType = yield (0, prompts_1.select)({
|
|
29
|
+
message: 'Installation type',
|
|
30
|
+
choices: [
|
|
31
|
+
{
|
|
32
|
+
value: 'stable',
|
|
33
|
+
name: 'Stable',
|
|
34
|
+
description: 'Use latest official released version. Recommended',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
value: 'experimental',
|
|
38
|
+
name: 'Experimental',
|
|
39
|
+
description: 'Using latest, untested version',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
value: 'custom',
|
|
43
|
+
name: 'Custom',
|
|
44
|
+
description: 'Select a specific branch',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
default: defaultValues_1.defaultValues.installationType,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (project.installationType === 'custom' && project.branch === undefined) {
|
|
51
|
+
const branchesOra = (yield import('ora'))
|
|
52
|
+
.default('Fetching branches...')
|
|
53
|
+
.start();
|
|
54
|
+
const { default: autocomplete } = yield import('inquirer-autocomplete-standalone');
|
|
55
|
+
const branches = (yield (0, git_1.getBranches)()).map((branch) => ({ value: branch }));
|
|
56
|
+
branchesOra.stop();
|
|
57
|
+
project.branch =
|
|
58
|
+
branches.length > 0
|
|
59
|
+
? yield autocomplete({
|
|
60
|
+
message: 'Branch name',
|
|
61
|
+
source: (input) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
if (input === undefined) {
|
|
63
|
+
return branches;
|
|
64
|
+
}
|
|
65
|
+
return branches.filter((branch) => branch.value.includes(input));
|
|
66
|
+
}),
|
|
67
|
+
})
|
|
68
|
+
: yield (0, prompts_1.input)({
|
|
69
|
+
message: 'Branch name',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (project.noGit === undefined) {
|
|
73
|
+
project.noGit = !(yield (0, prompts_1.confirm)({
|
|
74
|
+
message: 'Initialize a git repository?',
|
|
75
|
+
default: true,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
if (project.noInstall === undefined) {
|
|
79
|
+
project.noInstall = !(yield (0, prompts_1.confirm)({
|
|
80
|
+
message: 'Install dependencies?',
|
|
81
|
+
default: true,
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
return project;
|
|
85
|
+
});
|
|
86
|
+
exports.runQuestionaire = runQuestionaire;
|
|
87
|
+
//# sourceMappingURL=runQuestionaire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runQuestionaire.js","sourceRoot":"","sources":["../../../src/commands/create/runQuestionaire.ts"],"names":[],"mappings":";;;;AAAA,+CAA2D;AAC3D,mDAAgD;AAChD,uCAA4C;AAG5C;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAC7B,UAAsB,EAC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li",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1",
|
|
4
4
|
"description": "The Axinom Mosaic CLI",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"@asyncapi/diff": "^0.4.1",
|
|
35
35
|
"@asyncapi/modelina": "^1.8.4",
|
|
36
36
|
"@asyncapi/parser": "^2.0.2",
|
|
37
|
-
"@axinom/mosaic-id-link-be": "^0.21.0
|
|
38
|
-
"@axinom/mosaic-service-common": "^0.49.0
|
|
37
|
+
"@axinom/mosaic-id-link-be": "^0.21.0",
|
|
38
|
+
"@axinom/mosaic-service-common": "^0.49.0",
|
|
39
39
|
"@graphql-inspector/core": "^3.1.2",
|
|
40
|
+
"@inquirer/prompts": "^4.3.0",
|
|
40
41
|
"@stoplight/spectral-core": "^1.18.3",
|
|
41
42
|
"@stoplight/spectral-parsers": "^1.0.3",
|
|
42
43
|
"@stoplight/spectral-ruleset-bundler": "^1.5.2",
|
|
@@ -51,13 +52,18 @@
|
|
|
51
52
|
"glob": "^7.1.6",
|
|
52
53
|
"graphile-utils": "^4.13.0",
|
|
53
54
|
"graphql": "^15.4.0",
|
|
55
|
+
"inquirer-autocomplete-standalone": "^0.8.1",
|
|
54
56
|
"js-yaml": "^4.1.0",
|
|
55
57
|
"json-schema": "^0.4.0",
|
|
56
58
|
"json-schema-diff": "^0.17.1",
|
|
57
59
|
"json-schema-ref-parser": "^9.0.7",
|
|
58
60
|
"json5": "^2.2.0",
|
|
61
|
+
"ora": "^8.0.1",
|
|
59
62
|
"pg": "^8.11.3",
|
|
60
|
-
"
|
|
63
|
+
"simple-git": "^3.23.0",
|
|
64
|
+
"sql-formatter": "^4.0.2",
|
|
65
|
+
"tar": "^6.1.13",
|
|
66
|
+
"zlib": "^1.0.5"
|
|
61
67
|
},
|
|
62
68
|
"devDependencies": {
|
|
63
69
|
"@types/diff": "^5.0.0",
|
|
@@ -72,5 +78,5 @@
|
|
|
72
78
|
"publishConfig": {
|
|
73
79
|
"access": "public"
|
|
74
80
|
},
|
|
75
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "eec17809228284482d6acd1958062dbc8068dd7e"
|
|
76
82
|
}
|
package/src/cli/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createExtensionConfigCommand,
|
|
5
5
|
getExtensions,
|
|
6
6
|
} from '../commands/create-extension-config';
|
|
7
|
+
import { createSolutionCommand } from '../commands/create/command';
|
|
7
8
|
import { getAccessToken } from '../commands/get-access-token';
|
|
8
9
|
import { graphqlDiff } from '../commands/graphql-diff';
|
|
9
10
|
import { hosting } from '../commands/hosting';
|
|
@@ -28,7 +29,8 @@ export const run = async (): Promise<void> => {
|
|
|
28
29
|
.command(graphqlDiff)
|
|
29
30
|
.command(hosting)
|
|
30
31
|
.command(unpublishPilet)
|
|
31
|
-
.command(service)
|
|
32
|
+
.command(service)
|
|
33
|
+
.command(createSolutionCommand);
|
|
32
34
|
|
|
33
35
|
//adding cli extensions:
|
|
34
36
|
await Promise.all(
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ExitPromptError } from '@inquirer/prompts';
|
|
2
|
+
import { CommandModule } from 'yargs';
|
|
3
|
+
import { createSolution } from './createSolution';
|
|
4
|
+
import { defaultValues } from './defaultValues';
|
|
5
|
+
import { logger, setDebug } from './helpers/logger';
|
|
6
|
+
import { CliResults } from './helpers/types';
|
|
7
|
+
import { runQuestionaire } from './runQuestionaire';
|
|
8
|
+
|
|
9
|
+
export const createSolutionCommand: CommandModule<unknown, CliResults> = {
|
|
10
|
+
command: 'create',
|
|
11
|
+
describe: 'Creates a new Mosaic solution.',
|
|
12
|
+
builder: (yargs) =>
|
|
13
|
+
yargs
|
|
14
|
+
.positional('projectName', {
|
|
15
|
+
describe: `The name of the solution. Default: ${defaultValues.projectName}`,
|
|
16
|
+
type: 'string',
|
|
17
|
+
})
|
|
18
|
+
.positional('target', {
|
|
19
|
+
describe: `The root folder for the solution. Default: ${defaultValues.target}`,
|
|
20
|
+
type: 'string',
|
|
21
|
+
})
|
|
22
|
+
.option('default', {
|
|
23
|
+
alias: 'y',
|
|
24
|
+
describe: 'Bypass prompts and use default options',
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
})
|
|
27
|
+
.option('noGit', {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
describe: 'Do not initialize a new git repository',
|
|
30
|
+
})
|
|
31
|
+
.option('noInstall', {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
describe: 'Do not run package manager install command',
|
|
34
|
+
})
|
|
35
|
+
.option('installationType', {
|
|
36
|
+
choices: ['stable', 'experimental', 'custom'],
|
|
37
|
+
type: 'string',
|
|
38
|
+
})
|
|
39
|
+
.option('branch', {
|
|
40
|
+
type: 'string',
|
|
41
|
+
})
|
|
42
|
+
.option('debug', {
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
describe: 'Show debug logs',
|
|
45
|
+
}),
|
|
46
|
+
handler: async (options): Promise<void> => {
|
|
47
|
+
setDebug(!!options.debug);
|
|
48
|
+
options.projectName = options._[1] as string;
|
|
49
|
+
options.target = options._[2] as string;
|
|
50
|
+
|
|
51
|
+
logger.log('Welcome to Axinom Mosaic!');
|
|
52
|
+
logger.log("We're going to create a new Mosaic solution for you.\n");
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
if (options.default) {
|
|
56
|
+
await createSolution({
|
|
57
|
+
projectName: options.projectName ?? defaultValues.projectName,
|
|
58
|
+
target: options.target ?? defaultValues.target,
|
|
59
|
+
noGit: !!options.noGit,
|
|
60
|
+
noInstall: !!options.noInstall,
|
|
61
|
+
debug: !!options.debug,
|
|
62
|
+
default: true,
|
|
63
|
+
...(await getGitReference(options)),
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
logger.log(
|
|
67
|
+
'We just need a couple more things from you before we can get started:\n',
|
|
68
|
+
);
|
|
69
|
+
const answers = await runQuestionaire(options);
|
|
70
|
+
|
|
71
|
+
// new line
|
|
72
|
+
console.log();
|
|
73
|
+
|
|
74
|
+
await createSolution({
|
|
75
|
+
projectName: answers.projectName ?? defaultValues.projectName,
|
|
76
|
+
target: answers.target ?? defaultValues.target,
|
|
77
|
+
noGit: !!answers.noGit,
|
|
78
|
+
noInstall: !!answers.noInstall,
|
|
79
|
+
debug: !!options.debug,
|
|
80
|
+
default: false,
|
|
81
|
+
...(await getGitReference(answers)),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof ExitPromptError) {
|
|
86
|
+
logger.error('\nCreation of the solution was cancelled.');
|
|
87
|
+
} else {
|
|
88
|
+
logger.error('\nFailed to create a new Mosaic solution');
|
|
89
|
+
}
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
logger.log('\nSuccessfully created your Mosaic solution 🎉');
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const getGitReference = async (
|
|
98
|
+
options: CliResults,
|
|
99
|
+
): Promise<{
|
|
100
|
+
gitReference: string;
|
|
101
|
+
gitReferenceType: string;
|
|
102
|
+
}> => {
|
|
103
|
+
if (options.branch) {
|
|
104
|
+
return { gitReference: options.branch, gitReferenceType: 'heads' };
|
|
105
|
+
}
|
|
106
|
+
if (options.installationType === 'experimental') {
|
|
107
|
+
// TODO: remove the logic here and always pull `main` after branching model is switched
|
|
108
|
+
const devBranchRequest = await fetch(
|
|
109
|
+
'https://api.github.com/repos/Axinom/mosaic-media-template/branches/dev',
|
|
110
|
+
);
|
|
111
|
+
const devBranchExists = devBranchRequest.ok;
|
|
112
|
+
const gitReference = devBranchExists ? 'dev' : 'main';
|
|
113
|
+
|
|
114
|
+
return { gitReference, gitReferenceType: 'heads' };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const lastReleaseRequest = await fetch(
|
|
118
|
+
'https://api.github.com/repos/Axinom/mosaic-media-template/releases/latest',
|
|
119
|
+
);
|
|
120
|
+
const latestRelease = await lastReleaseRequest.json();
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
gitReference: latestRelease.tag_name,
|
|
124
|
+
gitReferenceType: 'tags',
|
|
125
|
+
};
|
|
126
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { simpleGit } from 'simple-git';
|
|
5
|
+
import * as tar from 'tar';
|
|
6
|
+
import { createGunzip } from 'zlib';
|
|
7
|
+
import { getCommitId } from './helpers/git';
|
|
8
|
+
import * as logger from './helpers/logger';
|
|
9
|
+
import { CreateSolutionInput } from './helpers/types';
|
|
10
|
+
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
12
|
+
const getOra = async () => (await import('ora')).default;
|
|
13
|
+
|
|
14
|
+
export const createSolution = async (
|
|
15
|
+
options: CreateSolutionInput,
|
|
16
|
+
): Promise<void> => {
|
|
17
|
+
logger.debug('CreateSolution options', JSON.stringify(options));
|
|
18
|
+
await downloadAndUnzipTemplate(options);
|
|
19
|
+
|
|
20
|
+
process.chdir(options.target);
|
|
21
|
+
|
|
22
|
+
await adjustSolution(options);
|
|
23
|
+
|
|
24
|
+
if (!options.noGit) {
|
|
25
|
+
await initializeGit(options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!options.noInstall) {
|
|
29
|
+
await installDependencies(options);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const downloadAndUnzipTemplate = async (
|
|
34
|
+
options: CreateSolutionInput,
|
|
35
|
+
): Promise<void> => {
|
|
36
|
+
const downloadOra = (await getOra())('Downloading the template...');
|
|
37
|
+
downloadOra.start();
|
|
38
|
+
|
|
39
|
+
const url = `https://github.com/Axinom/mosaic-media-template/archive/refs/${options.gitReferenceType}/${options.gitReference}.tar.gz`;
|
|
40
|
+
const response = await fetch(url);
|
|
41
|
+
|
|
42
|
+
if (response.ok) {
|
|
43
|
+
downloadOra.succeed('Template downloaded');
|
|
44
|
+
await extractArchive(response, options);
|
|
45
|
+
} else {
|
|
46
|
+
downloadOra.fail(
|
|
47
|
+
`Failed to download the template ('${response.statusText}')`,
|
|
48
|
+
);
|
|
49
|
+
logger.debug(
|
|
50
|
+
`Failed to download the template from ${url}`,
|
|
51
|
+
JSON.stringify(response),
|
|
52
|
+
);
|
|
53
|
+
throw new Error(response.statusText);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const extractArchive = async (
|
|
58
|
+
response: Response,
|
|
59
|
+
options: CreateSolutionInput,
|
|
60
|
+
): Promise<void> => {
|
|
61
|
+
const unzipOra = (await getOra())('Unzipping the template...');
|
|
62
|
+
const buffer = await response.arrayBuffer();
|
|
63
|
+
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const targetPath = path.resolve(options.target);
|
|
66
|
+
fs.mkdirSync(targetPath, { recursive: true });
|
|
67
|
+
|
|
68
|
+
const gunzip = createGunzip();
|
|
69
|
+
const extract = tar.extract({ cwd: targetPath, strip: 1 });
|
|
70
|
+
|
|
71
|
+
gunzip.on('data', (data) => extract.write(data));
|
|
72
|
+
gunzip.on('end', () => {
|
|
73
|
+
extract.end();
|
|
74
|
+
});
|
|
75
|
+
gunzip.on('error', (err) => {
|
|
76
|
+
unzipOra.fail('Failed to unzip the template');
|
|
77
|
+
logger.error(err);
|
|
78
|
+
reject(err);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
extract.on('finish', () => {
|
|
82
|
+
unzipOra.succeed('Template extracted');
|
|
83
|
+
resolve();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
gunzip.write(Buffer.from(buffer));
|
|
87
|
+
gunzip.end();
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const adjustSolution = async (options: CreateSolutionInput): Promise<void> => {
|
|
92
|
+
const adjustOra = (await getOra())('Adjusting package.json...').start();
|
|
93
|
+
try {
|
|
94
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
95
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
96
|
+
packageJson.name = options.projectName;
|
|
97
|
+
|
|
98
|
+
packageJson.mosaic = {
|
|
99
|
+
baseVersion: `${await getCommitId(options)} (${options.gitReference})`,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
103
|
+
adjustOra.succeed('package.json adjusted');
|
|
104
|
+
} catch (error) {
|
|
105
|
+
adjustOra.fail('Failed to adjust package.json');
|
|
106
|
+
logger.error(error);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const initializeGit = async (_options: CreateSolutionInput): Promise<void> => {
|
|
111
|
+
const gitOra = (await getOra())('Initializing git repository...').start();
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const git = simpleGit();
|
|
115
|
+
await git.init().add('./*').commit('Initial commit');
|
|
116
|
+
|
|
117
|
+
gitOra.succeed('Git repository initialized');
|
|
118
|
+
} catch (error) {
|
|
119
|
+
gitOra.fail('Failed to initialize git repository');
|
|
120
|
+
logger.error(error);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const installDependencies = async (
|
|
125
|
+
_options: CreateSolutionInput,
|
|
126
|
+
): Promise<void> => {
|
|
127
|
+
const installOra = (await getOra())('Installing dependencies...').start();
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
// Install dependencies
|
|
131
|
+
await new Promise<void>((resolve, reject) => {
|
|
132
|
+
const childProcess = exec('yarn install');
|
|
133
|
+
childProcess.stdout?.on('data', (data) => {
|
|
134
|
+
installOra.text = `Installing dependencies: ${data.toString()}`;
|
|
135
|
+
logger.debug(data);
|
|
136
|
+
});
|
|
137
|
+
childProcess.stderr?.on('data', (data) => {
|
|
138
|
+
logger.debug(data);
|
|
139
|
+
});
|
|
140
|
+
childProcess.on('close', (code) => {
|
|
141
|
+
if (code === 0) {
|
|
142
|
+
installOra.succeed('Dependencies installed');
|
|
143
|
+
resolve();
|
|
144
|
+
} else {
|
|
145
|
+
installOra.fail('Failed to install dependencies');
|
|
146
|
+
reject(new Error(`Command exited with code ${code}`));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
} catch (error) {
|
|
151
|
+
installOra.fail('Failed to install dependencies');
|
|
152
|
+
logger.error(error);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CreateSolutionInput } from './types';
|
|
2
|
+
|
|
3
|
+
export const getBranches = async (): Promise<string[]> => {
|
|
4
|
+
const branches: string[] = [];
|
|
5
|
+
let page = 1;
|
|
6
|
+
let morePages = true;
|
|
7
|
+
|
|
8
|
+
while (morePages) {
|
|
9
|
+
const result = await fetch(
|
|
10
|
+
`https://api.github.com/repos/Axinom/mosaic-media-template/branches?per_page=100&page=${page}`,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (result.status !== 200) {
|
|
14
|
+
console.warn('Failed to fetch the branches');
|
|
15
|
+
}
|
|
16
|
+
page++;
|
|
17
|
+
|
|
18
|
+
const data = await result.json();
|
|
19
|
+
|
|
20
|
+
branches.push(...data.map((branch: { name: string }) => branch.name));
|
|
21
|
+
|
|
22
|
+
if (data.length < 100) {
|
|
23
|
+
morePages = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const sortedBranches = branches.sort((a, b) => {
|
|
28
|
+
// first branches starting with "releases/", then "main", then "dev", then the rest
|
|
29
|
+
if (a.startsWith('releases/')) {
|
|
30
|
+
return -1;
|
|
31
|
+
}
|
|
32
|
+
if (a === 'main') {
|
|
33
|
+
return -1;
|
|
34
|
+
}
|
|
35
|
+
if (a === 'dev') {
|
|
36
|
+
return -1;
|
|
37
|
+
}
|
|
38
|
+
if (b.startsWith('releases/')) {
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
if (b === 'main') {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
if (b === 'dev') {
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return sortedBranches;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const getCommitId = async ({
|
|
54
|
+
gitReference,
|
|
55
|
+
gitReferenceType,
|
|
56
|
+
}: Pick<
|
|
57
|
+
CreateSolutionInput,
|
|
58
|
+
'gitReference' | 'gitReferenceType'
|
|
59
|
+
>): Promise<string> => {
|
|
60
|
+
let url: string;
|
|
61
|
+
|
|
62
|
+
if (gitReferenceType === 'tags') {
|
|
63
|
+
url = `https://api.github.com/repos/Axinom/mosaic-media-template/git/refs/tags/${gitReference}`;
|
|
64
|
+
} else {
|
|
65
|
+
url = `https://api.github.com/repos/Axinom/mosaic-media-template/branches/${gitReference}`;
|
|
66
|
+
}
|
|
67
|
+
const result = await fetch(url);
|
|
68
|
+
|
|
69
|
+
if (result.status !== 200) {
|
|
70
|
+
console.log(
|
|
71
|
+
'Failed to fetch the head of the branch',
|
|
72
|
+
url,
|
|
73
|
+
result.statusText,
|
|
74
|
+
);
|
|
75
|
+
return new Date().toISOString();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const data = await result.json();
|
|
79
|
+
|
|
80
|
+
return gitReferenceType === 'tags' ? data.object.sha : data.commit.sha;
|
|
81
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
let isDebug = false;
|
|
4
|
+
export const setDebug = (debug: boolean): void => {
|
|
5
|
+
isDebug = debug;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const success = (...args: any[]): void => {
|
|
9
|
+
console.log(chalk.green(`✅`, ...args));
|
|
10
|
+
};
|
|
11
|
+
export const error = (...args: any[]): void => {
|
|
12
|
+
console.log(chalk.red(...args));
|
|
13
|
+
};
|
|
14
|
+
export const info = (...args: any[]): void => {
|
|
15
|
+
console.log(chalk.blue(...args));
|
|
16
|
+
};
|
|
17
|
+
export const warn = (...args: any[]): void => {
|
|
18
|
+
console.log(chalk.bgYellow(...args));
|
|
19
|
+
};
|
|
20
|
+
export const log = (...args: any[]): void => {
|
|
21
|
+
console.log(chalk.yellow(...args));
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Only logs if debug is enabled
|
|
25
|
+
*/
|
|
26
|
+
export const debug = (...args: any[]): void => {
|
|
27
|
+
isDebug && console.log(chalk.gray(...args));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const logger = {
|
|
31
|
+
success,
|
|
32
|
+
error,
|
|
33
|
+
info,
|
|
34
|
+
warn,
|
|
35
|
+
debug,
|
|
36
|
+
log,
|
|
37
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface CreateSolutionInput {
|
|
2
|
+
projectName: string;
|
|
3
|
+
target: string;
|
|
4
|
+
noGit: boolean;
|
|
5
|
+
noInstall: boolean;
|
|
6
|
+
gitReference: string;
|
|
7
|
+
gitReferenceType: string;
|
|
8
|
+
debug: boolean;
|
|
9
|
+
default: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type CliResults = Partial<
|
|
13
|
+
Omit<CreateSolutionInput, 'gitReference' | 'gitReferenceType'>
|
|
14
|
+
> & {
|
|
15
|
+
installationType?: string;
|
|
16
|
+
branch?: string;
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { confirm, input, select } from '@inquirer/prompts';
|
|
2
|
+
import { defaultValues } from './defaultValues';
|
|
3
|
+
import { getBranches } from './helpers/git';
|
|
4
|
+
import { CliResults } from './helpers/types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Runs the questionnaire to gather user input for the project creation.
|
|
8
|
+
* @param cliResults - The initial CLI results object.
|
|
9
|
+
* @returns A promise that resolves to the updated CLI results object.
|
|
10
|
+
*/
|
|
11
|
+
export const runQuestionaire = async (
|
|
12
|
+
cliResults: CliResults,
|
|
13
|
+
): Promise<CliResults> => {
|
|
14
|
+
const project: CliResults = { ...cliResults };
|
|
15
|
+
|
|
16
|
+
if (project.projectName === undefined) {
|
|
17
|
+
project.projectName = await input({
|
|
18
|
+
message: 'Project name',
|
|
19
|
+
default: defaultValues.projectName,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (project.target === undefined) {
|
|
24
|
+
project.target = await input({
|
|
25
|
+
message: 'Target folder',
|
|
26
|
+
default: defaultValues.target,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (project.installationType === undefined) {
|
|
31
|
+
project.installationType = await select({
|
|
32
|
+
message: 'Installation type',
|
|
33
|
+
choices: [
|
|
34
|
+
{
|
|
35
|
+
value: 'stable',
|
|
36
|
+
name: 'Stable',
|
|
37
|
+
description: 'Use latest official released version. Recommended',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
value: 'experimental',
|
|
41
|
+
name: 'Experimental',
|
|
42
|
+
description: 'Using latest, untested version',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
value: 'custom',
|
|
46
|
+
name: 'Custom',
|
|
47
|
+
description: 'Select a specific branch',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
default: defaultValues.installationType,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (project.installationType === 'custom' && project.branch === undefined) {
|
|
55
|
+
const branchesOra = (await import('ora'))
|
|
56
|
+
.default('Fetching branches...')
|
|
57
|
+
.start();
|
|
58
|
+
|
|
59
|
+
const { default: autocomplete } = await import(
|
|
60
|
+
'inquirer-autocomplete-standalone'
|
|
61
|
+
);
|
|
62
|
+
const branches = (await getBranches()).map((branch) => ({ value: branch }));
|
|
63
|
+
branchesOra.stop();
|
|
64
|
+
|
|
65
|
+
project.branch =
|
|
66
|
+
branches.length > 0
|
|
67
|
+
? await autocomplete({
|
|
68
|
+
message: 'Branch name',
|
|
69
|
+
source: async (input) => {
|
|
70
|
+
if (input === undefined) {
|
|
71
|
+
return branches;
|
|
72
|
+
}
|
|
73
|
+
return branches.filter((branch) => branch.value.includes(input));
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
: await input({
|
|
77
|
+
message: 'Branch name',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (project.noGit === undefined) {
|
|
82
|
+
project.noGit = !(await confirm({
|
|
83
|
+
message: 'Initialize a git repository?',
|
|
84
|
+
default: true,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (project.noInstall === undefined) {
|
|
89
|
+
project.noInstall = !(await confirm({
|
|
90
|
+
message: 'Install dependencies?',
|
|
91
|
+
default: true,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return project;
|
|
96
|
+
};
|