Skip to content

Commit

Permalink
feat: release支持配置源地址
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed May 21, 2021
1 parent e33bb1c commit 25c581c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/cli-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export interface IConfig extends IProjectConfig {
release: {
// before hooks for run lint test build...
beforeRelease: ICmd[]
changelog: boolean
registry: string
// in lenra mode to ensure pkg publish order
order: string[]
branch: string
Expand Down
13 changes: 9 additions & 4 deletions packages/preset-built-in/src/plugin/command/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export default createPlugin({
'lint',
{
desc: 'a command for lint js/css',
usage: `xus lint `
usage: `xus lint `,
options: {
'--fix': 'lint and fix'
}
},
async () => {
async (cmdArgs) => {
const lintConfig = api.projectConfig.lint
let eslintRes = true
let stylelintRes = true
Expand All @@ -25,7 +28,7 @@ export default createPlugin({
cext.length > 0 ? cext : ['.js', '.jsx', '.ts', '.tsx', '.vue']
const args = [
'eslint',
'--fix',
cmdArgs?.fix && '--fix',
'--ext',
ext.join(','),
...include
Expand All @@ -46,7 +49,9 @@ export default createPlugin({
const ic = stylelint?.include || []
const include = ic.length > 0 ? ic : []
// ['./**/*.css', './**/*.vue', './**/*.less', './**/*.sass']
const args = ['stylelint', ...include].concat(['--fix'])
const args = ['stylelint', ...include].concat(
[cmdArgs?.fix && '--fix'].filter(Boolean)
)
api.logger.debug(`run stylelint with `)
api.logger.debug(args)
stylelintRes = await runCmd('npx', args, {
Expand Down
29 changes: 21 additions & 8 deletions packages/preset-built-in/src/plugin/command/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ async function publish(targets: string[], ops: IReleaseOps) {

// 3. generate changelog
// 4. commit changes
const runRes = await [
{
const cmds = [
ops?.changelog && {
bin: 'npx',
args: ['xus', 'changelog'],
message: {
Expand Down Expand Up @@ -222,7 +222,16 @@ async function publish(targets: string[], ops: IReleaseOps) {
failed: 'commit changes failed'
}
}
].reduce((p, cmd) => {
].filter(Boolean) as {
bin: string
args: string[]
message: {
start: string
succeed: string
failed: string
}
}[]
const runRes = await cmds.reduce((p, cmd) => {
return p.then(() => runCmd(cmd.bin, cmd.args, cmd.message))
}, Promise.resolve(true))
if (!runRes) return
Expand Down Expand Up @@ -311,11 +320,15 @@ async function workForPublish(pkgDir: string, ops: IReleaseOps) {
const pkgname = pkgdir2pkgname[pkgDir]
const saveCwd = process.cwd()
process.chdir(root)
await runCmd('npm', ['publish', '--access', 'public'], {
start: `publish ${pkgname} start`,
succeed: `publish ${pkgname} succeed`,
failed: `publish ${pkgname} failed`
})
await runCmd(
'npm',
['publish', '--access', 'public', '--registry', ops.registry],
{
start: `publish ${pkgname} start`,
succeed: `publish ${pkgname} succeed`,
failed: `publish ${pkgname} failed`
}
)
process.chdir(saveCwd)
}

Expand Down
4 changes: 4 additions & 0 deletions packages/preset-built-in/src/plugin/config/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type ICmd = {
export type IReleaseConfig = {
// before hooks for run lint test build...
beforeRelease: ICmd[]
changelog: boolean
registry: string
// in lenra mode to ensure pkg publish order
order: string[]
branch: string
Expand All @@ -36,6 +38,8 @@ export const releaseSchema = createSchema<IReleaseConfig>((joi) => {
export function defaultReleaseConfig(): IReleaseConfig {
return {
beforeRelease: [],
changelog: false,
registry: 'https://registry.npmjs.org/',
order: [],
branch: 'master'
}
Expand Down

0 comments on commit 25c581c

Please sign in to comment.