From 2be0001e0737509aa57c41510de4fc972b8209c2 Mon Sep 17 00:00:00 2001 From: Francisco Cruz Date: Fri, 8 Jan 2021 22:03:19 +0000 Subject: [PATCH] feat(cross-env): add cross-env to build:prod script --- README.md | 9 +++++++++ src/ng-add/index.ts | 14 +++++++++++++- src/ng-add/schema.json | 10 ++++++++++ src/ng-add/schema.ts | 10 ++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fdee075..5f79b48 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ All available flags: |  `postcssScssVersion` | The postcss-scss version to be installed. | `string` | `^3.0.4` | |  `skipTailwindInit` | Skip initializing Tailwind. | `boolean` | `false` | |  `tailwindVersion` | The Tailwind version to be installed. | `string` | `^2.0.1` | +|  `installCrossPlatform` | Set the build:prod script to be cross-platform. | `boolean` | `true` | +|  `crossEnvVersion` | The cross-env version to be installed. | `string` | `^7.0.3` | Advanced usage @@ -80,6 +82,13 @@ Want to integrate Tailwind CSS in version 1.x.x? No problem: ng add ngx-tailwind --tailwindVersion 1.9.6 --ngxBuildPlusVersion 10.1.1 --postcssVersion 7.0.35 --postcssImportVersion 12.0.1 --postcssLoaderVersion 4.0.4 --postcssScssVersion 3.0.4 ``` +By default, `cross-env` is added to the `build:prod` script to be able to set `NODE_ENV=prod` cross-platform. +If you want to override the default behavior, you can set the flag `--installCrossPlatform` to `false`: + +```bash +ng add ngx-tailwind --installCrossPlatform false +``` + ## Developing Install `@angular-devkit/schematics-cli` to be able to use `schematics` command diff --git a/src/ng-add/index.ts b/src/ng-add/index.ts index 5a64d2e..6d1a3d1 100755 --- a/src/ng-add/index.ts +++ b/src/ng-add/index.ts @@ -107,6 +107,14 @@ function addDependencies(_options: Schema): Rule { name: 'ngx-build-plus', version: _options.ngxBuildPlusVersion, }); + + if (_options.installCrossPlatform) { + addPackageJsonDependency(host, { + type: NodeDependencyType.Dev, + name: 'cross-env', + version: _options.crossEnvVersion, + }); + } }; } @@ -203,7 +211,11 @@ function addNpmScripts(_options: Schema): Rule { const pkg = JSON.parse(buffer.toString()); - pkg.scripts['build:prod'] = 'NODE_ENV=production ng build --prod'; + if (_options.installCrossPlatform) { + pkg.scripts['build:prod'] = 'cross-env NODE_ENV=production ng build --prod'; + } else { + pkg.scripts['build:prod'] = 'NODE_ENV=production ng build --prod'; + } tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2)); return tree; diff --git a/src/ng-add/schema.json b/src/ng-add/schema.json index 660cbe1..0aee07b 100755 --- a/src/ng-add/schema.json +++ b/src/ng-add/schema.json @@ -71,6 +71,16 @@ "type": "string", "description": "The Tailwind version to be installed.", "default": "^2.0.1" + }, + "crossEnvVersion": { + "type": "string", + "description": "The cross-env version to be installed.", + "default": "^7.0.3" + }, + "installCrossPlatform": { + "type": "boolean", + "description": "Set the build:prod script to be cross-platform.", + "default": true } } } diff --git a/src/ng-add/schema.ts b/src/ng-add/schema.ts index e679843..bd09608 100644 --- a/src/ng-add/schema.ts +++ b/src/ng-add/schema.ts @@ -48,6 +48,16 @@ export interface Schema { * Tailwind CSS version. */ tailwindVersion: string; + + /** + * Set the build:prod script to be cross-platform. + */ + installCrossPlatform: boolean; + + /** + * cross-env version. + */ + crossEnvVersion: string; } export type CssFormat = 'css' | 'scss';