Skip to content

Commit

Permalink
enchancement: add shipit script
Browse files Browse the repository at this point in the history
  • Loading branch information
hufeng committed Jul 21, 2021
1 parent ce18617 commit 14de5c8
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 5,570 deletions.
4 changes: 3 additions & 1 deletion package.json
@@ -1,5 +1,6 @@
{
"private": true,
"version": "4.0.0",
"workspaces": [
"packages/*"
],
Expand Down Expand Up @@ -31,6 +32,7 @@
"ts-jest": "^27.0.3",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"uuid": "3.2.1"
"uuid": "3.2.1",
"commander": "^8.0.0"
}
}
34 changes: 20 additions & 14 deletions scripts/check-license.ts → scripts/feature/check-license.ts
Expand Up @@ -20,7 +20,6 @@ import glob from 'glob'
import fs from 'fs-extra'
import chalk from 'chalk'
import prettier from 'prettier'
import pkg from '../package.json'

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

Expand Down Expand Up @@ -104,15 +103,15 @@ const meta = {
}
}

// check file apache license
;(async function checkLicense() {
// 是否需要fixed当前的文件
const fixed = process.argv[2]
/**
* check file apache license
*/
export async function checkLicense() {
const haveNoLicenceFiles = []

// 1. specify scan scope
const files = await globFiles()

const haveNoLicenceFiles = []

// 2. check weather include license or not
for await (let { file, content } of asyncReadFiles(files)) {
const cfg = getMeta(file)
Expand All @@ -126,14 +125,21 @@ const meta = {
// fixed
if (haveNoLicenceFiles.length === 0) {
console.log(chalk.greenBright(`Yes, All file have apache license`))
} else if (fixed) {
console.log(`\n fixed......`)
// fixed files
for await (let { file } of asyncWriteFiles(haveNoLicenceFiles)) {
console.log(chalk.greenBright(`${file} fixed ok`))
}
}
})()

return haveNoLicenceFiles
}

/**
* fixed license issue file
*/
export async function fixedFileLicense() {
const haveNoLicenceFiles = await checkLicense()
console.log(`\nfixed......`)
for await (let { file } of asyncWriteFiles(haveNoLicenceFiles)) {
console.log(chalk.greenBright(`${file} fixed ok`))
}
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util ~~~~~~~~~~~~~~~~~~~~~~~~~~
function globFiles(): Promise<Array<string>> {
Expand Down
129 changes: 129 additions & 0 deletions scripts/feature/prepare-release.ts
@@ -0,0 +1,129 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import fs from 'fs-extra'
import chalk, { stderr } from 'chalk'
import { checkLicense } from './check-license'
import { join } from 'path'
import { exec } from 'child_process'
import pkg from '../../package.json'

/**
* source code release, auto pipeline
* install before prepare release:
* - maven
* - ts-node
* - lerna
*/

export async function prepareRelease(dest: string) {
console.log(chalk.greenBright(`- check license`))
// check license
const noLicenseFiles = await checkLicense()
if (noLicenseFiles.length > 0) {
return
}

// copy current project to dest dir
const outputDir = join(dest, 'dubbo-js')
console.log(chalk.greenBright(`\n- export dubbo-js to ${outputDir} dir`))
fs.copySync('../', outputDir)

// clean each module lib
console.log(chalk.greenBright(`\n- clean node_modules`))
await sh`
cd ${outputDir}
lerna clean -y
rm -rf node_modules
`

// clean .git
console.log(chalk.greenBright(`\n- clean .git`))
await sh`
cd ${outputDir}
rm -rf .git
`

// clean __MACOSX and .DS_Store
console.log(chalk.greenBright(`\n- clean __MACOSX and .DS_Store`))
await sh`
cd ${outputDir}
find . | grep .DS_Store | xargs rm
find . | grep __MACOSX | xargs rm
`

// clean java target class
console.log(chalk.greenBright(`\n- clean dubbo-demo`))
await sh`
cd ${outputDir}/dubbo-java/dubbo-demo
mvn clean
`

// clean example node_modules
console.log(chalk.greenBright(`\n- clean example node_modules`))
await sh`
cd ${outputDir}
rm -rf fullstack/node_modules
rm -rf hello-egg/node_modules
rm -rf hello-koa/node_modules
rm -rf hello-midway/node_modules
`

// clean misc files
console.log(chalk.greenBright(`\n- clean misc files`))
await sh`
cd ${outputDir}
rm package-lock.json
rm -rf package-lock.json
rm -rf .idea
rm -rf coverage
rm -rf examples/hello-egg/typings
rm -rf examples/hello-midway/src/typings
rm -rf dubbo-java/nacos-docker/example/standalone-logs/
`

// zip source dir
console.log(chalk.greenBright(`\n- zip dubbo-js dir`))
await sh`
cd ${dest}
zip -r apache-dubbo-js-${pkg.version}-source-release.zip ${outputDir}
shasum -a 512 apache-dubbo-js-${pkg.version}-source-release.zip >> apache-dubbo-js-${pkg.version}-source-release.zip.sha512
gpg -ab apache-dubbo-js-${pkg.version}-source-release.zip
gpg --verify apache-dubbo-js-${pkg.version}-source-release.zip.asc apache-dubbo-js-${pkg.version}-source-release.zip
`
}

function sh(str: TemplateStringsArray, ...keys: Array<string>) {
const shell = str.reduce((r, v, i) => {
r += v
if (i < keys.length) {
r += keys[i]
}
return r
}, '')
return new Promise((resolve, reject) => {
console.log(chalk.greenBright(shell))
exec(shell, (err, stdout, stderr) => {
if (err) {
reject(err)
return
}
console.log(chalk.greenBright(stdout || stderr))
resolve(stdout || stderr)
})
})
}
46 changes: 46 additions & 0 deletions scripts/shipit.ts
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Command } from 'commander'
import { checkLicense, fixedFileLicense } from './feature/check-license'
import { prepareRelease } from './feature/prepare-release'

const program = new Command()

program
.version('1.0.0', '-v, --version', 'output the current version')
.description('🚀 dubbo-js shipit tools 🚀')

program
.command('check-license [fixed]')
.description('check file license')
.action(async (fixed = '') => {
if (fixed !== 'fixed') {
checkLicense()
} else {
fixedFileLicense()
}
})

program
.command('prepare-release [dest]')
.description('prepare source release')
.action((dest: string = '/tmp') => {
prepareRelease(dest)
})

program.parse(process.argv)

0 comments on commit 14de5c8

Please sign in to comment.