Skip to content

Commit

Permalink
feat(cross-env): add cross-env to build:prod script
Browse files Browse the repository at this point in the history
  • Loading branch information
fcruzel committed Jan 8, 2021
1 parent ddd4017 commit 2be0001
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
};
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
10 changes: 10 additions & 0 deletions src/ng-add/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 2be0001

Please sign in to comment.