-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
334 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const config = { | ||
target: 'node16', | ||
output: { | ||
path: 'dist', | ||
module: true, | ||
}, | ||
entry: { | ||
cli: './lib/bin.mjs', | ||
}, | ||
externals: { | ||
yargs: 'yargs', | ||
}, | ||
optimization: { | ||
// splitChunks: { | ||
// cacheGroups: { | ||
// vendors: { | ||
// name: 'share', | ||
// chunks: 'all', | ||
// minChunks: 2, | ||
// enforce: true, | ||
// reuseExistingChunk: true, | ||
// }, | ||
// }, | ||
// }, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Cheetor } from 'cheetor'; | ||
|
||
import * as pack from '@bring-it/utils/cmd/pack.mjs'; | ||
|
||
new Cheetor('../package.json', import.meta.url) | ||
.command(pack) | ||
.commandSafe('@bring-it/notify/dist/sub.mjs') | ||
.commandSafe('@bring-it/npm/dist/sub.mjs') | ||
.commandSafe('@bring-it/sample/dist/sub.mjs') | ||
.commandSafe('@bring-it/sentry/dist/sub.mjs') | ||
.commandSafe('@bring-it/sftp/dist/sub.mjs') | ||
.config((cli) => cli.wrap(null)) | ||
.setup(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@bring-it/cli", | ||
"version": "0.8.0", | ||
"description": "Common command line interface of 'bring-it'", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Eric Chen", | ||
"email": "[email protected]" | ||
}, | ||
"keywords": [ | ||
"bring-it", | ||
"ci", | ||
"cli", | ||
"deploy", | ||
"deployment", | ||
"frontend", | ||
"release" | ||
], | ||
"homepage": "https://github.com/airkro/bring-it/tree/master/packages/cli", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/airkro/bring-it.git", | ||
"directory": "packages/cli" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/airkro/bring-it/issues" | ||
}, | ||
"bin": { | ||
"bring-it": "dist/cli.mjs" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
"scripts": { | ||
"build": "best-shot prod", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"yargs": "^17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@bring-it/utils": "*", | ||
"cheetor": "^0.13.0" | ||
}, | ||
"engines": { | ||
"node": "^18.0.0 || ^20.0.0", | ||
"npm": ">=9.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const config = { | ||
target: 'node18', | ||
output: { | ||
path: 'dist', | ||
module: true, | ||
}, | ||
entry: { | ||
sub: './lib/cmd.mjs', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Logger, readConfig } from '@bring-it/utils/index.mjs'; | ||
|
||
import { createContent, dingtalk } from './utils.mjs'; | ||
|
||
const task = 'notify'; | ||
|
||
const logger = new Logger(task); | ||
|
||
const { DingTalkRobotToken } = process.env; | ||
|
||
// eslint-disable-next-line consistent-return | ||
export async function action({ mode }) { | ||
if (!DingTalkRobotToken) { | ||
logger.fail('env.DingTalkRobotToken is required'); | ||
|
||
process.exitCode = -1; | ||
|
||
return false; | ||
} | ||
|
||
try { | ||
const { [mode]: config, ...rest } = await readConfig(task, logger); | ||
|
||
const all = { ...rest, ...config }; | ||
|
||
const { project } = all; | ||
|
||
logger.json({ | ||
mode, | ||
project, | ||
}); | ||
|
||
logger.task('checking...'); | ||
|
||
dingtalk({ | ||
markdown: createContent(all), | ||
title: project, | ||
token: DingTalkRobotToken, | ||
}) | ||
.then(console.log) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); | ||
} catch (error) { | ||
logger.fail(error.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export const command = 'notify'; | ||
|
||
export const describe = 'Send releases notifications'; | ||
|
||
export function builder(cli) { | ||
cli.option('mode', { | ||
alias: 'm', | ||
describe: 'notify mode', | ||
default: 'noop', | ||
type: 'string', | ||
}); | ||
} | ||
|
||
export function handler(io) { | ||
import('./action.mjs') | ||
.then(({ action }) => action(io)) | ||
.catch((error) => { | ||
process.exitCode = 1; | ||
console.error(error); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { http } from '@bring-it/utils/index.mjs'; | ||
|
||
const { | ||
BRANCH_NAME, | ||
CCI_JOB_NAME, | ||
CI_BUILD_NUMBER, | ||
DEPOT_NAME, | ||
GIT_COMMIT_SHORT, | ||
GIT_COMMIT, | ||
GIT_HTTP_URL, | ||
JOB_ID, | ||
npm_package_version, | ||
PROJECT_NAME, | ||
PROJECT_WEB_URL, | ||
} = process.env; | ||
|
||
export function dingtalk({ markdown, title, token }) { | ||
return http({ | ||
url: 'https://oapi.dingtalk.com/robot/send', | ||
query: { access_token: token }, | ||
method: 'POST', | ||
json: { | ||
msgtype: 'markdown', | ||
markdown: { | ||
title, | ||
text: markdown | ||
.trim() | ||
// eslint-disable-next-line unicorn/prefer-string-replace-all | ||
.replace(/\n\n/g, '\n\n<br/>\n\n'), | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
export function createContent({ description, type }) { | ||
return ` | ||
### ${CCI_JOB_NAME} | ||
[${PROJECT_NAME}](${PROJECT_WEB_URL}) 发布了新的版本 | ||
- 所属项目:${description} | ||
- 发布类型:${type} | ||
- 版本编号:${npm_package_version} | ||
请择时部署到 **线上** 环境 | ||
- 代码仓库:[${DEPOT_NAME}](${GIT_HTTP_URL}) | ||
- 执行分支:[${BRANCH_NAME}](${PROJECT_WEB_URL}/d/${DEPOT_NAME}/git/tree/${BRANCH_NAME}) | ||
- 版本变更:[${GIT_COMMIT_SHORT}](${PROJECT_WEB_URL}/d/${DEPOT_NAME}/git/commit/${GIT_COMMIT}) | ||
- 构建产物:[CI - #${CI_BUILD_NUMBER}](${PROJECT_WEB_URL}/ci/job/${JOB_ID}/build/${CI_BUILD_NUMBER}/artifacts) | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "@bring-it/notify", | ||
"version": "0.0.0", | ||
"description": "Send releases notifications", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Eric Chen", | ||
"email": "[email protected]" | ||
}, | ||
"keywords": [ | ||
"bring-it", | ||
"ci", | ||
"cli", | ||
"deployment", | ||
"dingtalk", | ||
"frontend", | ||
"release", | ||
"wechat", | ||
"wecom" | ||
], | ||
"homepage": "https://github.com/airkro/bring-it/tree/master/packages/notify", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/airkro/bring-it.git", | ||
"directory": "packages/notify" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/airkro/bring-it/issues" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"type": "module", | ||
"scripts": { | ||
"build": "best-shot prod", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"peerDependencies": { | ||
"@bring-it/cli": "^0.8.0" | ||
}, | ||
"engines": { | ||
"node": "^18.0.0 || ^20.0.0", | ||
"npm": ">=9.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters