fix(schematics): handle complex asset options in ng-add
This commit is contained in:
parent
02a49e774f
commit
9a60c697e8
@ -301,6 +301,21 @@ describe('Nrwl Convert to Nx Workspace', () => {
|
|||||||
checkFilesExist('dist/apps/proj-server/main.js');
|
checkFilesExist('dist/apps/proj-server/main.js');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should convert a project with common libraries in the ecosystem', () => {
|
||||||
|
// create a new AngularCLI app
|
||||||
|
runNgNew();
|
||||||
|
|
||||||
|
// Add some Angular libraries
|
||||||
|
runCLI('add @angular/elements');
|
||||||
|
runCLI('add @angular/material');
|
||||||
|
runCLI('add @angular/pwa');
|
||||||
|
runCLI('add @ngrx/store');
|
||||||
|
runCLI('add @ngrx/effects');
|
||||||
|
copyMissingPackages();
|
||||||
|
// Add Nx
|
||||||
|
runCLI('add @nrwl/schematics');
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle workspaces with no e2e project', () => {
|
it('should handle workspaces with no e2e project', () => {
|
||||||
// create a new AngularCLI app
|
// create a new AngularCLI app
|
||||||
runNgNew();
|
runNgNew();
|
||||||
|
|||||||
@ -130,6 +130,22 @@ function updateAngularCLIJson(options: Schema): Rule {
|
|||||||
|
|
||||||
const oldSourceRoot = app.sourceRoot;
|
const oldSourceRoot = app.sourceRoot;
|
||||||
|
|
||||||
|
function convertAsset(asset: string | any) {
|
||||||
|
if (typeof asset === 'string') {
|
||||||
|
return asset.startsWith(oldSourceRoot)
|
||||||
|
? convertPath(options.name, asset)
|
||||||
|
: asset;
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...asset,
|
||||||
|
input:
|
||||||
|
asset.input && asset.input.startsWith(oldSourceRoot)
|
||||||
|
? convertPath(options.name, asset.input)
|
||||||
|
: asset.input
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app = {
|
app = {
|
||||||
...app,
|
...app,
|
||||||
root: path.join('apps', options.name),
|
root: path.join('apps', options.name),
|
||||||
@ -143,26 +159,19 @@ function updateAngularCLIJson(options: Schema): Rule {
|
|||||||
outputPath: path.join('dist/apps', options.name),
|
outputPath: path.join('dist/apps', options.name),
|
||||||
index: convertPath(options.name, buildConfig.options.index),
|
index: convertPath(options.name, buildConfig.options.index),
|
||||||
main: convertPath(options.name, buildConfig.options.main),
|
main: convertPath(options.name, buildConfig.options.main),
|
||||||
polyfills: convertPath(options.name, buildConfig.options.polyfills),
|
|
||||||
tsConfig: path.join(app.root, getFilename(buildConfig.options.tsConfig)),
|
tsConfig: path.join(app.root, getFilename(buildConfig.options.tsConfig)),
|
||||||
assets: buildConfig.options.assets.map(
|
polyfills:
|
||||||
asset =>
|
buildConfig.options.polyfills &&
|
||||||
asset.startsWith(oldSourceRoot)
|
convertPath(options.name, buildConfig.options.polyfills),
|
||||||
? convertPath(options.name, asset)
|
assets:
|
||||||
: asset
|
buildConfig.options.assets &&
|
||||||
),
|
buildConfig.options.assets.map(convertAsset),
|
||||||
styles: buildConfig.options.styles.map(
|
styles:
|
||||||
style =>
|
buildConfig.options.styles &&
|
||||||
style.startsWith(oldSourceRoot)
|
buildConfig.options.styles.map(convertAsset),
|
||||||
? convertPath(options.name, style)
|
scripts:
|
||||||
: style
|
buildConfig.options.scripts &&
|
||||||
),
|
buildConfig.options.scripts.map(convertAsset)
|
||||||
scripts: buildConfig.options.scripts.map(
|
|
||||||
script =>
|
|
||||||
script.startsWith(oldSourceRoot)
|
|
||||||
? convertPath(options.name, script)
|
|
||||||
: script
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(buildConfig.configurations)
|
Object.keys(buildConfig.configurations)
|
||||||
@ -222,30 +231,23 @@ function updateAngularCLIJson(options: Schema): Rule {
|
|||||||
testConfig.options = {
|
testConfig.options = {
|
||||||
...testConfig.options,
|
...testConfig.options,
|
||||||
main: convertPath(options.name, testConfig.options.main),
|
main: convertPath(options.name, testConfig.options.main),
|
||||||
polyfills: convertPath(options.name, testConfig.options.polyfills),
|
|
||||||
tsConfig: path.join(app.root, getFilename(testConfig.options.tsConfig)),
|
tsConfig: path.join(app.root, getFilename(testConfig.options.tsConfig)),
|
||||||
karmaConfig: path.join(
|
karmaConfig: path.join(
|
||||||
app.root,
|
app.root,
|
||||||
getFilename(testConfig.options.karmaConfig)
|
getFilename(testConfig.options.karmaConfig)
|
||||||
),
|
),
|
||||||
assets: testConfig.options.assets.map(
|
polyfills:
|
||||||
asset =>
|
testConfig.options.polyfills &&
|
||||||
asset.startsWith(oldSourceRoot)
|
convertPath(options.name, testConfig.options.polyfills),
|
||||||
? convertPath(options.name, asset)
|
assets:
|
||||||
: asset
|
testConfig.options.assets &&
|
||||||
),
|
testConfig.options.assets.map(convertAsset),
|
||||||
styles: testConfig.options.styles.map(
|
styles:
|
||||||
style =>
|
testConfig.options.styles &&
|
||||||
style.startsWith(oldSourceRoot)
|
testConfig.options.styles.map(convertAsset),
|
||||||
? convertPath(options.name, style)
|
scripts:
|
||||||
: style
|
testConfig.options.scripts &&
|
||||||
),
|
testConfig.options.scripts.map(convertAsset)
|
||||||
scripts: testConfig.options.scripts.map(
|
|
||||||
script =>
|
|
||||||
script.startsWith(oldSourceRoot)
|
|
||||||
? convertPath(options.name, script)
|
|
||||||
: script
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const lintConfig = app.architect.lint;
|
const lintConfig = app.architect.lint;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user