Skip to content

Commit 1e863ee

Browse files
committed
feat: initial work to provide schematics
This work is heavily based off of NgRx's schematics. Thank you to their contributors for their amazing work.
1 parent 01cf046 commit 1e863ee

32 files changed

+3286
-2
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"watch": "ng build --watch --configuration development",
99
"test": "ng test"
1010
},
11+
"workspaces": {
12+
"packages": [
13+
"projects/*"
14+
]
15+
},
1116
"private": true,
1217
"dependencies": {
1318
"@angular/animations": "^18.2.0",
@@ -34,6 +39,7 @@
3439
"@testing-library/user-event": "^14.5.2",
3540
"@types/jasmine": "~5.1.0",
3641
"@types/jest": "^29.5.12",
42+
"@types/node": "^22.5.4",
3743
"jasmine-core": "~5.2.0",
3844
"jest": "^29.7.0",
3945
"jest-environment-jsdom": "^29.7.0",

projects/angular-redux/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
"peerDependencies": {
1414
"@angular/common": ">=17.3.0",
1515
"@angular/core": ">=17.3.0",
16-
"redux": "^5.0.0"
16+
"redux": "^5.0.0",
17+
"@reduxjs/toolkit": "^2.2.7"
1718
},
1819
"peerDependenciesMeta": {
1920
"redux": {
2021
"optional": true
22+
},
23+
"@reduxjs/toolkit": {
24+
"optional": true
2125
}
2226
},
27+
"schematics": "./schematics/collection.json",
2328
"dependencies": {
2429
"tslib": "^2.3.0"
2530
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This code is originally from NgRx:
2+
3+
https://github.com/ngrx/platform/tree/main/modules/schematics-core
4+
https://github.com/ngrx/platform/tree/main/modules/store/schematics-core
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
dasherize,
3+
decamelize,
4+
camelize,
5+
classify,
6+
underscore,
7+
group,
8+
capitalize,
9+
featurePath,
10+
pluralize,
11+
} from './utility/strings';
12+
13+
export {
14+
findNodes,
15+
getSourceNodes,
16+
getDecoratorMetadata,
17+
getContentOfKeyLiteral,
18+
insertAfterLastOccurrence,
19+
insertImport,
20+
addBootstrapToModule,
21+
addDeclarationToModule,
22+
addExportToModule,
23+
addImportToModule,
24+
addProviderToComponent,
25+
addProviderToModule,
26+
replaceImport,
27+
containsProperty,
28+
} from './utility/ast-utils';
29+
30+
export {
31+
NoopChange,
32+
InsertChange,
33+
RemoveChange,
34+
ReplaceChange,
35+
createReplaceChange,
36+
createChangeRecorder,
37+
commitChanges
38+
} from './utility/change';
39+
export type {
40+
Host,
41+
Change
42+
} from './utility/change';
43+
44+
export {getWorkspace, getWorkspacePath} from './utility/config';
45+
export type { AppConfig } from './utility/config';
46+
47+
export { findComponentFromOptions } from './utility/find-component';
48+
49+
export {
50+
findModule,
51+
findModuleFromOptions,
52+
buildRelativePath
53+
} from './utility/find-module';
54+
export type { ModuleOptions } from './utility/find-module';
55+
56+
export { findPropertyInAstObject } from './utility/json-utilts';
57+
58+
export { getProjectPath, getProject, isLib } from './utility/project';
59+
60+
export const stringUtils = {
61+
dasherize,
62+
decamelize,
63+
camelize,
64+
classify,
65+
underscore,
66+
group,
67+
capitalize,
68+
featurePath,
69+
pluralize,
70+
};
71+
72+
export { updatePackage } from './utility/update';
73+
74+
export { parseName } from './utility/parse-name';
75+
76+
export { addPackageToPackageJson } from './utility/package';
77+
78+
export {
79+
visitTSSourceFiles,
80+
visitNgModuleImports,
81+
visitNgModuleExports,
82+
visitComponents,
83+
visitDecorator,
84+
visitNgModules,
85+
visitTemplates,
86+
} from './utility/visitors';
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { UnitTestTree } from '@angular-devkit/schematics/testing';
2+
3+
export function createAppModule(
4+
tree: UnitTestTree,
5+
path?: string
6+
): UnitTestTree {
7+
tree.create(
8+
path || '/src/app/app.module.ts',
9+
`
10+
import { BrowserModule } from '@angular/platform-browser';
11+
import { NgModule } from '@angular/core';
12+
import { AppComponent } from './app.component';
13+
14+
@NgModule({
15+
declarations: [
16+
AppComponent
17+
],
18+
imports: [
19+
BrowserModule
20+
],
21+
providers: [],
22+
bootstrap: [AppComponent]
23+
})
24+
export class AppModule { }
25+
`
26+
);
27+
28+
return tree;
29+
}
30+
31+
export function createAppModuleWithEffects(
32+
tree: UnitTestTree,
33+
path: string,
34+
effects?: string
35+
): UnitTestTree {
36+
tree.create(
37+
path || '/src/app/app.module.ts',
38+
`
39+
import { BrowserModule } from '@angular/platform-browser';
40+
import { NgModule } from '@angular/core';
41+
import { AppComponent } from './app.component';
42+
import { EffectsModule } from '@ngrx/effects';
43+
44+
@NgModule({
45+
declarations: [
46+
AppComponent
47+
],
48+
imports: [
49+
BrowserModule,
50+
${effects}
51+
],
52+
providers: [],
53+
bootstrap: [AppComponent]
54+
})
55+
export class AppModule { }
56+
`
57+
);
58+
59+
return tree;
60+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Tree } from '@angular-devkit/schematics';
2+
import {
3+
UnitTestTree,
4+
SchematicTestRunner,
5+
} from '@angular-devkit/schematics/testing';
6+
7+
export const packagePath = '/package.json';
8+
9+
export function createPackageJson(
10+
prefix: string,
11+
pkg: string,
12+
tree: UnitTestTree,
13+
version = '5.2.0',
14+
packagePath = '/package.json'
15+
) {
16+
tree.create(
17+
packagePath,
18+
`{
19+
"dependencies": {
20+
"@ngrx/${pkg}": "${prefix}${version}"
21+
}
22+
}`
23+
);
24+
25+
return tree;
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { UnitTestTree } from '@angular-devkit/schematics/testing';
2+
3+
export function createReducers(
4+
tree: UnitTestTree,
5+
path?: string,
6+
project = 'bar'
7+
) {
8+
tree.create(
9+
path || `/projects/${project}/src/app/reducers/index.ts`,
10+
`
11+
import { isDevMode } from '@angular/core';
12+
import {
13+
ActionReducer,
14+
ActionReducerMap,
15+
createFeatureSelector,
16+
createSelector,
17+
MetaReducer
18+
} from '@ngrx/${'store'}';
19+
20+
export interface State {
21+
22+
}
23+
24+
export const reducers: ActionReducerMap<State> = {
25+
26+
};
27+
28+
29+
export const metaReducers: MetaReducer<State>[] = isDevMode() ? [] : [];
30+
`
31+
);
32+
33+
return tree;
34+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {
2+
SchematicTestRunner,
3+
UnitTestTree,
4+
} from '@angular-devkit/schematics/testing';
5+
6+
export const defaultWorkspaceOptions = {
7+
name: 'workspace',
8+
newProjectRoot: 'projects',
9+
version: '6.0.0',
10+
};
11+
12+
export const defaultAppOptions = {
13+
name: 'bar',
14+
inlineStyle: false,
15+
inlineTemplate: false,
16+
viewEncapsulation: 'Emulated',
17+
routing: false,
18+
style: 'css',
19+
skipTests: false,
20+
standalone: false,
21+
};
22+
23+
const defaultLibOptions = {
24+
name: 'baz',
25+
};
26+
27+
export function getTestProjectPath(
28+
workspaceOptions: any = defaultWorkspaceOptions,
29+
appOptions: any = defaultAppOptions
30+
) {
31+
return `/${workspaceOptions.newProjectRoot}/${appOptions.name}`;
32+
}
33+
34+
export async function createWorkspace(
35+
schematicRunner: SchematicTestRunner,
36+
appTree: UnitTestTree,
37+
workspaceOptions = defaultWorkspaceOptions,
38+
appOptions = defaultAppOptions,
39+
libOptions = defaultLibOptions
40+
) {
41+
appTree = await schematicRunner.runExternalSchematic(
42+
'@schematics/angular',
43+
'workspace',
44+
workspaceOptions
45+
);
46+
47+
appTree = await schematicRunner.runExternalSchematic(
48+
'@schematics/angular',
49+
'application',
50+
appOptions,
51+
appTree
52+
);
53+
54+
appTree = await schematicRunner.runExternalSchematic(
55+
'@schematics/angular',
56+
'application',
57+
{ ...appOptions, name: 'bar-standalone', standalone: true },
58+
appTree
59+
);
60+
61+
appTree = await schematicRunner.runExternalSchematic(
62+
'@schematics/angular',
63+
'library',
64+
libOptions,
65+
appTree
66+
);
67+
68+
return appTree;
69+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './create-app-module';
2+
export * from './create-reducers';
3+
export * from './create-workspace';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const upgradeVersion = '6.0.0';
2+
export const versionPrefixes = ['~', '^', ''];

0 commit comments

Comments
 (0)