Skip to content

Commit

Permalink
feat(schematic): run against sandbox (#27)
Browse files Browse the repository at this point in the history
feat(schematic): run against sandbox-app

WIP that gets the schematic running against the host app (sandbox-app)
run `yarn clean:launch:all` 
expect new state and entity code in `sandbox-app/src/app/state/`
clean up with `yarn clean`
  • Loading branch information
schuchard committed Aug 3, 2018
1 parent b0eecb9 commit 1b0cfd3
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 1,229 deletions.
44 changes: 39 additions & 5 deletions README.md
Expand Up @@ -4,12 +4,32 @@

## Development

### Copy src project to schematic template files
### Link the schematic to the `sandbox-app`

Read the template app, `/schematic-src`, and copy all the necessary files into the schematic folder, `/src`. During the copy, replace all "entity" placeholders with their respective template placeholder.
```shell
yarn link:schematic
```

### Run schematic locally

Compile the schematic code

```shell
yarn build:schematic
```

Reset the `sandbox-app` to it's version controlled state, then execute the schematic locally against the `sandbox-app`.

```shell
yarn clean:launch
```

### Copy `schematic-src` files into schematic template files

Read the blueprint app, `/schematic-src`, and copy all the necessary files into the schematic folder, `/src/__files__`. During the copy, replace all "entity" placeholders with their respective template placeholder. Run this if changes to the `schematic-src` app have been made.

```shell
build:files
yarn build:run:fileBuilder
```

#### Entity string mapping
Expand All @@ -30,13 +50,27 @@ When editing the script that copies and modifies the blueprint files into the sc
Compile the `buildFiles` script into `/tmp` in one shell

```shell
build:ts
build:fileBuilder
```

In another shell, run the script and watch the `/tmp` dir for changes. Allows for attaching a debugger on port `9222`. See the attached `.vscode/launch.json` file for debugging with VSCode.

```shell
build:run
run:fileBuilder
```

Once both of these are run, changes to `./buildFiles.ts` should recompile and trigger an update to nodemon. Then trigger the VSCode debugger `f5` and that will land a breakpoint on line:1 of the app. Step over that to get to your breakpoint.

## Architecture

### ./src

This is the schematic code that's executed when running `ng g @briebug/ngrx-entity-schematic`.

### ./schematic-src

This the blueprint used for generating the schematic, specifically in template files in `./src/ngrx-entity/__files__`. This is a working application that defines the final form of the schematic.

### ./sandbox-app

This is an application that's used for testing the schematic locally for development.
13 changes: 7 additions & 6 deletions buildFiles.ts
Expand Up @@ -11,11 +11,12 @@ import * as klawSync from 'klaw-sync';
const LocalRootFolder = 'src/ngrx-entity/__files__';
const RootPath = `${process.cwd()}/${LocalRootFolder}`;
const names = {
file: `__name@dasherize`,
folder: `__name@dasherize`,
file: `__name@dasherize__`,
class: `<%= classify(name) %>`,
name: `<%= name %>`,
};
const newEntityFolder = `${RootPath}/${names.file}@if-flat__`;
const newEntityFolder = `${RootPath}/${names.folder}@if-flat__`;

interface SourceNodes {
fullPath: string;
Expand Down Expand Up @@ -68,7 +69,7 @@ interface SourceNodes {
// create __files__/${EntityName} folder
ensureDirSync(newEntityFolder);

renameEntityFiles(node, names.file);
renameEntityFiles(node, names);
}
});

Expand All @@ -89,11 +90,11 @@ function replaceEntityWithTemplateVariable(node: SourceNodes, file: string) {
return writeFileSync(`${RootPath}/${node.relativePath}`, newFile);
}

function renameEntityFiles(node: SourceNodes, name: string) {
function renameEntityFiles(node: SourceNodes, name: any) {
if (node.renameValue) {
const newName = node.relativePath
.replace(new RegExp(`${node.renameValue}`, 'i'), `${name}@if-flat__`)
.replace(new RegExp(`${node.renameValue}`, 'i'), name);
.replace(new RegExp(`${node.renameValue}`, 'i'), `${name.folder}@if-flat__`)
.replace(new RegExp(`${node.renameValue}`, 'i'), name.file);

return renameSync(`${RootPath}${node.relativePath}`, `${RootPath}${newName}`);
}
Expand Down
22 changes: 16 additions & 6 deletions package.json
@@ -1,11 +1,21 @@
{
"name": "ngrx-entity-generator",
"version": "0.0.0",
"name": "@briebug/ngrx-entity-schematic",
"version": "1.0.0",
"main": "src/ngrx-entity/index.js",
"schematics": "./src/collection.json",
"scripts": {
"build:ts": "node_modules/typescript/bin/tsc -w -p tsconfig.file-build.json",
"build:run": "nodemon --inspect-brk --watch tmp tmp/index.js",
"build:files": "node_modules/typescript/bin/tsc -p tsconfig.file-build.json && node ./tmp/buildFiles.js",
"clean": "git checkout -- sandbox-app && git clean -fd sandbox-app"
"build:fileBuilder": "node_modules/typescript/bin/tsc -w -p tsconfig.file-build.json",
"watch:fileBuilder": "nodemon --inspect-brk --watch tmp ./tmp/buildFiles.js",
"build:run:fileBuilder": "node_modules/typescript/bin/tsc -p tsconfig.file-build.json && node ./tmp/buildFiles.js",
"build:schematic": "tsc -p tsconfig.schematic.json",
"build:schematic:watch": "tsc -p tsconfig.schematic.json -watch",
"clean": "git checkout HEAD -- sandbox-app && git clean -fd sandbox-app",
"clean:launch": "npm run clean && npm run launch",
"clean:launch:all": "yarn build:run:fileBuilder && yarn build:schematic && yarn clean:launch",
"launch": "cd sandbox-app && ng g @briebug/ngrx-entity-schematic:ngrx-entity-schematic",
"test:ci": "npm run clean:launch && npm run test:sandbox && npm run clean",
"test:sandbox": "cd sandbox-app && npm run lint && npm run test && npm run e2e && npm run build",
"link:schematic": "yarn link && cd sandbox-app && yarn link @briebug/ngrx-entity-schematic"
},
"dependencies": {
"@angular-devkit/core": "^0.6.8",
Expand Down
10 changes: 0 additions & 10 deletions sandbox-app/src/app/state/app.interfaces.ts

This file was deleted.

17 changes: 0 additions & 17 deletions sandbox-app/src/app/state/app.reducer.ts

This file was deleted.

146 changes: 0 additions & 146 deletions sandbox-app/src/app/state/briebug/briebug.actions.ts

This file was deleted.

0 comments on commit 1b0cfd3

Please sign in to comment.