Convert .angular-cli.json to angular.json (for Angular 10/9/8/7/6 Migration from Angular 2/4/5)

Convert .angular-cli.json to angular.json (for Angular 10/9/8/7/6 Migration from Angular 2/4/5)

In this post we will give you information about Convert .angular-cli.json to angular.json (for Angular 10/9/8/7/6 Migration from Angular 2/4/5). Hear we will give you detail about Convert .angular-cli.json to angular.json (for Angular 10/9/8/7/6 Migration from Angular 2/4/5)And how to use it also give you demo for it if it is necessary.

In this quick example, we’ll see a script that can help you to convert .angular-cli.json to angular.json for migrating your app to Angular 10/…/6 from Angular 2/4/5.

This script is created by leo6104. You can use this Node script inside your Angular v5/4/2 project.

Create a ng-update-v6.js file inside the Angular project’s folder and add the following code:

constfs=require('fs');constpath=require('path');constargv=process.argv;constlegacyJSONPath=argv[2];constlegacyJSON=JSON.parse(fs.readFileSync(legacyJSONPath).toString());constnewJSON={"$schema":"./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json","version":1,"newProjectRoot":"src","projects":{}};legacyJSON.apps.forEach(app=>{constplatformType=app.platform||'browser';constrootPath=app.root;constenvironmentSource=path.relative(path.join(__dirname),path.join(__dirname,app.root,app.environmentSource));/**   * Configuration   **/constconfigurations={};if(platformType==='browser'){Object.keys(app.environments).forEach(env=>{if(env==='dev')return;configurations[(env==='prod'?'production':env)]={"fileReplacements":[{"src":environmentSource,"replaceWith":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.environments[env]))}],"optimization":true,"outputHashing":"all","sourceMap":false,"extractCss":true,"namedChunks":false,"aot":true,"extractLicenses":true,"vendorChunk":false,"buildOptimizer":true}});}else{Object.keys(app.environments).forEach(env=>{if(env==='dev')return;configurations[(env==='prod'?'production':env)]={"environment":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.environments[env]))}});}/**   * Options   **/constoptions={"outputPath":app.outDir,"main":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.main)),"tsConfig":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.tsconfig)),};options.serviceWorker=!!app.serviceWorker;if(app.stylePreprocessorOptions){options.stylePreprocessorOptions=app.stylePreprocessorOptions;options.stylePreprocessorOptions.includePaths=options.stylePreprocessorOptions.includePaths.map(stylePath=>{returnpath.relative(path.join(__dirname),path.join(__dirname,app.root,stylePath));});}if(platformType==='browser'){options['index']=path.relative(path.join(__dirname),path.join(__dirname,app.root,app.index));options['assets']=[];options['styles']=[];options['scripts']=[];app.assets.forEach(asset=>{if(typeofasset==='string'){constfilename=path.basename(asset);constfilePath=path.join(app.root,asset);conststats=fs.lstatSync(filePath);if(stats.isDirectory()){options.assets.push({glob:'**/*',input:filePath,output:filename});}else{letinputPath=filePath.split('/');inputPath.pop();inputPath=inputPath.join('/');options.assets.push({glob:filename,input:inputPath,output:filename});}}else{options.assets.push(Object.assign({},asset,{input:path.relative(path.join(__dirname),path.join(__dirname,app.root,asset.input))}));}});app.styles.forEach(style=>{if(typeofstyle==='string'){constfilePath=path.relative(path.join(__dirname),path.join(__dirname,app.root,style));options.styles.push(filePath);}else{options.styles.push(Object.assign({},asset,{input:path.relative(path.join(__dirname),path.join(__dirname,app.root,style.input))}));}});app.scripts.forEach(script=>{if(typeofscript==='string'){constfilePath=path.relative(path.join(__dirname),path.join(__dirname,app.root,script));options.scripts.push(filePath);}else{options.scripts.push(Object.assign({},asset,{input:path.relative(path.join(__dirname),path.join(__dirname,app.root,script.input))}));}});}if(app.polyfills){// polyfills dose not exists on Server cli settingoptions['polyfills']=path.relative(path.join(__dirname),path.join(__dirname,app.root,app.polyfills));}newJSON.projects[app.name]={"root":app.root,"projectType":"application","architect":{"build":{"builder":"@angular-devkit/build-angular:"+platformType,"options":options,"configurations":configurations}}};if(platformType==='browser'){if(app.testTsconfig){consttestOptions={"main":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.test)),"polyfills":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.polyfills)),"tsConfig":path.relative(path.join(__dirname),path.join(__dirname,app.root,app.testTsconfig)),"karmaConfig":rootPath+"/karma.conf.js","styles":[],"scripts":[],"assets":[]};if(app.polyfills){// polyfills dose not exists on Server cli settingtestOptions['polyfills']=path.relative(path.join(__dirname),path.join(__dirname,app.root,app.polyfills));}testOptions['tsConfig']=path.relative(path.join(__dirname),path.join(__dirname,app.root,app.testTsconfig));Object.assign(newJSON.projects[app.name].architect,{"test":{"builder":"@angular-devkit/build-angular:karma","options":testOptions}});}Object.assign(newJSON.projects[app.name].architect,{"serve":{"builder":"@angular-devkit/build-angular:dev-server","options":{"browserTarget":app.name+":build"},"configurations":{"production":{"browserTarget":app.name+":build:production"}}},"extract-i18n":{"builder":"@angular-devkit/build-angular:extract-i18n","options":{"browserTarget":app.name+":build"}},"lint":{"builder":"@angular-devkit/build-angular:tslint","options":{"tsConfig":[path.relative(path.join(__dirname),path.join(__dirname,app.root,app.tsconfig))],"exclude":["**/node_modules/**"]}}});}});fs.writeFileSync("angular.json",JSON.stringify(newJSON));console.log(newJSON);

Next, run the following command

$ node ng-update-v6.js .angular-cli.json

A file named angular.json will be created in your project.

Check this gist


Hope this code and post will helped you for implement Convert .angular-cli.json to angular.json (for Angular 10/9/8/7/6 Migration from Angular 2/4/5). if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US