@leverege/build-tools 2.91.0 → 2.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/prepack.mjs +16 -3
- package/src/refresh-npm-token.mjs +25 -0
package/package.json
CHANGED
package/src/prepack.mjs
CHANGED
|
@@ -8,13 +8,14 @@ import { $, fs, minimist, chalk } from 'zx'
|
|
|
8
8
|
|
|
9
9
|
process.env.FORCE_COLOR = '1'
|
|
10
10
|
|
|
11
|
-
const { compile, 'manual-tag' : manualTag, 'force-tag' : forceTag } = minimist( process.argv.slice( 2 ), {
|
|
11
|
+
const { compile, 'manual-tag' : manualTag, 'force-tag' : forceTag, 'push-tag' : pushTag } = minimist( process.argv.slice( 2 ), {
|
|
12
12
|
default : {
|
|
13
13
|
compile : true,
|
|
14
14
|
'force-tag' : false,
|
|
15
|
-
'manual-tag' : false
|
|
15
|
+
'manual-tag' : false,
|
|
16
|
+
'push-tag' : true
|
|
16
17
|
},
|
|
17
|
-
boolean : [ 'compile', 'manual-tag', '
|
|
18
|
+
boolean : [ 'compile', 'manual-tag', 'force-tag', 'push-tag' ]
|
|
18
19
|
} )
|
|
19
20
|
|
|
20
21
|
try {
|
|
@@ -60,6 +61,18 @@ if ( !isPrerelease || forceTag ) {
|
|
|
60
61
|
process.stderr.write( error.text() )
|
|
61
62
|
process.exit( error.exitCode )
|
|
62
63
|
}
|
|
64
|
+
|
|
65
|
+
if ( pushTag ) {
|
|
66
|
+
try {
|
|
67
|
+
await $( {
|
|
68
|
+
quiet : true
|
|
69
|
+
} )`git push --tags`
|
|
70
|
+
} catch ( error ) {
|
|
71
|
+
process.stderr.write( chalk.redBright( 'Failed to push git tag with error:\n' ) )
|
|
72
|
+
process.stderr.write( error.text() )
|
|
73
|
+
process.exit( error.exitCode )
|
|
74
|
+
}
|
|
75
|
+
}
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
function compileCmd( { isYarn } ) {
|
|
@@ -25,9 +25,13 @@ import commandLineArgs from 'command-line-args'
|
|
|
25
25
|
import commandLineUsage from 'command-line-usage'
|
|
26
26
|
import ms from 'ms'
|
|
27
27
|
import { lt as semverLt } from 'semver'
|
|
28
|
+
import YAML from 'js-yaml'
|
|
28
29
|
|
|
29
30
|
import { debug, log, shellCmd } from './Utils.mjs'
|
|
30
31
|
|
|
32
|
+
const AUTH_TOKEN_REGEX = /_authToken=(.+)/
|
|
33
|
+
const YARNRC_FILE_NAME = `${os.homedir()}/.yarnrc.yml`
|
|
34
|
+
|
|
31
35
|
const refreshTokenOptions = [ // Use refreshTokenOptions to tie into the Usage statements
|
|
32
36
|
{
|
|
33
37
|
name : 'project',
|
|
@@ -59,6 +63,12 @@ const refreshTokenOptions = [ // Use refreshTokenOptions to tie into the Usage s
|
|
|
59
63
|
default : false,
|
|
60
64
|
description : '{green display this help screen}',
|
|
61
65
|
},
|
|
66
|
+
{
|
|
67
|
+
name : 'update-yarnrc',
|
|
68
|
+
type : Boolean,
|
|
69
|
+
defaultValue : true,
|
|
70
|
+
description : '{green updates the npmAuthToken variable of your .yarnrc.yml file (in addition to .npmrc/.npmrc.ro)}'
|
|
71
|
+
}
|
|
62
72
|
]
|
|
63
73
|
|
|
64
74
|
const sections = [
|
|
@@ -195,11 +205,14 @@ const getGcpSecretCommand = ( secretName ) => {
|
|
|
195
205
|
|
|
196
206
|
// fetch the contents of the npmrc secret file stored on the specified project
|
|
197
207
|
let npmrcFile
|
|
208
|
+
let npmAuthToken
|
|
198
209
|
try {
|
|
199
210
|
const npmTokenFetcher = getGcpSecretCommand( 'REFRESH_NPM_NPMRC' )
|
|
200
211
|
debug( { npmTokenFetcher }, '<==Secret Fetcher' )
|
|
201
212
|
|
|
202
213
|
npmrcFile = await shellCmd( npmTokenFetcher )
|
|
214
|
+
npmAuthToken = npmrcFile.match( AUTH_TOKEN_REGEX )?.[1]
|
|
215
|
+
debug( { npmAuthToken }, '<==npmAuthToken' )
|
|
203
216
|
debug( { npmrcFile }, '<==shellCmd Output npmrc file' )// debug
|
|
204
217
|
} catch ( err ) {
|
|
205
218
|
log( chalk.yellow( `\nFailed Command => [${err.escapedCommand}]\n\n` ), chalk.red( err.stderr ) )
|
|
@@ -234,6 +247,18 @@ try {
|
|
|
234
247
|
fs.copyFileSync( filename, `${filename}-BAK` ) // make a backup for safety
|
|
235
248
|
}
|
|
236
249
|
fs.writeFileSync( filename, npmrcFile )
|
|
250
|
+
|
|
251
|
+
if ( args.updateYarnrc && npmAuthToken ) {
|
|
252
|
+
let yarnRcContent = { nodeLinker : 'node-modules' }
|
|
253
|
+
if ( fs.existsSync( YARNRC_FILE_NAME ) ) {
|
|
254
|
+
fs.copyFileSync( YARNRC_FILE_NAME, `${YARNRC_FILE_NAME}-BAK` )
|
|
255
|
+
yarnRcContent = YAML.load( fs.readFileSync( YARNRC_FILE_NAME, 'utf-8' ) )
|
|
256
|
+
debug( { yarnRcContent }, '<==yarnrc content' )
|
|
257
|
+
yarnRcContent.npmAuthToken = npmAuthToken
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
fs.writeFileSync( YARNRC_FILE_NAME, YAML.dump( yarnRcContent ) )
|
|
261
|
+
}
|
|
237
262
|
}
|
|
238
263
|
} catch ( fileErr ) {
|
|
239
264
|
log( fileErr, 'fs failed' )
|