@leverege/build-tools 2.91.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.91.1",
3
+ "version": "2.92.0",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -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' )