@azrico/azcli 1.1.44 → 1.1.45
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.js +54 -2
- package/dist/libs/builder/build_wp.js +113 -1
- package/dist/libs/builder/build_yarn.js +11 -1
- package/dist/libs/builder/index.js +21 -1
- package/dist/libs/cleaner/cleanbuild.js +12 -1
- package/dist/libs/cleaner/cleannext.js +12 -1
- package/dist/libs/cleaner/cleannode.js +21 -1
- package/dist/libs/cleaner/index.js +37 -1
- package/dist/libs/commons/filehandler.js +61 -3
- package/dist/libs/commons/helper_exec.js +49 -1
- package/dist/libs/commons/helper_interface.js +96 -4
- package/dist/libs/commons/helper_string.js +15 -1
- package/dist/libs/commons/index.js +5 -1
- package/dist/libs/integ/index.js +7 -1
- package/dist/libs/integ/integ_readme.js +6 -1
- package/dist/libs/packager/index.js +18 -1
- package/dist/libs/packager/packager.js +236 -9
- package/dist/libs/up/filterOptionsByAcceptable.js +16 -2
- package/dist/libs/up/index.js +35 -1
- package/dist/libs/up/update_composer.js +53 -1
- package/dist/libs/up/update_py.js +10 -1
- package/dist/libs/up/update_yarn.js +78 -2
- package/dist/libs/yarnhelp/index.js +8 -1
- package/dist/libs/yarnhelp/yarnb.js +14 -1
- package/dist/libs/yarnhelp/yarni.js +14 -1
- package/dist/libs/yarnhelp/yarnt.js +14 -1
- package/package.json +1 -1
|
@@ -1,10 +1,102 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
const prefix_text = '[az-cli]';
|
|
4
|
+
const valid_project_types = ['php', 'yarn', 'python'];
|
|
5
|
+
export function loadProjectType(args = null) {
|
|
6
|
+
const pt = getProjectType(args);
|
|
7
|
+
if (!pt)
|
|
8
|
+
return;
|
|
9
|
+
show_msg(`${chalk.gray('detected project type:')} ${chalk.green(pt)}`, 'text');
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
2
12
|
* Get project type from given args and existing files
|
|
3
13
|
* respects the no- prefix to exclude types
|
|
4
14
|
*
|
|
5
15
|
* for example --nopython will exclude python projects.
|
|
6
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export function getProjectType(args = null, check_files = true) {
|
|
18
|
+
if (args != null && typeof args === 'object' && args.type)
|
|
19
|
+
return args.type;
|
|
20
|
+
for (const t of valid_project_types) {
|
|
21
|
+
if (Object.hasOwn(args, 'no' + t))
|
|
22
|
+
continue;
|
|
23
|
+
/**
|
|
7
24
|
* direct match ex: --php
|
|
8
|
-
*/
|
|
25
|
+
*/
|
|
26
|
+
if (Object.hasOwn(args, t))
|
|
27
|
+
return t;
|
|
28
|
+
/**
|
|
9
29
|
* --mode=php
|
|
10
|
-
*/
|
|
30
|
+
*/
|
|
31
|
+
if (Object.hasOwn(args, 'mode') && args.mode == t)
|
|
32
|
+
return t;
|
|
33
|
+
}
|
|
34
|
+
if (check_files) {
|
|
35
|
+
if (fs.existsSync('./composer.json') || fs.existsSync('index.php'))
|
|
36
|
+
args.php = 1;
|
|
37
|
+
else if (fs.existsSync('./pyproject.yaml'))
|
|
38
|
+
args.python = 1;
|
|
39
|
+
else if (fs.existsSync('./package.json'))
|
|
40
|
+
args.yarn = 1;
|
|
41
|
+
return getProjectType(args, false);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
export function show_div() {
|
|
46
|
+
return show_msg('--------------------------------------------------------------------------', 'text', false);
|
|
47
|
+
}
|
|
48
|
+
export function show_msg(txt, type = '', showCli = true) {
|
|
49
|
+
if (Array.isArray(txt))
|
|
50
|
+
txt = txt
|
|
51
|
+
.flat()
|
|
52
|
+
.map((r) => String(r))
|
|
53
|
+
.join(' ');
|
|
54
|
+
/* -------------------------------------------------------------------------- */
|
|
55
|
+
var prefix = '';
|
|
56
|
+
switch (type) {
|
|
57
|
+
case 'text':
|
|
58
|
+
case 'none':
|
|
59
|
+
case 'default':
|
|
60
|
+
if (showCli)
|
|
61
|
+
prefix = chalk.bold.bgGreen(prefix_text);
|
|
62
|
+
console.info(prefix + ' ' + chalk.gray(txt));
|
|
63
|
+
break;
|
|
64
|
+
case '':
|
|
65
|
+
default:
|
|
66
|
+
if (showCli)
|
|
67
|
+
prefix = chalk.bgGreen(prefix_text);
|
|
68
|
+
console.info(prefix + ' ' + txt);
|
|
69
|
+
break;
|
|
70
|
+
case 'danger':
|
|
71
|
+
prefix = chalk.bgRedBright(prefix_text);
|
|
72
|
+
console.error(prefix + ' ' + chalk.gray(txt));
|
|
73
|
+
case 'error':
|
|
74
|
+
prefix = chalk.bgRed(prefix_text);
|
|
75
|
+
console.error(prefix + ' ' + chalk.gray(txt));
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function show_error(err) {
|
|
80
|
+
if (err instanceof Error)
|
|
81
|
+
err = err.message;
|
|
82
|
+
show_msg([chalk.red.bold('error : '), err], 'error');
|
|
83
|
+
return Error(err);
|
|
84
|
+
}
|
|
85
|
+
export function err_unknown_action(args) {
|
|
86
|
+
let argsTxt = '';
|
|
87
|
+
if (typeof args === 'string') {
|
|
88
|
+
argsTxt = args;
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
argsTxt = JSON.stringify(args);
|
|
92
|
+
show_msg(chalk.red.bold('Unknown command : ') + ' ' + chalk.gray(argsTxt), 'error');
|
|
93
|
+
}
|
|
94
|
+
export function err_unknown(args) {
|
|
95
|
+
let argsTxt = '';
|
|
96
|
+
if (typeof args === 'string') {
|
|
97
|
+
argsTxt = args;
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
argsTxt = JSON.stringify(args);
|
|
101
|
+
show_msg(chalk.red.bold('Unknown error : ') + ' ' + chalk.gray(argsTxt), 'error');
|
|
102
|
+
}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
export function custom_trim(s, ...mask_list) {
|
|
2
|
+
if (typeof s != 'string' || !s)
|
|
3
|
+
return s;
|
|
4
|
+
mask_list.map((mask) => {
|
|
5
|
+
if (!s || !mask)
|
|
6
|
+
return '';
|
|
7
|
+
while (s.startsWith(mask)) {
|
|
8
|
+
s = s.substring(mask.length);
|
|
9
|
+
}
|
|
10
|
+
while (s.endsWith(mask)) {
|
|
11
|
+
s = s.substring(0, s.length - mask.length);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return s;
|
|
15
|
+
}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './helper_interface';
|
|
2
|
+
export * from './helper_string';
|
|
3
|
+
export * from './helper_exec';
|
|
4
|
+
export * from './filehandler';
|
|
5
|
+
// export { err_unknown_action, err_unknown, show_msg, show_loading, do_exec };
|
package/dist/libs/integ/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/* Automatically integrates tools */
|
|
2
|
+
import { loadProjectType } from '../commons';
|
|
3
|
+
export function handle(args) {
|
|
4
|
+
loadProjectType();
|
|
5
|
+
console.info('IntegHelper');
|
|
6
|
+
}
|
|
7
|
+
export default handle;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/* Automatically integrates version history for current project */
|
|
2
|
+
export function handle(args) {
|
|
3
|
+
console.info('integrates');
|
|
4
|
+
// console.info('Building WP Plugin');
|
|
5
|
+
}
|
|
6
|
+
export default handle;
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/* Automatically integrates tools */
|
|
2
|
+
import { err_unknown, loadProjectType } from '../commons';
|
|
3
|
+
import packager from './packager';
|
|
4
|
+
export function handle(args) {
|
|
5
|
+
loadProjectType();
|
|
6
|
+
try {
|
|
7
|
+
packager(args);
|
|
8
|
+
}
|
|
9
|
+
catch (ex) {
|
|
10
|
+
err_unknown('unknown error');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default [
|
|
14
|
+
'package <mode>',
|
|
15
|
+
'convert each folder in ./packages dir into its own package. modes: prepare|finalize|go',
|
|
16
|
+
() => { },
|
|
17
|
+
handle,
|
|
18
|
+
];
|
|
@@ -1,16 +1,243 @@
|
|
|
1
|
-
|
|
1
|
+
/* This lib helps you build a wordpress plugin */
|
|
2
|
+
import { custom_trim, do_exec, err_unknown_action, readIfExists, show_div, show_error, show_msg, } from '../commons';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
/**
|
|
2
6
|
* get path of current active `dist` or `build`
|
|
3
7
|
* @returns
|
|
4
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
function getDistPath() {
|
|
10
|
+
if (fs.existsSync('./dist'))
|
|
11
|
+
return './dist';
|
|
12
|
+
if (fs.existsSync('./build'))
|
|
13
|
+
return './build';
|
|
14
|
+
if (fs.existsSync('./temp'))
|
|
15
|
+
return './temp';
|
|
16
|
+
throw 'no dist/build found. make sure to run this after building your files normally';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
5
19
|
* get a list of all folders in the ./packages directory
|
|
6
20
|
* @param dist
|
|
7
21
|
* @returns
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
*/
|
|
23
|
+
function getPackagePaths(includeCore = false) {
|
|
24
|
+
const distpath = getDistPath();
|
|
25
|
+
const packagespath = `./packages`;
|
|
26
|
+
const dir = fs
|
|
27
|
+
.readdirSync(packagespath)
|
|
28
|
+
.filter((s) => {
|
|
29
|
+
if (!includeCore && s === 'core')
|
|
30
|
+
return false;
|
|
31
|
+
return !s.startsWith('_') && !s.startsWith('.');
|
|
32
|
+
})
|
|
33
|
+
.map((r) => {
|
|
34
|
+
const p = path.join(packagespath, r);
|
|
35
|
+
const dp = path.join(distpath, packagespath, r);
|
|
36
|
+
return {
|
|
37
|
+
path: p,
|
|
38
|
+
distpath: dp,
|
|
39
|
+
fullpath: path.resolve(p),
|
|
40
|
+
fulldistpath: path.resolve(dp),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
function getPackagesData() {
|
|
46
|
+
const basePkg = getBasePackageName();
|
|
47
|
+
return getPackagePaths().map((r) => {
|
|
48
|
+
const foldername = r.path.split(path.sep).pop();
|
|
49
|
+
//
|
|
50
|
+
const jsonpath = path.join(r.path, 'package.json');
|
|
51
|
+
const jsonData = JSON.parse(readIfExists(jsonpath));
|
|
52
|
+
//
|
|
53
|
+
const pkgname = jsonData.name
|
|
54
|
+
? String(jsonData.name).split('/').pop()?.split('.').pop()
|
|
55
|
+
: foldername;
|
|
56
|
+
const fullname = basePkg + '.' + pkgname;
|
|
57
|
+
//
|
|
58
|
+
return {
|
|
59
|
+
...r,
|
|
60
|
+
fullname: fullname,
|
|
61
|
+
name: pkgname,
|
|
62
|
+
jsonData: jsonData,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function parseDeps(deps) {
|
|
67
|
+
let fromdeps = {};
|
|
68
|
+
if (!deps)
|
|
69
|
+
deps = {};
|
|
70
|
+
if (Array.isArray(deps)) {
|
|
71
|
+
deps.forEach((r) => {
|
|
72
|
+
fromdeps[r] = 'latest';
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else
|
|
76
|
+
fromdeps = deps;
|
|
77
|
+
return fromdeps;
|
|
78
|
+
}
|
|
79
|
+
function upgradedeps(fromPkg, version) {
|
|
80
|
+
const keysToCheck = ['peerDependencies', 'dependencies'];
|
|
81
|
+
for (const check_key of keysToCheck) {
|
|
82
|
+
const deps = parseDeps(fromPkg[check_key]); //make sure the key exists
|
|
83
|
+
for (const package_name in deps) {
|
|
84
|
+
if (deps[package_name].startsWith('workspace')) {
|
|
85
|
+
fromPkg[check_key][package_name] = version;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function copydeps(fromPkg, toPkg, version = '') {
|
|
91
|
+
const keysToCheck = ['peerDependencies', 'dependencies'];
|
|
92
|
+
for (const check_key of keysToCheck) {
|
|
93
|
+
const fromdeps = parseDeps(fromPkg[check_key]);
|
|
94
|
+
for (const package_name in fromdeps) {
|
|
95
|
+
if (!toPkg[check_key])
|
|
96
|
+
toPkg[check_key] = {};
|
|
97
|
+
const setVersion = String(version || fromdeps[package_name] || 'latest');
|
|
98
|
+
toPkg[check_key][package_name] = setVersion;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function getBasePackageName(basePackageJson) {
|
|
103
|
+
if (!basePackageJson)
|
|
104
|
+
basePackageJson = JSON.parse(readIfExists('package.json'));
|
|
105
|
+
return custom_trim(String(basePackageJson.name).replaceAll('workspace', ''), '.', ' ', '/');
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
13
108
|
* prepare the core package
|
|
14
|
-
*/
|
|
109
|
+
*/
|
|
110
|
+
async function prepare() {
|
|
111
|
+
const basePackageJson = JSON.parse(readIfExists('package.json'));
|
|
112
|
+
/* -------------------------- make the core package ------------------------- */
|
|
113
|
+
const coredir = './packages/core';
|
|
114
|
+
if (fs.existsSync(coredir))
|
|
115
|
+
fs.rmSync(coredir, { recursive: true, force: true });
|
|
116
|
+
const core_package_data = { ...basePackageJson };
|
|
117
|
+
core_package_data.name = getBasePackageName(basePackageJson);
|
|
118
|
+
core_package_data.private = false;
|
|
119
|
+
core_package_data.main = './index';
|
|
120
|
+
core_package_data.homepage = '.';
|
|
121
|
+
delete core_package_data.scripts;
|
|
122
|
+
delete core_package_data.soucre;
|
|
123
|
+
delete core_package_data.workspaces;
|
|
124
|
+
delete core_package_data.files;
|
|
125
|
+
/* ----------- add all of the @azcms packages to the @core package ---------- */
|
|
126
|
+
delete core_package_data.devDependencies;
|
|
127
|
+
delete core_package_data.dependencies;
|
|
128
|
+
delete core_package_data.peerDependencies;
|
|
129
|
+
const packagesData = getPackagesData();
|
|
130
|
+
copydeps({
|
|
131
|
+
dependencies: packagesData.map((r) => r.fullname),
|
|
132
|
+
peerDependencies: packagesData.map((r) => r.fullname),
|
|
133
|
+
}, core_package_data, 'workspace:^');
|
|
134
|
+
/* ------ core package must include all deps from all children packages ----- */
|
|
135
|
+
fs.mkdirSync(coredir);
|
|
136
|
+
fs.writeFileSync(path.join(coredir, 'package.json'), JSON.stringify(core_package_data, undefined, 2));
|
|
137
|
+
fs.writeFileSync(path.join(coredir, 'index.ts'), packagesData.map((r) => `export * from "${r.fullname}";`).join('\n'));
|
|
138
|
+
show_msg('created the core package');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
15
141
|
* set version of all packages in the dist path to the correct version
|
|
16
|
-
*/
|
|
142
|
+
*/
|
|
143
|
+
async function finalize() {
|
|
144
|
+
const basePackageJson = JSON.parse(readIfExists('package.json'));
|
|
145
|
+
const basePkgName = getBasePackageName(basePackageJson);
|
|
146
|
+
const distpath = getDistPath();
|
|
147
|
+
const plist = getPackagesData();
|
|
148
|
+
/* --------------------- copy all package.json into dist -------------------- */
|
|
149
|
+
await do_exec([`copyfiles ./packages/**/package.json ./dist`]);
|
|
150
|
+
/* ---------------------- fix versions of core package ---------------------- */
|
|
151
|
+
const corejsonpath = path.join(distpath, 'packages/core', 'package.json');
|
|
152
|
+
const corejson = JSON.parse(readIfExists(corejsonpath));
|
|
153
|
+
const setVersion = basePackageJson.version;
|
|
154
|
+
copydeps({
|
|
155
|
+
dependencies: plist.map((r) => r.fullname),
|
|
156
|
+
peerDependencies: plist.map((r) => r.fullname),
|
|
157
|
+
}, corejson, setVersion);
|
|
158
|
+
fs.writeFileSync(corejsonpath, JSON.stringify(corejson, undefined, 2));
|
|
159
|
+
/* -------------------------------------------------------------------------- */
|
|
160
|
+
let fixCount = 0;
|
|
161
|
+
show_msg(`working on ${plist.length} packages for ${basePkgName}`, 'text');
|
|
162
|
+
for (const pkg of plist) {
|
|
163
|
+
const jsonData = pkg.jsonData;
|
|
164
|
+
const pkgdistpath = path.join(pkg.distpath, 'package.json');
|
|
165
|
+
/* ------------------------------- fix version ------------------------------ */
|
|
166
|
+
jsonData.name = basePkgName + '.' + pkg.name; //update the version
|
|
167
|
+
jsonData.version = setVersion;
|
|
168
|
+
jsonData.description = 'module of ' + jsonData.name;
|
|
169
|
+
jsonData.private = false;
|
|
170
|
+
delete jsonData.scripts;
|
|
171
|
+
/* ----------------- add all packages of root into children ----------------- */
|
|
172
|
+
copydeps(basePackageJson, jsonData, '');
|
|
173
|
+
/* ------------------ update version of workspace packages ------------------ */
|
|
174
|
+
upgradedeps(jsonData, setVersion);
|
|
175
|
+
fs.writeFileSync(pkgdistpath, JSON.stringify(jsonData, undefined, 2));
|
|
176
|
+
const res = await do_exec([`cd ${pkg.fulldistpath}/ & npm pkg fix`]);
|
|
177
|
+
if (res.code === 0) {
|
|
178
|
+
show_msg([` -> fix:`, pkg.name, jsonData.version], 'text');
|
|
179
|
+
fixCount++;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
show_error([` -> fix failed:`, pkg.name, `error:`, res.stderr]);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
show_msg(`finalized ${fixCount} packages. you can publish them now :)`);
|
|
186
|
+
}
|
|
187
|
+
async function publish() {
|
|
188
|
+
show_msg(`publishing ...`);
|
|
189
|
+
let pcount = 0;
|
|
190
|
+
const paths = getPackagePaths(true);
|
|
191
|
+
await Promise.all(paths.map(async (p) => {
|
|
192
|
+
const res = await do_exec([
|
|
193
|
+
`cd ${p.fulldistpath}/ & npm publish --access public --tag latest`,
|
|
194
|
+
]);
|
|
195
|
+
if (res.code === 0) {
|
|
196
|
+
show_msg(['published:', p.distpath]);
|
|
197
|
+
pcount++;
|
|
198
|
+
}
|
|
199
|
+
else
|
|
200
|
+
show_error(['publish failed with code:', res.code, 'error:', res.stderr]);
|
|
201
|
+
}));
|
|
202
|
+
show_msg(`published ${pcount} packages`);
|
|
203
|
+
}
|
|
204
|
+
async function build() {
|
|
205
|
+
show_msg(`building ...`);
|
|
206
|
+
const res = await do_exec('yarn run build');
|
|
207
|
+
if (res.code === 0) {
|
|
208
|
+
show_msg(`build command was run sucessfully`);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
show_error(['build failed code:', res.code]);
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
export async function handle(args) {
|
|
217
|
+
try {
|
|
218
|
+
if (args.mode === 'go') {
|
|
219
|
+
show_div();
|
|
220
|
+
await prepare();
|
|
221
|
+
if (await build()) {
|
|
222
|
+
await finalize();
|
|
223
|
+
await publish();
|
|
224
|
+
}
|
|
225
|
+
show_div();
|
|
226
|
+
}
|
|
227
|
+
else if (args.mode === 'publish') {
|
|
228
|
+
await publish();
|
|
229
|
+
}
|
|
230
|
+
else if (args.mode === 'prepare') {
|
|
231
|
+
await prepare();
|
|
232
|
+
}
|
|
233
|
+
else if (args.mode === 'finalize') {
|
|
234
|
+
await finalize();
|
|
235
|
+
}
|
|
236
|
+
else
|
|
237
|
+
err_unknown_action(args);
|
|
238
|
+
}
|
|
239
|
+
catch (ex) {
|
|
240
|
+
return show_error(ex);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export default handle;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
2
|
Acceptable options:
|
|
3
3
|
- Keep workspace dependencies.
|
|
4
4
|
- Use latest dependencies.
|
|
5
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
export default function findAcceptableIndex(options) {
|
|
7
|
+
let depIndex = options.findIndex((s) => filterWorkspace(s));
|
|
8
|
+
if (depIndex < 0)
|
|
9
|
+
depIndex = options.findIndex((s) => filterLatest(s));
|
|
10
|
+
return depIndex;
|
|
11
|
+
}
|
|
12
|
+
const KEEP_WORKSPACE_DEPENDENCY = new RegExp('attach.*workspace', 'i');
|
|
13
|
+
function filterWorkspace(option) {
|
|
14
|
+
return KEEP_WORKSPACE_DEPENDENCY.test(option);
|
|
15
|
+
}
|
|
16
|
+
const USE_RESOLVED_FROM_LATEST = new RegExp('use.*latest', 'i');
|
|
17
|
+
function filterLatest(option) {
|
|
18
|
+
return USE_RESOLVED_FROM_LATEST.test(option);
|
|
19
|
+
}
|
package/dist/libs/up/index.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import { getProjectType, loadProjectType, } from '../commons';
|
|
2
|
+
import { show_error, show_msg } from '../commons';
|
|
3
|
+
import { update_yarn } from './update_yarn';
|
|
4
|
+
import { update_composer } from './update_composer';
|
|
5
|
+
import { update_py } from './update_py';
|
|
6
|
+
export async function handle(args) {
|
|
7
|
+
try {
|
|
8
|
+
loadProjectType(args);
|
|
9
|
+
/* -------- check if we are in a yarn package or php composer package ------- */
|
|
10
|
+
switch (getProjectType(args)) {
|
|
11
|
+
case 'php':
|
|
12
|
+
return await update_composer(args);
|
|
13
|
+
case 'yarn':
|
|
14
|
+
return await update_yarn(args);
|
|
15
|
+
case 'python':
|
|
16
|
+
return await update_py(args);
|
|
17
|
+
default:
|
|
18
|
+
return show_msg('no update steps for this project type', 'text');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (ex) {
|
|
22
|
+
return show_error(ex);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default [
|
|
26
|
+
'up <target>',
|
|
27
|
+
'update all packages while keeping workspace pacakges',
|
|
28
|
+
(yargs) => yargs.option('type', {
|
|
29
|
+
alias: 't',
|
|
30
|
+
describe: 'Specify the type of project',
|
|
31
|
+
choices: ['php', 'yarn', 'python'],
|
|
32
|
+
type: 'string',
|
|
33
|
+
}),
|
|
34
|
+
handle,
|
|
35
|
+
];
|
|
@@ -1 +1,53 @@
|
|
|
1
|
-
"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.update_composer=update_composer;var _commons=require("../commons"),_fs=_interopRequireDefault(require("fs"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function b(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function f(b,d,e,f){var g=d&&d.prototype instanceof k?d:k,h=Object.create(g.prototype),a=new B(f||[]);return E(h,"_invoke",{value:w(b,e,a)}),h}function j(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function k(){}function l(){}function m(){}function q(a){["next","throw","return"].forEach(function(c){b(a,c,function(a){return this._invoke(c,a)})})}function s(b,d){function c(e,f,g,i){var a=j(b[e],b,f);if("throw"!==a.type){var k=a.arg,l=k.value;return l&&"object"==_typeof(l)&&t.call(l,"__await")?d.resolve(l.__await).then(function(a){c("next",a,g,i)},function(a){c("throw",a,g,i)}):d.resolve(l).then(function(a){k.value=a,g(k)},function(a){return c("throw",a,g,i)})}i(a.arg)}var e;E(this,"_invoke",{value:function(a,b){function f(){return new d(function(d,e){c(a,b,d,e)})}return e=e?e.then(f,f):f()}})}function w(a,b,d){var e="suspendedStart";return function(f,g){if(e==="executing")throw Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return{value:D,done:!0}}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=x(h,d);if(i){if(i===G)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"===e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=j(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===G)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function x(b,c){var d=c.method,e=b.iterator[d];if(e===D)return c.delegate=null,"throw"===d&&b.iterator["return"]&&(c.method="return",c.arg=D,x(b,c),"throw"===c.method)||"return"!==d&&(c.method="throw",c.arg=new TypeError("The iterator does not provide a '"+d+"' method")),G;var f=j(e,b.iterator,c.arg);if("throw"===f.type)return c.method="throw",c.arg=f.arg,c.delegate=null,G;var g=f.arg;return g?g.done?(c[b.resultName]=g.value,c.next=b.nextLoc,"return"!==c.method&&(c.method="next",c.arg=D),c.delegate=null,G):g:(c.method="throw",c.arg=new TypeError("iterator result is not an object"),c.delegate=null,G)}function z(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function A(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function B(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(z,this),this.reset(!0)}function C(a){if(a||""===a){var b=a[F];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(t.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=D,b.done=!0,b};return d.next=d}}throw new TypeError(_typeof(a)+" is not iterable")}_regeneratorRuntime=function(){return h};var D,h={},e=Object.prototype,t=e.hasOwnProperty,E=Object.defineProperty||function(a,b,c){a[b]=c.value},n="function"==typeof Symbol?Symbol:{},F=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";try{b({},"")}catch(a){b=function(a,b,c){return a[b]=c}}h.wrap=f;var G={},i={};b(i,F,function(){return this});var o=Object.getPrototypeOf,d=o&&o(o(C([])));d&&d!==e&&t.call(d,F)&&(i=d);var r=m.prototype=k.prototype=Object.create(i);return l.prototype=m,E(r,"constructor",{value:m,configurable:!0}),E(m,"constructor",{value:l,configurable:!0}),l.displayName=b(m,c,"GeneratorFunction"),h.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===l||"GeneratorFunction"===(b.displayName||b.name))},h.mark=function(a){return Object.setPrototypeOf?Object.setPrototypeOf(a,m):(a.__proto__=m,b(a,c,"GeneratorFunction")),a.prototype=Object.create(r),a},h.awrap=function(a){return{__await:a}},q(s.prototype),b(s.prototype,a,function(){return this}),h.AsyncIterator=s,h.async=function(b,c,d,e,g){void 0===g&&(g=Promise);var j=new s(f(b,c,d,e),g);return h.isGeneratorFunction(c)?j:j.next().then(function(a){return a.done?a.value:j.next()})},q(r),b(r,c,"Generator"),b(r,F,function(){return this}),b(r,"toString",function(){return"[object Generator]"}),h.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},h.values=C,B.prototype={constructor:B,reset:function(a){if(this.prev=0,this.next=0,this.sent=this._sent=D,this.done=!1,this.delegate=null,this.method="next",this.arg=D,this.tryEntries.forEach(A),!a)for(var b in this)"t"===b.charAt(0)&&t.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=D)},stop:function(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function(b){function d(a,c){return h.type="throw",h.arg=b,e.next=a,c&&(e.method="next",e.arg=D),!!c}if(this.done)throw b;for(var e=this,f=this.tryEntries.length-1;0<=f;--f){var g=this.tryEntries[f],h=g.completion;if("root"===g.tryLoc)return d("end");if(g.tryLoc<=this.prev){var j=t.call(g,"catchLoc"),k=t.call(g,"finallyLoc");if(j&&k){if(this.prev<g.catchLoc)return d(g.catchLoc,!0);if(this.prev<g.finallyLoc)return d(g.finallyLoc)}else if(!j){if(!k)throw Error("try statement without catch or finally");if(this.prev<g.finallyLoc)return d(g.finallyLoc)}else if(this.prev<g.catchLoc)return d(g.catchLoc,!0)}}},abrupt:function(b,c){for(var d,e=this.tryEntries.length-1;0<=e;--e)if(d=this.tryEntries[e],d.tryLoc<=this.prev&&t.call(d,"finallyLoc")&&this.prev<d.finallyLoc){var f=d;break}f&&("break"===b||"continue"===b)&&f.tryLoc<=c&&c<=f.finallyLoc&&(f=null);var g=f?f.completion:{};return g.type=b,g.arg=c,f?(this.method="next",this.next=f.finallyLoc,G):this.complete(g)},complete:function(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),G},finish:function(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),A(b),G},catch:function(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var f=d.arg;A(b)}return f}throw Error("illegal catch attempt")},delegateYield:function(a,b,c){return this.delegate={iterator:C(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=D),G}},h}function _createForOfIteratorHelper(b,c){var d="undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(!d){if(Array.isArray(b)||(d=_unsupportedIterableToArray(b))||c&&b&&"number"==typeof b.length){d&&(b=d);var e=0,f=function(){};return{s:f,n:function(){return e>=b.length?{done:!0}:{done:!1,value:b[e++]}},e:function(a){throw a},f:f}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var g,h=!0,i=!1;return{s:function(){d=d.call(b)},n:function(){var a=d.next();return h=a.done,a},e:function(a){i=!0,g=a},f:function(){try{h||null==d["return"]||d["return"]()}finally{if(i)throw g}}}}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function asyncGeneratorStep(b,d,f,e,g,h,a){try{var c=b[h](a),i=c.value}catch(a){return void f(a)}c.done?d(i):Promise.resolve(i).then(e,g)}function _asyncToGenerator(b){return function(){var c=this,d=arguments;return new Promise(function(e,f){function g(a){asyncGeneratorStep(i,e,f,g,h,"next",a)}function h(a){asyncGeneratorStep(i,e,f,g,h,"throw",a)}var i=b.apply(c,d);g(void 0)})}}function update_composer(){return _update_composer.apply(this,arguments)}function _update_composer(){return _update_composer=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f,g,h,i,j;return _regeneratorRuntime().wrap(function k(b){for(;1;)switch(b.prev=b.next){case 0:return(0,_commons.show_msg)("cleaning composer cache..."),(0,_commons.rmIfExists)("./composer.lock",!0),_fs["default"].existsSync("./vendor/autoload.php")&&(0,_commons.rmIfExists)("./vendor",!0),b.next=5,(0,_commons.do_exec)(["composer clearcache"]);case 5:return(0,_commons.show_msg)("dump-autoload..."),b.next=8,(0,_commons.do_exec)(["composer dump-autoload"]);case 8:if(!a.prod){b.next=15;break}return(0,_commons.show_msg)("install (prod)..."),b.next=12,(0,_commons.do_exec)(["composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader"]);case 12:(0,_commons.show_msg)("install done!"),b.next=19;break;case 15:return(0,_commons.show_msg)("install (dev)..."),b.next=18,(0,_commons.do_exec)(["composer install"]);case 18:(0,_commons.show_msg)("install done!");case 19:if((0,_commons.show_msg)("updating..."),a.prod){b.next=58;break}return b.next=23,(0,_commons.do_exec)(["composer show --no-dev -f json"]);case 23:if(c=b.sent,b.prev=24,d=c.stdout.toString(),!(c.stderr+"").toLocaleLowerCase().includes("no dep")){b.next=30;break}(0,_commons.show_msg)("no composer non-dev dependencies found to update"),b.next=52;break;case 30:e=JSON.parse(d),f=e.installed,g=_createForOfIteratorHelper(f),b.prev=33,g.s();case 35:if((h=g.n()).done){b.next=44;break}return i=h.value,j=i.name,(0,_commons.show_msg)("update composer package: '".concat(j,"'")),b.next=41,(0,_commons.do_exec)(["composer require \"".concat(j,"\"")]);case 41:b.sent;case 42:b.next=35;break;case 44:b.next=49;break;case 46:b.prev=46,b.t0=b["catch"](33),g.e(b.t0);case 49:return b.prev=49,g.f(),b.finish(49);case 52:b.next=58;break;case 54:b.prev=54,b.t1=b["catch"](24),(0,_commons.show_error)("loading composer packages list failed"),(0,_commons.show_error)(b.t1+"");case 58:return b.next=60,(0,_commons.do_exec)(["composer update"]);case 60:(0,_commons.show_msg)("done");case 61:case"end":return b.stop()}},b,null,[[24,54],[33,46,49,52]])})),_update_composer.apply(this,arguments)}
|
|
1
|
+
import { do_exec, path_resolve_args, rmIfExists, show_error, show_msg } from '../commons';
|
|
2
|
+
export async function update_composer(args) {
|
|
3
|
+
show_msg(`cleaning composer cache...`);
|
|
4
|
+
const files_to_remove = [
|
|
5
|
+
path_resolve_args('./composer.lock', args),
|
|
6
|
+
path_resolve_args('./vendor', args),
|
|
7
|
+
];
|
|
8
|
+
for (const f of files_to_remove) {
|
|
9
|
+
rmIfExists(f, true);
|
|
10
|
+
}
|
|
11
|
+
await do_exec([`composer clearcache`]);
|
|
12
|
+
/* -------------------------------------------------------------------------- */
|
|
13
|
+
show_msg(`dump-autoload...`);
|
|
14
|
+
await do_exec([`composer dump-autoload`]);
|
|
15
|
+
if (args.prod) {
|
|
16
|
+
show_msg(`install (prod)...`);
|
|
17
|
+
await do_exec([
|
|
18
|
+
`composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader`,
|
|
19
|
+
]);
|
|
20
|
+
show_msg(`install done!`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
show_msg(`install (dev)...`);
|
|
24
|
+
await do_exec([`composer install`]);
|
|
25
|
+
show_msg(`install done!`);
|
|
26
|
+
}
|
|
27
|
+
show_msg(`updating...`);
|
|
28
|
+
if (!args.prod) {
|
|
29
|
+
/* ------------------------- now update each package ------------------------ */
|
|
30
|
+
const cmp_packages = await do_exec([`composer show --no-dev -f json`]);
|
|
31
|
+
try {
|
|
32
|
+
const cmp_packages_str = cmp_packages.stdout.toString();
|
|
33
|
+
if (String(cmp_packages.stderr).toLocaleLowerCase().includes('no dep')) {
|
|
34
|
+
show_msg('no composer non-dev dependencies found to update');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const cmp_packages_obj = JSON.parse(cmp_packages_str);
|
|
38
|
+
const pkg_req = cmp_packages_obj.installed;
|
|
39
|
+
for (const element of pkg_req) {
|
|
40
|
+
const pkg_name = element.name;
|
|
41
|
+
show_msg(`update composer package: '${pkg_name}'`);
|
|
42
|
+
const upd_res = await do_exec([`composer require "${pkg_name}"`]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (er) {
|
|
47
|
+
show_error(`loading composer packages list failed`);
|
|
48
|
+
show_error(String(er));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
await do_exec([`composer update`]);
|
|
52
|
+
show_msg(`done`);
|
|
53
|
+
}
|