Skip to content

Commit

Permalink
feat(npm-script): add purge script for tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjulian committed Oct 23, 2020
1 parent da9c2d6 commit f13c66a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion angular-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"e2e": "ng e2e",
"build:prod": "NODE_ENV=production ng build --prod"
},
"private": true,
"dependencies": {
Expand Down
28 changes: 24 additions & 4 deletions src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
NodeDependencyType,
} from '@schematics/angular/utility/dependencies';
import {
getWorkspace as getWorkspaceConfig,
getWorkspace,
updateWorkspace,
} from '@schematics/angular/utility/config';
import { InsertChange } from '@schematics/angular/utility/change';
Expand All @@ -35,7 +35,7 @@ const NGX_BUILD_PLUS_KARMA_BUILDER_TARGET = 'ngx-build-plus:karma';

export function ngAdd(_options: Schema): Rule {
return async (host: Tree) => {
const workspace = getWorkspaceConfig(host);
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, _options.project);

const projectName = _options.project || Object.keys(workspace.projects)[0];
Expand Down Expand Up @@ -64,6 +64,7 @@ export function ngAdd(_options: Schema): Rule {

return chain([
addDependencies(_options),
addNpmScripts(_options),
updateStyles(_options),
addWebpackConfig(_options),
updateAngularJSON(_options),
Expand All @@ -72,6 +73,7 @@ export function ngAdd(_options: Schema): Rule {
]);
};
}

function addDependencies(_options: Schema): Rule {
return (host: Tree) => {
addPackageJsonDependency(host, {
Expand Down Expand Up @@ -110,7 +112,7 @@ function addDependencies(_options: Schema): Rule {

function updateStyles(options: Schema): Rule {
return (tree: Tree, context: SchematicContext) => {
const workspace = getWorkspaceConfig(tree);
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace, options.project);
const stylePath = getProjectStyleFile(project, options.cssFormat);

Expand Down Expand Up @@ -158,7 +160,7 @@ function addWebpackConfig(options: Schema): Rule {

function updateAngularJSON(options: Schema): Rule {
return (tree: Tree, context: SchematicContext) => {
const workspace = getWorkspaceConfig(tree);
const workspace = getWorkspace(tree);
const project = getProjectFromWorkspace(workspace, options.project);

const browserTargets = getTargetsByBuilderName(project, Builders.Browser);
Expand Down Expand Up @@ -195,6 +197,24 @@ function updateAngularJSON(options: Schema): Rule {
};
}

function addNpmScripts(_options: Schema): Rule {
return (tree: Tree) => {
const pkgPath = 'package.json';
const buffer = tree.read(pkgPath);

if (buffer === null) {
throw new SchematicsException('Could not find package.json');
}

const pkg = JSON.parse(buffer.toString());

pkg.scripts['build:prod'] = 'NODE_ENV=production ng build --prod';

tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
return tree;
};
}

function install(): Rule {
return async (_host: Tree, context: SchematicContext) => {
// Install the dependency
Expand Down

0 comments on commit f13c66a

Please sign in to comment.