|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -const utils = require('../utils'); |
4 | | -const path = require('path'); |
5 | | -const validateConfig = require('../validateConfig'); |
6 | | -const config = require(path.resolve('package.json')); |
7 | | -const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH || utils.ghActionsBranch(process.env); |
| 3 | +import { ghActionsBranch } from '../utils.js'; |
| 4 | +import { resolve } from 'path'; |
| 5 | +import validateConfig from '../validateConfig.js'; |
| 6 | +const config = require(resolve('package.json')); |
| 7 | +const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH || ghActionsBranch(process.env); |
8 | 8 | const branchTags = config.release && config.release.branchTags; |
9 | 9 | const tag = branchTags && branchTags[branch]; |
10 | 10 | const dryRun = process.argv.find(arg => /^(--dry-run|-n)$/.test(arg)); |
11 | 11 | const publicPackage = process.argv.find(arg => /^(--public)$/.test(arg)); |
12 | 12 | const validate = process.argv.find(arg => /^(--validate|-v)$/.test(arg)); |
13 | | -const command = [ 'npm', 'publish' ]; |
| 13 | +const command = ['npm', 'publish']; |
14 | 14 |
|
15 | 15 | if (validate) { |
16 | | - validateConfig(config); |
17 | | - return; |
18 | | -} |
| 16 | + validateConfig(config); |
| 17 | + // return; |
| 18 | +} else { |
| 19 | + if (tag) { |
| 20 | + command.push('--tag', tag); |
| 21 | + } |
19 | 22 |
|
20 | | -if (tag) { |
21 | | - command.push('--tag', tag); |
22 | | -} |
| 23 | + if (publicPackage) { |
| 24 | + command.push('--access=public'); |
| 25 | + } |
23 | 26 |
|
24 | | -if (publicPackage) { |
25 | | - command.push('--access=public'); |
26 | | -} |
| 27 | + if (!branchTags) { |
| 28 | + console.warn('[WARN] No branch tag configuration'); |
| 29 | + } |
27 | 30 |
|
28 | | -if (!branchTags) { |
29 | | - console.warn('[WARN] No branch tag configuration'); |
30 | | -} |
31 | | - |
32 | | -if (dryRun) { |
33 | | - console.log(command.join(' ')); |
34 | | -} else { |
35 | | - const exec = require('child_process').exec; |
36 | | - exec(command.join(' '), function(error, stdout, stderr) { |
37 | | - console.log(stdout); |
| 31 | + if (dryRun) { |
| 32 | + console.log(command.join(' ')); |
| 33 | + } else { |
| 34 | + const exec = require('child_process').exec; |
| 35 | + exec(command.join(' '), function (error, stdout, stderr) { |
| 36 | + console.log(stdout); |
38 | 37 |
|
39 | | - if (error) { |
40 | | - console.error(`[ERROR] npm publish: ${stderr}`); |
41 | | - process.exit(1); |
42 | | - } |
43 | | - }); |
| 38 | + if (error) { |
| 39 | + console.error(`[ERROR] npm publish: ${stderr}`); |
| 40 | + process.exit(1); |
| 41 | + } |
| 42 | + }); |
| 43 | + } |
44 | 44 | } |
0 commit comments