Skip to content

Commit 1837dba

Browse files
brandonrobertsMikeRyanDev
authored andcommitted
feat(Schematics): Introduce @ngrx/schematics (#631)
Closes #53
1 parent 561542c commit 1837dba

File tree

79 files changed

+3949
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3949
-68
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist
2+
/modules/schematics/src/*/files/*

build/builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default createBuilder([
1212
['Cleaning JavaScript files', tasks.cleanJavaScriptFiles],
1313
['Removing remaining sourcemap files', tasks.removeRemainingSourceMapFiles],
1414
['Copying type definition files', tasks.copyTypeDefinitionFiles],
15+
['Copying schematic files', tasks.copySchematicFiles],
1516
['Minifying UMD bundles', tasks.minifyUmdBundles],
1617
['Copying documents', tasks.copyDocs],
1718
['Copying package.json files', tasks.copyPackageJsonFiles],

build/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface PackageDescription {
22
name: string;
33
hasTestingModule: boolean;
4+
bundle: boolean;
45
}
56

67
export interface Config {
@@ -12,25 +13,36 @@ export const packages: PackageDescription[] = [
1213
{
1314
name: 'store',
1415
hasTestingModule: false,
16+
bundle: true,
1517
},
1618
{
1719
name: 'effects',
1820
hasTestingModule: true,
21+
bundle: true,
1922
},
2023
{
2124
name: 'router-store',
2225
hasTestingModule: false,
26+
bundle: true,
2327
},
2428
{
2529
name: 'store-devtools',
2630
hasTestingModule: false,
31+
bundle: true,
2732
},
2833
{
2934
name: 'entity',
3035
hasTestingModule: false,
36+
bundle: true,
3137
},
3238
{
3339
name: 'codegen',
3440
hasTestingModule: false,
41+
bundle: true,
42+
},
43+
{
44+
name: 'schematics',
45+
hasTestingModule: false,
46+
bundle: false,
3547
},
3648
];

build/tasks.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ async function _compilePackagesWithNgc(pkg: string) {
4141
: [pkg, 'index'];
4242

4343
const entryTypeDefinition = `export * from './${exportPath}/${moduleName}';`;
44-
const entryMetadata = `{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./${pkg}/index"}]}`;
44+
const entryMetadata = `{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./${
45+
pkg
46+
}/index"}]}`;
4547

4648
await Promise.all([
4749
util.writeFile(`./dist/packages/${pkg}.d.ts`, entryTypeDefinition),
@@ -57,6 +59,9 @@ export async function bundleFesms(config: Config) {
5759
const pkgs = util.getAllPackages(config);
5860

5961
await mapAsync(pkgs, async pkg => {
62+
if (!util.shouldBundle(config, pkg)) {
63+
return;
64+
}
6065
const topLevelName = util.getTopLevelName(pkg);
6166

6267
await util.exec('rollup', [
@@ -79,6 +84,9 @@ export async function downLevelFesmsToES5(config: Config) {
7984
const tscArgs = ['--target es5', '--module es2015', '--noLib', '--sourceMap'];
8085

8186
await mapAsync(packages, async pkg => {
87+
if (!util.shouldBundle(config, pkg)) {
88+
return;
89+
}
8290
const topLevelName = util.getTopLevelName(pkg);
8391

8492
const file = `./dist/${topLevelName}/${config.scope}/${pkg}.js`;
@@ -98,6 +106,9 @@ export async function downLevelFesmsToES5(config: Config) {
98106
*/
99107
export async function createUmdBundles(config: Config) {
100108
await mapAsync(util.getAllPackages(config), async pkg => {
109+
if (!util.shouldBundle(config, pkg)) {
110+
return;
111+
}
101112
const topLevelName = util.getTopLevelName(pkg);
102113
const destinationName = util.getDestinationName(pkg);
103114

@@ -127,14 +138,21 @@ export async function cleanTypeScriptFiles(config: Config) {
127138
* leaving the bundles and FESM in place
128139
*/
129140
export async function cleanJavaScriptFiles(config: Config) {
141+
const packages = util
142+
.getTopLevelPackages(config)
143+
.filter(pkg => !util.shouldBundle(config, pkg));
130144
const jsFilesGlob = './dist/packages/**/*.js';
131145
const jsExcludeFilesFlob = './dist/packages/(bundles|@ngrx)/**/*.js';
132146
const filesToRemove = await util.getListOfFiles(
133147
jsFilesGlob,
134148
jsExcludeFilesFlob
135149
);
136150

137-
await mapAsync(filesToRemove, util.remove);
151+
const filteredFilesToRemove = filesToRemove.filter((file: string) =>
152+
packages.some(pkg => file.indexOf(pkg) === -1)
153+
);
154+
155+
await mapAsync(filteredFilesToRemove, util.remove);
138156
}
139157

140158
/**
@@ -143,6 +161,9 @@ export async function cleanJavaScriptFiles(config: Config) {
143161
*/
144162
export async function renamePackageEntryFiles(config: Config) {
145163
await mapAsync(util.getAllPackages(config), async pkg => {
164+
if (!util.shouldBundle(config, pkg)) {
165+
return;
166+
}
146167
const bottomLevelName = util.getBottomLevelName(pkg);
147168

148169
const files = await util.getListOfFiles(`./dist/packages/${pkg}/index.**`);
@@ -192,6 +213,9 @@ export async function minifyUmdBundles(config: Config) {
192213
const uglifyArgs = ['-c', '-m', '--comments'];
193214

194215
await mapAsync(util.getAllPackages(config), async pkg => {
216+
if (!util.shouldBundle(config, pkg)) {
217+
return;
218+
}
195219
const topLevelName = util.getTopLevelName(pkg);
196220
const destinationName = util.getDestinationName(pkg);
197221
const file = `./dist/${topLevelName}/bundles/${destinationName}.umd.js`;
@@ -201,7 +225,9 @@ export async function minifyUmdBundles(config: Config) {
201225
file,
202226
...uglifyArgs,
203227
`-o ${out}`,
204-
`--source-map "filename='${out}.map' includeSources='${file}', content='${file}.map'"`,
228+
`--source-map "filename='${out}.map' includeSources='${file}', content='${
229+
file
230+
}.map'"`,
205231
]);
206232
});
207233
}
@@ -288,3 +314,28 @@ export function mapAsync<T>(
288314
) {
289315
return Promise.all(list.map(mapFn));
290316
}
317+
318+
/**
319+
* Copy schematics files
320+
*/
321+
export async function copySchematicFiles(config: Config) {
322+
const packages = util
323+
.getTopLevelPackages(config)
324+
.filter(pkg => !util.shouldBundle(config, pkg));
325+
326+
const collectionFiles = await util.getListOfFiles(
327+
`./modules/?(${packages.join('|')})/collection.json`
328+
);
329+
const schemaFiles = await util.getListOfFiles(
330+
`./modules/?(${packages.join('|')})/src/*/schema.*`
331+
);
332+
const templateFiles = await util.getListOfFiles(
333+
`./modules/?(${packages.join('|')})/src/*/files/*`
334+
);
335+
const files = [...collectionFiles, ...schemaFiles, ...templateFiles];
336+
337+
await mapAsync(files, async file => {
338+
const target = file.replace('modules/', 'dist/');
339+
await util.copy(file, target);
340+
});
341+
}

build/util.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ export function createBuilder(tasks: TaskDef[]) {
134134
}
135135

136136
export function flatMap<K, J>(list: K[], mapFn: (item: K) => J[]): J[] {
137-
return list.reduce(function(newList, nextItem) {
138-
return [...newList, ...mapFn(nextItem)];
139-
}, [] as J[]);
137+
return list.reduce(
138+
function(newList, nextItem) {
139+
return [...newList, ...mapFn(nextItem)];
140+
},
141+
[] as J[]
142+
);
140143
}
141144

142145
export function getTopLevelPackages(config: Config) {
@@ -178,3 +181,9 @@ export function getBottomLevelName(packageName: string) {
178181
export function baseDir(...dirs: string[]): string {
179182
return `"${path.resolve(__dirname, '../', ...dirs)}"`;
180183
}
184+
185+
export function shouldBundle(config: Config, packageName: string) {
186+
const pkg = config.packages.find(pkg => pkg.name === packageName);
187+
188+
return pkg ? pkg.bundle : false;
189+
}

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ machine:
22
environment:
33
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
44
node:
5-
version: 8.6.0
5+
version: 8.9.1
66

77
dependencies:
88
pre:

example-app/app/auth/components/login-form.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Login Page', () => {
3333
* HTML.
3434
*
3535
* We can also use this as a validation tool against changes
36-
* to the component's template against the currently stored
36+
* to the component's template against the currently stored
3737
* snapshot.
3838
*/
3939
expect(fixture).toMatchSnapshot();

example-app/app/books/effects/book.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export class BookEffects {
6161
@Inject(SEARCH_DEBOUNCE)
6262
private debounce: number,
6363
/**
64-
* You inject an optional Scheduler that will be undefined
65-
* in normal application usage, but its injected here so that you can mock out
66-
* during testing using the RxJS TestScheduler for simulating passages of time.
67-
*/
64+
* You inject an optional Scheduler that will be undefined
65+
* in normal application usage, but its injected here so that you can mock out
66+
* during testing using the RxJS TestScheduler for simulating passages of time.
67+
*/
6868
@Optional()
6969
@Inject(SEARCH_SCHEDULER)
7070
private scheduler: Scheduler

example-app/app/books/reducers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface BooksState {
1111
}
1212

1313
export interface State extends fromRoot.State {
14-
'books': BooksState;
14+
books: BooksState;
1515
}
1616

1717
export const reducers = {
@@ -39,7 +39,7 @@ export const reducers = {
3939
/**
4040
* The createFeatureSelector function selects a piece of state from the root of the state object.
4141
* This is used for selecting feature states that are loaded eagerly or lazily.
42-
*/
42+
*/
4343
export const getBooksState = createFeatureSelector<BooksState>('books');
4444

4545
/**

modules/codegen/src/metadata/get-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function getType(
1313
}
1414

1515
return ts.isLiteralTypeNode(typeProperty.type as any)
16-
? typeProperty.type as any
16+
? (typeProperty.type as any)
1717
: undefined;
1818

1919
// return !!typeProperty && ts.isLiteralTypeNode(typeProperty.type) ? typeProperty.type : undefined;

0 commit comments

Comments
 (0)