Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement ng add for store and effects packages #1067

Merged
merged 16 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/dist
/modules/schematics/src/*/files/*
/modules/schematics-core/templates/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change templates to files so its consistent with schematics. If we want to change files to templates across the board, we'll do that in a separate PR.

/modules/**/schematics-core/templates/*
/tmp
package-lock.json
package.json
Expand Down
1 change: 1 addition & 0 deletions modules/effects/schematics-core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ts_library(
"**/*.ts",
],
exclude = [
"**/templates/**/*.ts",
"**/testing/**/*.ts",
"**/*spec.ts",
],
Expand Down
5 changes: 5 additions & 0 deletions modules/effects/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export const stringUtils = {
};

export { updatePackage } from './utility/update';

export { parseName } from './utility/parse-name';

export { addPackageToPackageJson } from './utility/package';

export { platformVersion } from './utility/libs-version';
1 change: 1 addition & 0 deletions modules/effects/schematics-core/utility/libs-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platformVersion = '^6.0.0';
27 changes: 27 additions & 0 deletions modules/effects/schematics-core/utility/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Tree } from '@angular-devkit/schematics';

/**
* Adds a package to the package.json
*/
export function addPackageToPackageJson(
host: Tree,
type: string,
pkg: string,
version: string
): Tree {
if (host.exists('package.json')) {
const sourceText = host.read('package.json')!.toString('utf-8');
const json = JSON.parse(sourceText);
if (!json[type]) {
json[type] = {};
}

if (!json[type][pkg]) {
json[type][pkg] = version;
}

host.overwrite('package.json', JSON.stringify(json, null, 2));
}

return host;
}
1 change: 1 addition & 0 deletions modules/entity/schematics-core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ts_library(
"**/*.ts",
],
exclude = [
"**/templates/**/*.ts",
"**/testing/**/*.ts",
"**/*spec.ts",
],
Expand Down
5 changes: 5 additions & 0 deletions modules/entity/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export const stringUtils = {
};

export { updatePackage } from './utility/update';

export { parseName } from './utility/parse-name';

export { addPackageToPackageJson } from './utility/package';

export { platformVersion } from './utility/libs-version';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
ActionReducer,
ActionReducerMap,
createFeatureSelector,
createSelector,
MetaReducer
} from '@ngrx/store';
import { environment } from '<%= environmentsPath %>';

export interface <%= classify(stateInterface) %> {

}

export const reducers: ActionReducerMap<<%= classify(stateInterface) %>> = {

};


export const metaReducers: MetaReducer<<%= classify(stateInterface) %>>[] = !environment.production ? [] : [];
1 change: 1 addition & 0 deletions modules/entity/schematics-core/utility/libs-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platformVersion = '^6.0.0';
27 changes: 27 additions & 0 deletions modules/entity/schematics-core/utility/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Tree } from '@angular-devkit/schematics';

/**
* Adds a package to the package.json
*/
export function addPackageToPackageJson(
host: Tree,
type: string,
pkg: string,
version: string
): Tree {
if (host.exists('package.json')) {
const sourceText = host.read('package.json')!.toString('utf-8');
const json = JSON.parse(sourceText);
if (!json[type]) {
json[type] = {};
}

if (!json[type][pkg]) {
json[type][pkg] = version;
}

host.overwrite('package.json', JSON.stringify(json, null, 2));
}

return host;
}
1 change: 1 addition & 0 deletions modules/router-store/schematics-core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ts_library(
"**/*.ts",
],
exclude = [
"**/templates/**/*.ts",
"**/testing/**/*.ts",
"**/*spec.ts",
],
Expand Down
5 changes: 5 additions & 0 deletions modules/router-store/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export const stringUtils = {
};

export { updatePackage } from './utility/update';

export { parseName } from './utility/parse-name';

export { addPackageToPackageJson } from './utility/package';

export { platformVersion } from './utility/libs-version';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
ActionReducer,
ActionReducerMap,
createFeatureSelector,
createSelector,
MetaReducer
} from '@ngrx/store';
import { environment } from '<%= environmentsPath %>';

export interface <%= classify(stateInterface) %> {

}

export const reducers: ActionReducerMap<<%= classify(stateInterface) %>> = {

};


export const metaReducers: MetaReducer<<%= classify(stateInterface) %>>[] = !environment.production ? [] : [];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platformVersion = '^6.0.0';
27 changes: 27 additions & 0 deletions modules/router-store/schematics-core/utility/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Tree } from '@angular-devkit/schematics';

/**
* Adds a package to the package.json
*/
export function addPackageToPackageJson(
host: Tree,
type: string,
pkg: string,
version: string
): Tree {
if (host.exists('package.json')) {
const sourceText = host.read('package.json')!.toString('utf-8');
const json = JSON.parse(sourceText);
if (!json[type]) {
json[type] = {};
}

if (!json[type][pkg]) {
json[type][pkg] = version;
}

host.overwrite('package.json', JSON.stringify(json, null, 2));
}

return host;
}
5 changes: 5 additions & 0 deletions modules/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export const stringUtils = {
};

export { updatePackage } from './utility/update';

export { parseName } from './utility/parse-name';

export { addPackageToPackageJson } from './utility/package';

export { platformVersion } from './utility/libs-version';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
ActionReducer,
ActionReducerMap,
createFeatureSelector,
createSelector,
MetaReducer
} from '@ngrx/store';
import { environment } from '<%= environmentsPath %>';

export interface <%= classify(stateInterface) %> {

}

export const reducers: ActionReducerMap<<%= classify(stateInterface) %>> = {

};


export const metaReducers: MetaReducer<<%= classify(stateInterface) %>>[] = !environment.production ? [] : [];
1 change: 1 addition & 0 deletions modules/schematics-core/utility/libs-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platformVersion = '^6.0.0';
27 changes: 27 additions & 0 deletions modules/schematics-core/utility/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Tree } from '@angular-devkit/schematics';

/**
* Adds a package to the package.json
*/
export function addPackageToPackageJson(
host: Tree,
type: string,
pkg: string,
version: string
): Tree {
if (host.exists('package.json')) {
const sourceText = host.read('package.json')!.toString('utf-8');
const json = JSON.parse(sourceText);
if (!json[type]) {
json[type] = {};
}

if (!json[type][pkg]) {
json[type][pkg] = version;
}

host.overwrite('package.json', JSON.stringify(json, null, 2));
}

return host;
}
1 change: 1 addition & 0 deletions modules/schematics/schematics-core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ts_library(
"**/*.ts",
],
exclude = [
"**/templates/**/*.ts",
"**/testing/**/*.ts",
"**/*spec.ts",
],
Expand Down
5 changes: 5 additions & 0 deletions modules/schematics/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export const stringUtils = {
};

export { updatePackage } from './utility/update';

export { parseName } from './utility/parse-name';

export { addPackageToPackageJson } from './utility/package';

export { platformVersion } from './utility/libs-version';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
ActionReducer,
ActionReducerMap,
createFeatureSelector,
createSelector,
MetaReducer
} from '@ngrx/store';
import { environment } from '<%= environmentsPath %>';

export interface <%= classify(stateInterface) %> {

}

export const reducers: ActionReducerMap<<%= classify(stateInterface) %>> = {

};


export const metaReducers: MetaReducer<<%= classify(stateInterface) %>>[] = !environment.production ? [] : [];
1 change: 1 addition & 0 deletions modules/schematics/schematics-core/utility/libs-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platformVersion = '^6.0.0';
27 changes: 27 additions & 0 deletions modules/schematics/schematics-core/utility/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Tree } from '@angular-devkit/schematics';

/**
* Adds a package to the package.json
*/
export function addPackageToPackageJson(
host: Tree,
type: string,
pkg: string,
version: string
): Tree {
if (host.exists('package.json')) {
const sourceText = host.read('package.json')!.toString('utf-8');
const json = JSON.parse(sourceText);
if (!json[type]) {
json[type] = {};
}

if (!json[type][pkg]) {
json[type][pkg] = version;
}

host.overwrite('package.json', JSON.stringify(json, null, 2));
}

return host;
}
4 changes: 1 addition & 3 deletions modules/schematics/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
chain,
filter,
mergeWith,
move,
template,
url,
} from '@angular-devkit/schematics';
Expand Down Expand Up @@ -152,13 +151,12 @@ export default function(options: StoreOptions): Rule {
options.stateInterface = stringUtils.classify(options.stateInterface);
}

const templateSource = apply(url('./files'), [
const templateSource = apply(url('../../schematics-core/templates/store'), [
template({
...stringUtils,
...(options as object),
environmentsPath,
} as any),
move(parsedPath.path),
]);

return chain([
Expand Down
1 change: 1 addition & 0 deletions modules/store-devtools/schematics-core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ts_library(
"**/*.ts",
],
exclude = [
"**/templates/**/*.ts",
"**/testing/**/*.ts",
"**/*spec.ts",
],
Expand Down
5 changes: 5 additions & 0 deletions modules/store-devtools/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export const stringUtils = {
};

export { updatePackage } from './utility/update';

export { parseName } from './utility/parse-name';

export { addPackageToPackageJson } from './utility/package';

export { platformVersion } from './utility/libs-version';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
ActionReducer,
ActionReducerMap,
createFeatureSelector,
createSelector,
MetaReducer
} from '@ngrx/store';
import { environment } from '<%= environmentsPath %>';

export interface <%= classify(stateInterface) %> {

}

export const reducers: ActionReducerMap<<%= classify(stateInterface) %>> = {

};


export const metaReducers: MetaReducer<<%= classify(stateInterface) %>>[] = !environment.production ? [] : [];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platformVersion = '^6.0.0';
Loading