@@ -122,8 +122,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
122122 }
123123 updatePackageJsonFiles ( pkgJsonFiles , upgradeable , fs ) ;
124124 createNpmrc ( rootPath , fs ) ;
125- updateGithubWorkflows ( fs ) ;
126- updateAzureWorkflows ( fs ) ;
125+ updateWorkflows ( fs ) ;
127126
128127 return true ;
129128}
@@ -213,53 +212,51 @@ function updatePackageJsonFiles(
213212 }
214213}
215214
216- function updateWorkflows (
217- fs : IFileSystem ,
218- basePath : string ,
219- workflowFiles : string [ ] ,
220- oldInstallCmd : string ,
221- newInstallCmd : string
222- ) : void {
223- for ( const fileName of workflowFiles ) {
224- const workflowPath = `${ basePath } /${ fileName } ` ;
225- if ( fs . fileExists ( workflowPath ) ) {
226- let workflow = fs . readFile ( workflowPath ) ;
227- if ( workflow ) {
228- workflow = workflow . replace ( oldInstallCmd , newInstallCmd ) ;
229- fs . writeFile ( workflowPath , workflow ) ;
230- }
231- }
232- }
233- }
215+ function updateWorkflows ( fs : IFileSystem ) : void {
216+ type WorkflowGroup = {
217+ basePath : string ;
218+ files : string [ ] ;
219+ oldCmd : string ;
220+ newCmd : string ;
221+ } ;
234222
235- function updateGithubWorkflows ( fs : IFileSystem ) : void {
236- updateWorkflows (
237- fs ,
238- ".github/workflows" ,
239- [ "node.js.yml" , "github-pages.yml" ] ,
240- "- run: npm i # replace with 'npm ci' after committing lock file from first install" ,
241- `- run: echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
223+ const workflowGroups : WorkflowGroup [ ] = [
224+ {
225+ basePath : ".github/workflows" ,
226+ files : [ "node.js.yml" , "github-pages.yml" ] ,
227+ oldCmd : "- run: npm i # replace with 'npm ci' after committing lock file from first install" ,
228+ newCmd : `- run: echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
242229 - run: echo "//packages.infragistics.com/npm/js-licensed/:_auth=\${{ secrets.NPM_AUTH_TOKEN }}" >> ~/.npmrc
243230 - run: echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
244231 - run: npm i # replace with 'npm ci' after committing lock file from first install`
245- ) ;
246- }
247-
248- function updateAzureWorkflows ( fs : IFileSystem ) : void {
249- updateWorkflows (
250- fs ,
251- ".azure/workflows" ,
252- [ "azure-pipelines.yml" ] ,
253- "- script: npm i # replace with 'npm ci' after committing lock file from first install" ,
254- `- script: |
255- echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
256- echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
257- echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
258- displayName: 'Authenticate'
259- env:
260- NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
232+ } ,
233+ {
234+ basePath : ".azure/workflows" ,
235+ files : [ "azure-pipelines.yml" ] ,
236+ oldCmd : "- script: npm i # replace with 'npm ci' after committing lock file from first install" ,
237+ newCmd : `- script: |
238+ echo "@infragistics:registry=https://packages.infragistics.com/npm/js-licensed/" >> ~/.npmrc
239+ echo "//packages.infragistics.com/npm/js-licensed/:_auth=$NPM_AUTH_TOKEN" >> ~/.npmrc
240+ echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
241+ displayName: 'Authenticate'
242+ env:
243+ NPM_AUTH_TOKEN: $(NPM_AUTH_TOKEN)
261244 - script: npm i # replace with 'npm ci' after committing lock file from first install`
262- ) ;
245+ }
246+ ] ;
247+
248+ for ( const group of workflowGroups ) {
249+ for ( const file of group . files ) {
250+ const path = `${ group . basePath } /${ file } ` ;
251+ if ( fs . fileExists ( path ) ) {
252+ let content = fs . readFile ( path ) ;
253+ if ( content ?. includes ( group . oldCmd ) ) {
254+ content = content . replace ( group . oldCmd , group . newCmd ) ;
255+ fs . writeFile ( path , content ) ;
256+ }
257+ }
258+ }
259+ }
263260}
264261
265262function createNpmrc (
0 commit comments