forked from erda-project/erda-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherda.ts
executable file
·132 lines (118 loc) · 4.71 KB
/
erda.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
// Copyright (c) 2021 Terminus, Inc.
//
// This program is free software: you can use, redistribute, and/or modify
// it under the terms of the GNU Affero General Public License, version 3
// or later ("AGPL"), as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import path from 'path';
import { Command } from 'commander';
import inquirer from 'inquirer';
import build from '../lib/build';
import release from '../lib/release';
import addLicense from '../lib/add-license';
import checkLicense from '../lib/check-license';
import launcher from '../lib/launcher';
import init from '../lib/init';
import i18n from '../lib/i18n';
import generateService from '../lib/service-generator';
import checkCliVersion from '../lib/check-cli-version';
import checkBuildStatus from '../lib/check-build-status';
const program = new Command();
inquirer.registerPrompt('directory', require('inquirer-select-directory'));
program.version(`erda-ui/cli ${require('../../package').version}`).usage('<command> [options]');
program
.command('init')
.description('install dependency & initialize .env config')
.option('-s, --skip', 'skip the cli version check')
.option('-p, --port <port>', 'set scheduler port')
.option('-b, --backendUrl <backendUrl>', 'set backend(api) url')
.option('-o, --override', 'ignore current .env file and override')
.option('-ol, --online', 'is online execution')
.action(async (options) => {
init(options);
await checkCliVersion(options);
});
program
.command('build')
.description(
'bundle files to public directory, pass true to launch a local full compilation build, pass image sha to launch a local partial compilation build based on image',
)
.option('-i, --image <image>', 'image sha as build base, e.g. 1.0-20210506-48bd74')
.option('-l, --local', 'enable local mode, if image arg is given, then local mode is forcibly')
.option('-s, --skip', 'skip the cli version check')
.option('-m, --enableSourceMap', 'generate source map')
.option('-o, --online', 'whether is online build')
.action(async (options) => {
await checkCliVersion(options);
build(options);
});
program
.command('release')
.description('build & push docker image')
.option('-i, --image <image>', 'image sha as build base, e.g. 1.0-20210506-48bd74')
.option('-l, --local', 'enable local mode, if image arg is given, then local mode is forcibly')
.option('-s, --skip', 'skip the cli version check')
.option('-m, --enableSourceMap', 'generate source map')
.action((options) => {
release(options);
});
program
.command('i18n [workDir]')
.description('translate words in work dir')
.option('-s, --skip', 'skip the cli version check')
.action(async (_workDir, options) => {
await checkCliVersion(options);
const workDir = _workDir ? path.resolve(process.cwd(), _workDir) : process.cwd();
i18n({ workDir });
});
program
.command('generate-service [workDir]')
.description('generate service by API swagger')
.option('-s, --skip', 'skip the cli version check')
.action(async (_workDir, options) => {
await checkCliVersion(options);
const workDir = _workDir ? path.resolve(process.cwd(), _workDir) : process.cwd();
generateService({ workDir });
});
program
.command('add-license')
.option('-t, --fileType <file_type>', 'File type', 'js,ts,jsx,tsx')
.description('add license header in files if not exist')
.action(({ fileType }) => {
addLicense({ fileType });
});
program
.command('check-license')
.option('-t, --fileType <file_type>', 'File type', 'js,ts,jsx,tsx')
.option('-d, --directory <directory>', 'work directory')
.option('-f, --filter <filter>', 'filter log', 'warn')
.description('check license header in files')
.action(({ fileType, directory, filter }) => {
checkLicense({ fileType, directory, filter });
});
program
.command('launch')
.description('launch erda ui in development mode')
.option('-s, --skip', 'skip the cli version check')
.action(async (options) => {
await checkCliVersion(options);
launcher();
});
program
.command('check-build-status')
.description(
'compare git commit sha with previous build, if match it will skip build and reuse last built files. Only used in pipeline build',
)
.option('-s, --skip', 'skip the cli version check')
.action(async (options) => {
await checkCliVersion(options);
checkBuildStatus();
});
program.parse(process.argv);