11import * as process from 'node:process' ;
22import * as fs from 'node:fs' ;
33import { execSync } from 'node:child_process' ;
4+ import pkg from './package.json' with { type : 'json' } ;
45
5- const PKG = JSON . parse ( fs . readFileSync ( './package.json' ) . toString ( ) ) ;
66const RELEASE_BRANCH = 'master' ;
77
88// Paths for ESLint to check. Converted to string for convenience.
@@ -32,12 +32,12 @@ const PRETTIER_PATHS = [
3232] . join ( ' ' ) ;
3333
3434const task = process . argv [ 2 ] ;
35- const args = process . argv . slice ( 3 ) . join ( ' ' ) ;
35+ const taskArgs = process . argv . slice ( 3 ) . join ( ' ' ) ;
3636
3737void run ( ) ;
3838
3939async function run ( ) {
40- logInfo ( args ? `[args:"${ args } "]` : '' ) ;
40+ logInfo ( taskArgs ? `[args:"${ taskArgs } "]` : '' ) ;
4141
4242 switch ( task ) {
4343 // As per NPM documentation (https://docs.npmjs.com/cli/v9/using-npm/scripts)
@@ -89,7 +89,7 @@ async function run() {
8989 }
9090
9191 case 'coverage' : {
92- executeCmd ( `jest --coverage ${ args } ` ) ;
92+ executeCmd ( `jest --coverage ${ taskArgs } ` ) ;
9393 executeCmd ( 'open-cli coverage/lcov-report/index.html' ) ;
9494
9595 break ;
@@ -103,11 +103,11 @@ async function run() {
103103
104104 case 'release' : {
105105 checkRelease ( ) ;
106- executeCmd ( `git commit -am '${ PKG . version } '` ) ;
107- executeCmd ( `git tag -a ${ PKG . version } -m '${ PKG . version } '` ) ;
106+ executeCmd ( `git commit -am '${ pkg . version } '` ) ;
107+ executeCmd ( `git tag -a ${ pkg . version } -m '${ pkg . version } '` ) ;
108108 executeCmd ( `git push origin ${ RELEASE_BRANCH } ` ) ;
109- executeCmd ( `git push origin '${ PKG . version } '` ) ;
110- executeCmd ( 'npm publish' ) ;
109+ executeCmd ( `git push origin '${ pkg . version } '` ) ;
110+ executeInteractiveCmd ( 'npm publish' ) ;
111111
112112 break ;
113113 }
@@ -194,7 +194,7 @@ function format() {
194194function test ( ) {
195195 logInfo ( 'test()' ) ;
196196
197- executeCmd ( `jest --silent false --detectOpenHandles ${ args } ` ) ;
197+ executeCmd ( `jest --silent false --detectOpenHandles ${ taskArgs } ` ) ;
198198}
199199
200200function installDeps ( ) {
@@ -244,20 +244,32 @@ function executeCmd(command) {
244244 }
245245}
246246
247- function logInfo ( message ) {
247+ function executeInteractiveCmd ( command ) {
248+ logInfo ( `executeInteractiveCmd(): ${ command } ` ) ;
249+
250+ try {
251+ execSync ( command , { stdio : 'inherit' , env : process . env } ) ;
252+ } catch ( error ) {
253+ logError ( `executeInteractiveCmd() failed, exiting: ${ error } ` ) ;
254+
255+ exitWithError ( ) ;
256+ }
257+ }
258+
259+ function logInfo ( ...args ) {
248260 // eslint-disable-next-line no-console
249- console . log ( `npm-scripts \x1b[36m[INFO] [${ task } ]\x1b[0m` , message ) ;
261+ console . log ( `npm-scripts.mjs \x1b[36m[INFO] [${ task } ]\x1b[0m` , ... args ) ;
250262}
251263
252264// eslint-disable-next-line no-unused-vars
253- function logWarn ( message ) {
265+ function logWarn ( ... args ) {
254266 // eslint-disable-next-line no-console
255- console . warn ( `npm-scripts \x1b[33m[WARN] [${ task } ]\x1b[ 0m` , message ) ;
267+ console . warn ( `npm-scripts.mjs \x1b[33m[WARN] [${ task } ]\x1b\ 0m` , ... args ) ;
256268}
257269
258- function logError ( message ) {
270+ function logError ( ... args ) {
259271 // eslint-disable-next-line no-console
260- console . error ( `npm-scripts \x1b[31m[ERROR] [${ task } ]\x1b[0m` , message ) ;
272+ console . error ( `npm-scripts.mjs \x1b[31m[ERROR] [${ task } ]\x1b[0m` , ... args ) ;
261273}
262274
263275function exitWithError ( ) {
0 commit comments