Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
fix(generators): Add support custom username and email options
Browse files Browse the repository at this point in the history
  • Loading branch information
EndyKaufman committed Jul 16, 2018
1 parent 6a81ef8 commit 69fa21f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"build:tsc": "tsc -p tsconfig.json",
"build": "run-s build:tsc",
"test": "npm run build && jasmine src/**/*_spec.js",
"run-entity": "npm run build && schematics .:entity --name=test-entity --root=fixtures/entity --dry-run=false --force",
"run-new": "npm run build && schematics .:new --name=demo --root=fixtures/new --dry-run=false --force"
"run-entity": "npm run build && schematics .:entity --name=test-entity --root=fixtures/entity --username=demo --email=demo@demo.demo --dry-run=false --force",
"run-new": "npm run build && schematics .:new --name=demo --root=fixtures/new --username=demo --email=demo@demo.demo --dry-run=false --force",
"manual-test": "npm run run-entity && npm run run-new && npm run test"
},
"keywords": [
"schematics",
Expand Down Expand Up @@ -68,4 +69,4 @@
"typescript"
]
}
}
}
10 changes: 8 additions & 2 deletions src/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { humanize, pluralize, underscore } from 'inflection';
import { join, resolve } from 'path';

const dot = require('dot-object');
const gitEmail = require('git-user-email');
const gitUsername = require('git-username');

// Instead of `any`, it would make sense here to get a schema-to-dts package and output the
// interfaces so you get type-safe options.
export default function (options: any): Rule {
const root = options.root;
const name = options.name;
const fields = options.fields;
const gitInfo = { username: options.username || gitUsername(), email: options.email || gitEmail() };
const chains = [];
let app = options.app;
let core = options.core;
Expand All @@ -26,7 +29,7 @@ export default function (options: any): Rule {
} catch (e) {
angularConfigPath = resolve(__dirname, 'files', 'project', 'angular.json');
chains.push(
schematic('new', { root: root, name: 'demo' })
schematic('new', { root: root, name: 'demo', username: gitInfo.username, email: gitInfo.email })
)
}
try {
Expand Down Expand Up @@ -75,6 +78,8 @@ export default function (options: any): Rule {
name: name,
fields: fields,
root: root,
gitInfo: gitInfo,
...dot.dot({ gitInfo: gitInfo }),
app: appConfig,
core: coreConfig,
web: webConfig,
Expand Down Expand Up @@ -115,8 +120,8 @@ export default function (options: any): Rule {
} catch (error) {
existsFrames = [
'content-types',
'permissions',
'groups',
'permissions',
'users'
];
}
Expand All @@ -125,6 +130,7 @@ export default function (options: any): Rule {
data.pluralize(name)
);
}
existsFrames = existsFrames.sort();
try {
accessSync(entityPageModuleFile, constants.F_OK);
const templatePageSource = apply(url('./files/page-only-routes'), [
Expand Down
8 changes: 8 additions & 0 deletions src/entity/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"type": "string",
"description": "Entity singular name on ke-bab case"
},
"username": {
"type": "string",
"description": "Username"
},
"email": {
"type": "string",
"description": "Email"
},
"root": {
"type": "string",
"description": "Root folder",
Expand Down
2 changes: 1 addition & 1 deletion src/new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const gitUsername = require('git-username');
export default function (options: any): Rule {
const root = options.root;
const name = options.name;
const gitInfo = { username: gitUsername(), email: gitEmail() };
const gitInfo = { username: options.username || gitUsername(), email: options.email || gitEmail() };
const templateSource = apply(url('./files'), [
template({
...strings,
Expand Down
8 changes: 8 additions & 0 deletions src/new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"type": "string",
"description": "Application name on ke-bab case"
},
"username": {
"type": "string",
"description": "Username"
},
"email": {
"type": "string",
"description": "Email"
},
"root": {
"type": "string",
"description": "Root folder",
Expand Down

0 comments on commit 69fa21f

Please sign in to comment.