Skip to content

Commit

Permalink
feat: added generate schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminDobler committed May 21, 2019
1 parent bab90b1 commit 6b7d960
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 8 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# NgNode

# ngnode
Angular + Node = :heart:


### Create new node project

```bash
ng generate --schematic=@richapps/ngnode:application <project-name>
```

### Build and run node app

```bash
ng run <project-name>:build-node
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@richapps/ngnode",
"version": "0.0.0",
"version": "0.0.1",
"description": "devkit for building node apps with the angular cli",
"author": {
"name": "Benjamin Dobler",
Expand Down
Empty file.
1 change: 1 addition & 0 deletions schematics/application/files/src/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schematics/application/files/src/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
39 changes: 37 additions & 2 deletions schematics/application/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schematics/application/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 59 additions & 3 deletions schematics/application/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import {chain, Rule, SchematicContext, SchematicsException, Tree} from "@angular-devkit/schematics";
import {
apply,
chain,
mergeWith, move,
Rule,
SchematicContext,
SchematicsException,
template,
Tree, url
} from "@angular-devkit/schematics";
import {validateProjectName} from "@schematics/angular/utility/validation";
import {getWorkspace} from "@schematics/angular/utility/workspace";
import {getWorkspace as getWorkspace2} from "@schematics/angular/utility/config";

import {join, normalize} from "@angular-devkit/core";
import {updateWorkspace} from "@schematics/angular/utility/config";
import {ProjectType} from "@schematics/angular/utility/workspace-models";


export default function (options: any): Rule {
Expand All @@ -14,17 +27,60 @@ export default function (options: any): Rule {
options.prefix = options.prefix || 'app';

const workspace = await getWorkspace(host);

const newProjectRoot = workspace.extensions.newProjectRoot as (string | undefined) || '';
const isRootApp = options.projectRoot !== undefined;
const appDir = isRootApp
? options.projectRoot as string
: join(normalize(newProjectRoot), options.name);
const sourceDir = `${appDir}/src/app`
const sourceDir = `${appDir}/src`
options.appProjectRoot = sourceDir;


console.log("Add Node app! ", sourceDir);

return chain([]);
return chain([updateAngularConfig(options), addFiles(options)]);

}
}

function updateAngularConfig(options): Rule {
return async (tree: Tree, _context: SchematicContext) => {
const workspace = getWorkspace2(tree);

const project = workspace.projects[options.name] = {


projectType: ProjectType.Application,
root: "projects/node1",
sourceRoot: options.appProjectRoot,
prefix: "app",
architect: {
['build-node']: {
builder: "@richapps/ngnode:build",
options: {
outputPath: "dist/" + options.name,
main: "main.ts"
}
}
}
}
return updateWorkspace(workspace);
}
}


function addFiles(options) {
return mergeWith(
apply(url(`./files/src`), [
template({
tmpl: '',
name: options.name,
root: options.appProjectRoot
}),
move(options.appProjectRoot)
]));
}



0 comments on commit 6b7d960

Please sign in to comment.