|
| 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 | +} |
0 commit comments