Skip to content

Commit

Permalink
feat(schematics): do not set boot page when the target file is modifi…
Browse files Browse the repository at this point in the history
…ed (#3178)
  • Loading branch information
hsuanxyz authored and vthinkxie committed Mar 27, 2019
1 parent c685836 commit 0a3f62c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 6 additions & 7 deletions schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"default": false,
"description": "Do not add ng-zorro-antd dependencies to package.json (e.g., --skipPackageJson)"
},
"bootPage": {
"type": "boolean",
"default": true,
"description": "Set up boot page."
},
"dynamicIcon": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -124,13 +129,7 @@
"type": "boolean",
"default": true,
"description": "Whether Angular browser animations should be set up."
},
"bootPage": {
"type": "boolean",
"default": true,
"description": "Whether boot page should be set up.",
"x-prompt": "Set up the boot page"
}
},
"required": []
}
}
14 changes: 10 additions & 4 deletions schematics/ng-generate/boot-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Rule, Tree } from '@angular-devkit/schematics';
import { getProjectFromWorkspace } from '@angular/cdk/schematics';
import { getWorkspace } from '@schematics/angular/utility/config';
import chalk from 'chalk';
import { statSync as fsStatSync } from 'fs';
import { Schema } from './schema';

const bootPageHTML = `<!-- NG-ZORRO -->
<a href="https://github.com/NG-ZORRO/ng-zorro-antd" target="_blank" style="display: flex;align-items: center;justify-content: center;height: 100%;width: 100%;">
<img height="300" src="https://img.alicdn.com/tfs/TB1X.qJJgHqK1RjSZFgXXa7JXXa-89-131.svg">
</a>`;

export default function (options: Schema): Rule {
export default function(options: Schema): Rule {
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
Expand All @@ -18,11 +19,16 @@ export default function (options: Schema): Rule {

if (!buffer) {
console.log();
console.error(chalk.red(`Could not find the project ${chalk.blue(appHTMLFile)} file inside of the ` +
`workspace config`));
console.error(
chalk.red(`Could not find the project ${chalk.blue(appHTMLFile)} file inside of the ` + `workspace config`)
);
return;
}
host.overwrite(appHTMLFile, bootPageHTML);
const stat = fsStatSync(appHTMLFile);
if (stat.mtimeMs === stat.ctimeMs) {
host.overwrite(appHTMLFile, bootPageHTML);
}

return host;
};
}

0 comments on commit 0a3f62c

Please sign in to comment.