Skip to content

Commit 14de5c8

Browse files
committed
enchancement: add shipit script
1 parent ce18617 commit 14de5c8

File tree

5 files changed

+198
-5570
lines changed

5 files changed

+198
-5570
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"private": true,
3+
"version": "4.0.0",
34
"workspaces": [
45
"packages/*"
56
],
@@ -31,6 +32,7 @@
3132
"ts-jest": "^27.0.3",
3233
"ts-node": "^9.1.1",
3334
"typescript": "^4.2.4",
34-
"uuid": "3.2.1"
35+
"uuid": "3.2.1",
36+
"commander": "^8.0.0"
3537
}
3638
}
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import glob from 'glob'
2020
import fs from 'fs-extra'
2121
import chalk from 'chalk'
2222
import prettier from 'prettier'
23-
import pkg from '../package.json'
2423

2524
const prettierConfig = fs.readJSONSync('../.prettierrc')
2625

@@ -104,15 +103,15 @@ const meta = {
104103
}
105104
}
106105

107-
// check file apache license
108-
;(async function checkLicense() {
109-
// 是否需要fixed当前的文件
110-
const fixed = process.argv[2]
106+
/**
107+
* check file apache license
108+
*/
109+
export async function checkLicense() {
110+
const haveNoLicenceFiles = []
111+
111112
// 1. specify scan scope
112113
const files = await globFiles()
113114

114-
const haveNoLicenceFiles = []
115-
116115
// 2. check weather include license or not
117116
for await (let { file, content } of asyncReadFiles(files)) {
118117
const cfg = getMeta(file)
@@ -126,14 +125,21 @@ const meta = {
126125
// fixed
127126
if (haveNoLicenceFiles.length === 0) {
128127
console.log(chalk.greenBright(`Yes, All file have apache license`))
129-
} else if (fixed) {
130-
console.log(`\n fixed......`)
131-
// fixed files
132-
for await (let { file } of asyncWriteFiles(haveNoLicenceFiles)) {
133-
console.log(chalk.greenBright(`${file} fixed ok`))
134-
}
135128
}
136-
})()
129+
130+
return haveNoLicenceFiles
131+
}
132+
133+
/**
134+
* fixed license issue file
135+
*/
136+
export async function fixedFileLicense() {
137+
const haveNoLicenceFiles = await checkLicense()
138+
console.log(`\nfixed......`)
139+
for await (let { file } of asyncWriteFiles(haveNoLicenceFiles)) {
140+
console.log(chalk.greenBright(`${file} fixed ok`))
141+
}
142+
}
137143

138144
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util ~~~~~~~~~~~~~~~~~~~~~~~~~~
139145
function globFiles(): Promise<Array<string>> {

scripts/feature/prepare-release.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import fs from 'fs-extra'
19+
import chalk, { stderr } from 'chalk'
20+
import { checkLicense } from './check-license'
21+
import { join } from 'path'
22+
import { exec } from 'child_process'
23+
import pkg from '../../package.json'
24+
25+
/**
26+
* source code release, auto pipeline
27+
* install before prepare release:
28+
* - maven
29+
* - ts-node
30+
* - lerna
31+
*/
32+
33+
export async function prepareRelease(dest: string) {
34+
console.log(chalk.greenBright(`- check license`))
35+
// check license
36+
const noLicenseFiles = await checkLicense()
37+
if (noLicenseFiles.length > 0) {
38+
return
39+
}
40+
41+
// copy current project to dest dir
42+
const outputDir = join(dest, 'dubbo-js')
43+
console.log(chalk.greenBright(`\n- export dubbo-js to ${outputDir} dir`))
44+
fs.copySync('../', outputDir)
45+
46+
// clean each module lib
47+
console.log(chalk.greenBright(`\n- clean node_modules`))
48+
await sh`
49+
cd ${outputDir}
50+
lerna clean -y
51+
rm -rf node_modules
52+
`
53+
54+
// clean .git
55+
console.log(chalk.greenBright(`\n- clean .git`))
56+
await sh`
57+
cd ${outputDir}
58+
rm -rf .git
59+
`
60+
61+
// clean __MACOSX and .DS_Store
62+
console.log(chalk.greenBright(`\n- clean __MACOSX and .DS_Store`))
63+
await sh`
64+
cd ${outputDir}
65+
find . | grep .DS_Store | xargs rm
66+
find . | grep __MACOSX | xargs rm
67+
`
68+
69+
// clean java target class
70+
console.log(chalk.greenBright(`\n- clean dubbo-demo`))
71+
await sh`
72+
cd ${outputDir}/dubbo-java/dubbo-demo
73+
mvn clean
74+
`
75+
76+
// clean example node_modules
77+
console.log(chalk.greenBright(`\n- clean example node_modules`))
78+
await sh`
79+
cd ${outputDir}
80+
rm -rf fullstack/node_modules
81+
rm -rf hello-egg/node_modules
82+
rm -rf hello-koa/node_modules
83+
rm -rf hello-midway/node_modules
84+
`
85+
86+
// clean misc files
87+
console.log(chalk.greenBright(`\n- clean misc files`))
88+
await sh`
89+
cd ${outputDir}
90+
rm package-lock.json
91+
rm -rf package-lock.json
92+
rm -rf .idea
93+
rm -rf coverage
94+
rm -rf examples/hello-egg/typings
95+
rm -rf examples/hello-midway/src/typings
96+
rm -rf dubbo-java/nacos-docker/example/standalone-logs/
97+
`
98+
99+
// zip source dir
100+
console.log(chalk.greenBright(`\n- zip dubbo-js dir`))
101+
await sh`
102+
cd ${dest}
103+
zip -r apache-dubbo-js-${pkg.version}-source-release.zip ${outputDir}
104+
shasum -a 512 apache-dubbo-js-${pkg.version}-source-release.zip >> apache-dubbo-js-${pkg.version}-source-release.zip.sha512
105+
gpg -ab apache-dubbo-js-${pkg.version}-source-release.zip
106+
gpg --verify apache-dubbo-js-${pkg.version}-source-release.zip.asc apache-dubbo-js-${pkg.version}-source-release.zip
107+
`
108+
}
109+
110+
function sh(str: TemplateStringsArray, ...keys: Array<string>) {
111+
const shell = str.reduce((r, v, i) => {
112+
r += v
113+
if (i < keys.length) {
114+
r += keys[i]
115+
}
116+
return r
117+
}, '')
118+
return new Promise((resolve, reject) => {
119+
console.log(chalk.greenBright(shell))
120+
exec(shell, (err, stdout, stderr) => {
121+
if (err) {
122+
reject(err)
123+
return
124+
}
125+
console.log(chalk.greenBright(stdout || stderr))
126+
resolve(stdout || stderr)
127+
})
128+
})
129+
}

scripts/shipit.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { Command } from 'commander'
19+
import { checkLicense, fixedFileLicense } from './feature/check-license'
20+
import { prepareRelease } from './feature/prepare-release'
21+
22+
const program = new Command()
23+
24+
program
25+
.version('1.0.0', '-v, --version', 'output the current version')
26+
.description('🚀 dubbo-js shipit tools 🚀')
27+
28+
program
29+
.command('check-license [fixed]')
30+
.description('check file license')
31+
.action(async (fixed = '') => {
32+
if (fixed !== 'fixed') {
33+
checkLicense()
34+
} else {
35+
fixedFileLicense()
36+
}
37+
})
38+
39+
program
40+
.command('prepare-release [dest]')
41+
.description('prepare source release')
42+
.action((dest: string = '/tmp') => {
43+
prepareRelease(dest)
44+
})
45+
46+
program.parse(process.argv)

0 commit comments

Comments
 (0)