-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from reduxjs/ng-add
feat: Support `ng add`
- Loading branch information
Showing
37 changed files
with
3,594 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,18 @@ | |
"scripts": { | ||
"ng": "ng", | ||
"start": "ng serve", | ||
"build": "ng build", | ||
"build": "ng build angular-redux && tsc -p projects/angular-redux/tsconfig.schematics.json && yarn build:copy", | ||
"build:copy": "cd ./projects/angular-redux/schematics && copyfiles \"**/*.json\" ../../../dist/angular-redux/schematics", | ||
"build:ng": "ng build", | ||
"watch": "ng build --watch --configuration development", | ||
"test": "ng test" | ||
"test": "yarn test:ng && yarn test:schematics", | ||
"test:ng": "ng test", | ||
"test:schematics": "cd projects/angular-redux/schematics && jest" | ||
}, | ||
"workspaces": { | ||
"packages": [ | ||
"projects/*" | ||
] | ||
}, | ||
"private": true, | ||
"dependencies": { | ||
|
@@ -32,12 +41,16 @@ | |
"@testing-library/dom": "^10.0.0", | ||
"@testing-library/jest-dom": "^6.4.8", | ||
"@testing-library/user-event": "^14.5.2", | ||
"@types/copyfiles": "^2", | ||
"@types/jasmine": "~5.1.0", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^22.5.4", | ||
"copyfiles": "^2.4.1", | ||
"jasmine-core": "~5.2.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"ng-packagr": "^18.2.0", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "~5.5.2" | ||
}, | ||
"packageManager": "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This code is originally from NgRx: | ||
|
||
https://github.com/ngrx/platform/tree/main/modules/schematics-core | ||
https://github.com/ngrx/platform/tree/main/modules/store/schematics-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
dasherize, | ||
decamelize, | ||
camelize, | ||
classify, | ||
underscore, | ||
group, | ||
capitalize, | ||
featurePath, | ||
pluralize, | ||
} from './utility/strings'; | ||
|
||
export { | ||
findNodes, | ||
getSourceNodes, | ||
getDecoratorMetadata, | ||
getContentOfKeyLiteral, | ||
insertAfterLastOccurrence, | ||
insertImport, | ||
addBootstrapToModule, | ||
addDeclarationToModule, | ||
addExportToModule, | ||
addImportToModule, | ||
addProviderToComponent, | ||
addProviderToModule, | ||
replaceImport, | ||
containsProperty, | ||
} from './utility/ast-utils'; | ||
|
||
export { | ||
NoopChange, | ||
InsertChange, | ||
RemoveChange, | ||
ReplaceChange, | ||
createReplaceChange, | ||
createChangeRecorder, | ||
commitChanges | ||
} from './utility/change'; | ||
export type { | ||
Host, | ||
Change | ||
} from './utility/change'; | ||
|
||
export {getWorkspace, getWorkspacePath} from './utility/config'; | ||
export type { AppConfig } from './utility/config'; | ||
|
||
export { findComponentFromOptions } from './utility/find-component'; | ||
|
||
export { | ||
findModule, | ||
findModuleFromOptions, | ||
buildRelativePath | ||
} from './utility/find-module'; | ||
export type { ModuleOptions } from './utility/find-module'; | ||
|
||
export { findPropertyInAstObject } from './utility/json-utilts'; | ||
|
||
export { getProjectPath, getProject, isLib } from './utility/project'; | ||
|
||
export const stringUtils = { | ||
dasherize, | ||
decamelize, | ||
camelize, | ||
classify, | ||
underscore, | ||
group, | ||
capitalize, | ||
featurePath, | ||
pluralize, | ||
}; | ||
|
||
export { parseName } from './utility/parse-name'; | ||
|
||
export { addPackageToPackageJson } from './utility/package'; | ||
|
||
export { | ||
visitTSSourceFiles, | ||
visitNgModuleImports, | ||
visitNgModuleExports, | ||
visitComponents, | ||
visitDecorator, | ||
visitNgModules, | ||
visitTemplates, | ||
} from './utility/visitors'; |
60 changes: 60 additions & 0 deletions
60
projects/angular-redux/schematics-core/testing/create-app-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
|
||
export function createAppModule( | ||
tree: UnitTestTree, | ||
path?: string | ||
): UnitTestTree { | ||
tree.create( | ||
path || '/src/app/app.module.ts', | ||
` | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import { AppComponent } from './app.component'; | ||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
` | ||
); | ||
|
||
return tree; | ||
} | ||
|
||
export function createAppModuleWithEffects( | ||
tree: UnitTestTree, | ||
path: string, | ||
effects?: string | ||
): UnitTestTree { | ||
tree.create( | ||
path || '/src/app/app.module.ts', | ||
` | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import { AppComponent } from './app.component'; | ||
import { EffectsModule } from '@ngrx/effects'; | ||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
${effects} | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
` | ||
); | ||
|
||
return tree; | ||
} |
26 changes: 26 additions & 0 deletions
26
projects/angular-redux/schematics-core/testing/create-package.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { | ||
UnitTestTree, | ||
SchematicTestRunner, | ||
} from '@angular-devkit/schematics/testing'; | ||
|
||
export const packagePath = '/package.json'; | ||
|
||
export function createPackageJson( | ||
prefix: string, | ||
pkg: string, | ||
tree: UnitTestTree, | ||
version = '5.2.0', | ||
packagePath = '/package.json' | ||
) { | ||
tree.create( | ||
packagePath, | ||
`{ | ||
"dependencies": { | ||
"@ngrx/${pkg}": "${prefix}${version}" | ||
} | ||
}` | ||
); | ||
|
||
return tree; | ||
} |
34 changes: 34 additions & 0 deletions
34
projects/angular-redux/schematics-core/testing/create-reducers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
|
||
export function createReducers( | ||
tree: UnitTestTree, | ||
path?: string, | ||
project = 'bar' | ||
) { | ||
tree.create( | ||
path || `/projects/${project}/src/app/reducers/index.ts`, | ||
` | ||
import { isDevMode } from '@angular/core'; | ||
import { | ||
ActionReducer, | ||
ActionReducerMap, | ||
createFeatureSelector, | ||
createSelector, | ||
MetaReducer | ||
} from '@ngrx/${'store'}'; | ||
export interface State { | ||
} | ||
export const reducers: ActionReducerMap<State> = { | ||
}; | ||
export const metaReducers: MetaReducer<State>[] = isDevMode() ? [] : []; | ||
` | ||
); | ||
|
||
return tree; | ||
} |
69 changes: 69 additions & 0 deletions
69
projects/angular-redux/schematics-core/testing/create-workspace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
SchematicTestRunner, | ||
UnitTestTree, | ||
} from '@angular-devkit/schematics/testing'; | ||
|
||
export const defaultWorkspaceOptions = { | ||
name: 'workspace', | ||
newProjectRoot: 'projects', | ||
version: '6.0.0', | ||
}; | ||
|
||
export const defaultAppOptions = { | ||
name: 'bar', | ||
inlineStyle: false, | ||
inlineTemplate: false, | ||
viewEncapsulation: 'Emulated', | ||
routing: false, | ||
style: 'css', | ||
skipTests: false, | ||
standalone: false, | ||
}; | ||
|
||
const defaultLibOptions = { | ||
name: 'baz', | ||
}; | ||
|
||
export function getTestProjectPath( | ||
workspaceOptions: any = defaultWorkspaceOptions, | ||
appOptions: any = defaultAppOptions | ||
) { | ||
return `/${workspaceOptions.newProjectRoot}/${appOptions.name}`; | ||
} | ||
|
||
export async function createWorkspace( | ||
schematicRunner: SchematicTestRunner, | ||
appTree: UnitTestTree, | ||
workspaceOptions = defaultWorkspaceOptions, | ||
appOptions = defaultAppOptions, | ||
libOptions = defaultLibOptions | ||
) { | ||
appTree = await schematicRunner.runExternalSchematic( | ||
'@schematics/angular', | ||
'workspace', | ||
workspaceOptions | ||
); | ||
|
||
appTree = await schematicRunner.runExternalSchematic( | ||
'@schematics/angular', | ||
'application', | ||
appOptions, | ||
appTree | ||
); | ||
|
||
appTree = await schematicRunner.runExternalSchematic( | ||
'@schematics/angular', | ||
'application', | ||
{ ...appOptions, name: 'bar-standalone', standalone: true }, | ||
appTree | ||
); | ||
|
||
appTree = await schematicRunner.runExternalSchematic( | ||
'@schematics/angular', | ||
'library', | ||
libOptions, | ||
appTree | ||
); | ||
|
||
return appTree; | ||
} |
Oops, something went wrong.