Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Sep 1, 2017
0 parents commit 7ac762c
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.idea
dist
build
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "AngularExt",
"version": "0.0.1n",
"description": "",
"main": "index.js",
"scripts": {
"build": "./scripts/build.sh"
},
"devDependencies": {
"typescript": "2.4.2",
"@types/node": "8.0.7",
"@types/jasmine": "2.5.53",

"@angular-devkit/core": "0.0.9",
"@angular-devkit/schematics": "0.0.9"
},
"author": "Victor Savkin",
"license": "MIT"
}
6 changes: 6 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

rm -rf build
rm -rf tmp
tsc
rsync -a --exclude=*.ts src/ build/
Empty file added src/index.ts
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface SomeAction {
type: 'SOME_ACTION';
payload: {};
}

export type <%= className %>Action = SomeAction;

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {TalksAndFiltersEffects} from './talks-and-filters.effects';
import {readAll} from '@nrwl/ext';
import {of} from 'rxjs/observable/of';
import {hot} from 'jasmine-marbles';

describe('<%= className %>Effects', () => {
describe('someEffect', () => {
it('should work', async () => {
const actions = new Actions(hot('-a-|', {a: {type: 'SOME_ACTION'}}));
const effects = new <%= className %>Effects();

expect(await readAll(effects.navigateToTalk)).toEqual([
{type: 'OTHER_ACTION'}
]);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Injectable} from '@angular/core';
import {Effect, Actions} from '@ngrx/effects';
import {of} from 'rxjs/observable/of';

@Injectable()
export class <%= className %>Effects {
@Effect() someEffect = this.actions.ofType('SOME_ACTION').switchMap((a) => {
// process the action
return of({type: 'OTHER_ACTION'});
});

constructor(private actions: Actions) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {<%= className %>} from './<%= fileName %>.interfaces';

export const <%= propertyName %>InitialState: <%= className %> = {
// fill it initial state here
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface <%= className %> {
// define state here
}

export interface <%= className %>State {
readonly <%= propertyName %>: <%= className %>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { <%= propertyName %>Reducer } from './<%= fileName %>.reducer';
import { <%= propertyName %>InitialState } from './<%= fileName %>.init';
import { <%= className %> } from './<%= fileName %>.interfaces';
import { SomeAction } from './<%= fileName %>.actions';

describe('<%= propertyName %>Reducer', () => {
it('should work', () => {
const state: <%= className %> = {};
const action: SomeAction = {type: 'SOME_ACTION', payload: {}};
const actual = <%= propertyName %>Reducer(state, action);
expect(actual).toEqual({});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {<%= className %>} from './<%= fileName %>.interfaces';
import {<%= className %>Action} from './<%= fileName %>.actions';

export function <%= propertyName %>Reducer(state: <%= className %>, action: <%= className %>Action): <%= className %> {
switch (action.type) {
case 'SOME_ACTION': {
return {...state, ...action.payload};
}
default: {
return state;
}
}
}
14 changes: 14 additions & 0 deletions src/schematics/addNgRxToModule/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {apply, branchAndMerge, chain, mergeWith, Rule, template, Tree, url} from '@angular-devkit/schematics';
import { names } from "../name-utils";

export default function (options: any): Rule {
const templateSource = apply(url('./files'), [
template({...options, tmpl: '', ...names(options.name)})
]);

return chain([
branchAndMerge(chain([
mergeWith(templateSource)
])),
]);
}
14 changes: 14 additions & 0 deletions src/schematics/addNgRxToModule/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/schema",
"id": "NewLib",
"title": "Add NgRx support to a module",
"type": "object",
"properties": {
"path": {
"type": "string"
}
},
"required": [
"path"
]
}
11 changes: 11 additions & 0 deletions src/schematics/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "nrwl",
"version": "0.1",
"schematics": {
"addNgRxToModule": {
"factory": "./addNgRxToModule",
"schema": "./addNgRxToModule/schema.json",
"description": "Add NgRx support to a module."
}
}
}
26 changes: 26 additions & 0 deletions src/schematics/name-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function names(name: string): any {
return {
name,
className: toClassName(name),
propertyName: toPropertyName(name),
fileName: toFileName(name)
};
}

function toClassName(str: string): string {
return toCapitalCase(toPropertyName(str));
}

function toPropertyName(s: string): string {
return s
.replace(/(-|_|\.|\s)+(.)?/g, (_, __, chr) => chr ? chr.toUpperCase() : '')
.replace(/^([A-Z])/, m => m.toLowerCase());
}

function toFileName(s: string): string {
return s.replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase().replace(/[ _]/g, '-');
}

function toCapitalCase(s: string): string {
return s.charAt(0).toUpperCase() + s.substr(1);
}
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "build",
"typeRoots": ["node_modules/@types"],
"skipLibCheck": true,
"lib": [
"es2015"
]
},
"exclude": [
"tmp",
"node_modules"
]
}
50 changes: 50 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@angular-devkit/[email protected]":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-0.0.6.tgz#caf25c0c7928196e244b5fe5124256fcef6bce7c"

"@angular-devkit/[email protected]":
version "0.0.9"
resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-0.0.9.tgz#d4620b4355e73f1ccbd1fe8334848d596a80e272"

"@angular-devkit/[email protected]":
version "0.0.9"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-0.0.9.tgz#84668c0196648de7e88e1727b2e7defbd7962dfd"
dependencies:
"@angular-devkit/core" "0.0.6"
"@ngtools/json-schema" "^1.1.0"
minimist "^1.2.0"
rxjs "^5.4.2"

"@ngtools/json-schema@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@ngtools/json-schema/-/json-schema-1.1.0.tgz#c3a0c544d62392acc2813a42c8a0dc6f58f86922"

"@types/[email protected]":
version "2.5.53"
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.5.53.tgz#4e0cefad09df5ec48c8dd40433512f84b1568d61"

"@types/[email protected]":
version "8.0.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.7.tgz#fb0ad04b5b6f6eabe0372a32a8f1fbba5c130cae"

minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

rxjs@^5.4.2:
version "5.4.2"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.4.2.tgz#2a3236fcbf03df57bae06fd6972fd99e5c08fcf7"
dependencies:
symbol-observable "^1.0.1"

symbol-observable@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"

[email protected]:
version "2.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844"

0 comments on commit 7ac762c

Please sign in to comment.