-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nx): update storybook configuration (#2104)
- Loading branch information
1 parent
093e693
commit c4cba1c
Showing
7 changed files
with
235 additions
and
21 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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"schematics": {} | ||
"schematics": { | ||
"update-builder-8.8.2": { | ||
"version": "8.8.2", | ||
"description": "Update storybook builder and tsconfig", | ||
"factory": "./src/migrations/update-8-8-2/update-builder-8-8-2" | ||
} | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
packages/storybook/src/migrations/update-8-8-2/update-builder-8-8-2.spec.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,157 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { | ||
updateJsonInTree, | ||
readJsonInTree, | ||
updateWorkspaceInTree, | ||
readWorkspace, | ||
getWorkspacePath | ||
} from '@nrwl/workspace'; | ||
|
||
import * as path from 'path'; | ||
|
||
describe('Update 8-8-2', () => { | ||
let tree: Tree; | ||
let schematicRunner: SchematicTestRunner; | ||
|
||
beforeEach(async () => { | ||
tree = Tree.empty(); | ||
schematicRunner = new SchematicTestRunner( | ||
'@nrwl/storybook', | ||
path.join(__dirname, '../../../migrations.json') | ||
); | ||
}); | ||
|
||
it(`should remove headless/watch as options for e2e builder`, async () => { | ||
tree.create( | ||
'workspace.json', | ||
JSON.stringify({ | ||
projects: { | ||
['home-ui']: { | ||
projectType: 'library', | ||
root: 'libs/home/ui', | ||
sourceRoot: 'libs/home/ui/src', | ||
prefix: 'app', | ||
architect: { | ||
storybook: { | ||
builder: '@nrwl/storybook:storybook', | ||
options: { | ||
uiFramework: '@storybook/angular', | ||
port: 4400, | ||
config: { | ||
configFolder: 'libs/home/ui/.storybook' | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
['home-ui-e2e']: { | ||
root: 'apps/home-ui-e2e', | ||
sourceRoot: 'apps/home-ui-e2e/src', | ||
architect: { | ||
e2e: { | ||
builder: '@nrwl/cypress:cypress', | ||
options: { | ||
cypressConfig: 'apps/home-ui-e2e/cypress.json', | ||
tsConfig: 'apps/home-ui-e2e/tsconfig.e2e.json', | ||
devServerTarget: 'home-ui:storybook', | ||
headless: false, | ||
watch: true | ||
}, | ||
configurations: { | ||
headless: { | ||
devServerTarget: 'home-ui:storybook:ci', | ||
headless: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
|
||
tree = await schematicRunner | ||
.runSchematicAsync('update-builder-8.8.2', {}, tree) | ||
.toPromise(); | ||
|
||
const config = readWorkspace(tree); | ||
expect( | ||
config.projects['home-ui-e2e'].architect.e2e.options.headless | ||
).toBeUndefined(); | ||
expect( | ||
config.projects['home-ui-e2e'].architect.e2e.options.watch | ||
).toBeUndefined(); | ||
expect( | ||
config.projects['home-ui-e2e'].architect.e2e.configurations | ||
).toBeUndefined(); | ||
}); | ||
|
||
it(`should add emitDecoratorMetadata to storybook tsconfig.json`, async () => { | ||
tree.create( | ||
'libs/home/ui/.storybook/tsconfig.json', | ||
JSON.stringify({ | ||
extends: '../tsconfig.json', | ||
exclude: ['../src/test.ts', '../**/*.spec.ts'], | ||
include: ['../src/**/*'] | ||
}) | ||
); | ||
tree.create( | ||
'workspace.json', | ||
JSON.stringify({ | ||
projects: { | ||
['home-ui']: { | ||
projectType: 'library', | ||
root: 'libs/home/ui', | ||
sourceRoot: 'libs/home/ui/src', | ||
prefix: 'app', | ||
architect: { | ||
storybook: { | ||
builder: '@nrwl/storybook:storybook', | ||
options: { | ||
uiFramework: '@storybook/angular', | ||
port: 4400, | ||
config: { | ||
configFolder: 'libs/home/ui/.storybook' | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
['home-ui-e2e']: { | ||
root: 'apps/home-ui-e2e', | ||
sourceRoot: 'apps/home-ui-e2e/src', | ||
architect: { | ||
e2e: { | ||
builder: '@nrwl/cypress:cypress', | ||
options: { | ||
cypressConfig: 'apps/home-ui-e2e/cypress.json', | ||
tsConfig: 'apps/home-ui-e2e/tsconfig.e2e.json', | ||
devServerTarget: 'home-ui:storybook', | ||
headless: false, | ||
watch: true | ||
}, | ||
configurations: { | ||
headless: { | ||
devServerTarget: 'home-ui:storybook:ci', | ||
headless: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
|
||
tree = await schematicRunner | ||
.runSchematicAsync('update-builder-8.8.2', {}, tree) | ||
.toPromise(); | ||
|
||
const tsconfig = readJsonInTree( | ||
tree, | ||
'libs/home/ui/.storybook/tsconfig.json' | ||
); | ||
expect(tsconfig.compilerOptions.emitDecoratorMetadata).toBe(true); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/storybook/src/migrations/update-8-8-2/update-builder-8-8-2.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,61 @@ | ||
import { Rule, chain } from '@angular-devkit/schematics'; | ||
import { | ||
updateWorkspaceInTree, | ||
readWorkspaceJson, | ||
readWorkspace, | ||
updateJsonInTree | ||
} from '@nrwl/workspace'; | ||
|
||
export default function update(): Rule { | ||
return chain([ | ||
updateWorkspaceInTree(config => { | ||
const filteredProjects = []; | ||
Object.keys(config.projects).forEach(name => { | ||
if ( | ||
config.projects[name].architect && | ||
config.projects[name].architect.e2e && | ||
config.projects[name].architect.e2e.builder === | ||
'@nrwl/cypress:cypress' && | ||
config.projects[name].architect.e2e.options.devServerTarget.endsWith( | ||
':storybook' | ||
) | ||
) { | ||
filteredProjects.push(config.projects[name]); | ||
} | ||
}); | ||
filteredProjects.forEach(p => { | ||
delete p.architect.e2e.options.headless; | ||
delete p.architect.e2e.options.watch; | ||
delete p.architect.e2e.configurations; | ||
}); | ||
return config; | ||
}), | ||
(tree, context) => { | ||
const workspace = readWorkspace(tree); | ||
const tsconfigUpdateRules = []; | ||
Object.keys(workspace.projects).forEach(name => { | ||
if ( | ||
workspace.projects[name].architect && | ||
workspace.projects[name].architect.storybook && | ||
workspace.projects[name].architect.storybook.builder === | ||
'@nrwl/storybook:storybook' && | ||
workspace.projects[name].architect.storybook.options.config | ||
.configFolder | ||
) { | ||
const storybookFolderPath = | ||
workspace.projects[name].architect.storybook.options.config | ||
.configFolder; | ||
tsconfigUpdateRules.push( | ||
updateJsonInTree(`${storybookFolderPath}/tsconfig.json`, json => ({ | ||
...json, | ||
compilerOptions: { | ||
emitDecoratorMetadata: true | ||
} | ||
})) | ||
); | ||
} | ||
}); | ||
return chain(tsconfigUpdateRules); | ||
} | ||
]); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/storybook/src/schematics/configuration/lib-files/.storybook/tsconfig.json
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true | ||
}, | ||
"exclude": ["../src/test.ts", "../**/*.spec.ts"], | ||
"include": ["../src/**/*"] | ||
} |
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