Skip to content

Commit ba65a3f

Browse files
committed
feat(omni release): npm publish support OTP
1 parent 8613c93 commit ba65a3f

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
English | [简体中文](./CHANGELOG.zh-CN.md)
44

55
## v2.4.x
6+
### v2.4.3
7+
1. 「optimization」 `omni release` npm publish support OTP
8+
69
### v2.4.2
710
1. 「optimization」 `omni build` pass params to the rollup custom config
811

docs/CHANGELOG.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
[English](./CHANGELOG.md) | 简体中文
44

55
## v2.4.x
6+
### v2.4.3
7+
1. 「optimization」 `omni release` npm publish 支持两步验证(OTP)
8+
69
### v2.4.2
710
1. 「optimization」 `omni build` rollup 自定义配置文件的参数传递
811

src/commands/release/index.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
nodeVersionCheck,
1616
logPrefix
1717
} from '@omni-door/utils';
18+
import { spawn } from 'child_process';
1819
import { getHandlers, signal, logo } from '../../utils';
1920
import buildCommands from '../build';
2021
/* import types */
@@ -353,14 +354,45 @@ export default async function (
353354
}, () => {}, true
354355
);
355356

356-
await exec(
357-
[`npm publish --registry=${npm || npmUrl} --tag=${tag}`],
358-
() => {
359-
logEmph(`The npm-package publish success with version ${pkj.version}@${tag}!`);
360-
logEmph(`npm包发布成功, 版本号为 ${pkj.version}@${tag}!`);
361-
},
362-
handleReleaseErr('The npm-package publish failed(npm包发布失败)!')
363-
);
357+
await new Promise((resolve, reject) => {
358+
const npm_publish = spawn(
359+
'npm',
360+
[
361+
'publish',
362+
`--registry=${(npm && typeof npm === 'string') ? npm : npmUrl}`,
363+
`--tag=${tag}`,
364+
'--access public'
365+
],
366+
{
367+
detached: true,
368+
stdio: 'inherit'
369+
}
370+
);
371+
372+
if (npm_publish.stdout) {
373+
npm_publish.stdout.on('data', data => {
374+
console.info(data.toString());
375+
});
376+
}
377+
378+
if (npm_publish.stderr) {
379+
npm_publish.stderr.on('data', data => {
380+
console.info(data.toString());
381+
});
382+
}
383+
384+
npm_publish.on('error', handleReleaseErr('The npm-package publish failed(npm包发布失败)!'));
385+
386+
npm_publish.on('close', code => {
387+
if (code === 0) {
388+
logEmph(`The npm-package publish success with version ${pkj.version}@${tag}!`);
389+
logEmph(`npm包发布成功, 版本号为 ${pkj.version}@${tag}!`);
390+
resolve(null);
391+
} else {
392+
reject();
393+
}
394+
});
395+
});
364396
}
365397

366398
// handle release plugins

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export interface OmniConfig {
113113
};
114114
release: {
115115
git?: string;
116-
npm?: string;
116+
npm?: string | boolean;
117117
autoBuild?: boolean;
118118
autoTag?: boolean;
119119
preflight?: {

0 commit comments

Comments
 (0)