-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6170f35
commit afa8343
Showing
10 changed files
with
221 additions
and
26 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
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 |
---|---|---|
@@ -1,21 +1,34 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const index = fs.readFileSync(path.join(__dirname, 'src/index.ts'), { | ||
encoding: 'utf-8', | ||
}); | ||
fs.writeFileSync( | ||
path.join(__dirname, '../../dist/libs/mf/src/index.js'), | ||
index | ||
); | ||
|
||
const nguniversal = fs.readFileSync( | ||
path.join(__dirname, 'src/nguniversal.ts'), | ||
// const index = fs.readFileSync(path.join(__dirname, 'src/index.ts'), { | ||
// encoding: 'utf-8', | ||
// }); | ||
// fs.writeFileSync( | ||
// path.join(__dirname, '../../dist/libs/mf/src/index.js'), | ||
// index | ||
// ); | ||
|
||
// const nguniversal = fs.readFileSync( | ||
// path.join(__dirname, 'src/nguniversal.ts'), | ||
// { | ||
// encoding: 'utf-8', | ||
// } | ||
// ); | ||
// fs.writeFileSync( | ||
// path.join(__dirname, '../../dist/libs/mf/src/nguniversal.js'), | ||
// nguniversal | ||
// ); | ||
|
||
|
||
const webpack2 = fs.readFileSync( | ||
path.join(__dirname, 'webpack.ts'), | ||
{ | ||
encoding: 'utf-8', | ||
} | ||
); | ||
fs.writeFileSync( | ||
path.join(__dirname, '../../dist/libs/mf/src/nguniversal.js'), | ||
nguniversal | ||
); | ||
path.join(__dirname, '../../dist/libs/mf/webpack.js'), | ||
'module.exports = require("./src/webpack.js");' | ||
); |
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,3 @@ | ||
export interface RemoveSchema { | ||
project: string; | ||
} |
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,13 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "mf", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "The project to add module federation", | ||
"x-prompt": "Project name (press enter for default project)" | ||
} | ||
} | ||
} |
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,98 @@ | ||
import path = require('path'); | ||
import { noop } from 'rxjs'; | ||
import { getWorkspaceFileName } from '../mf/schematic'; | ||
import { Rule, Tree } from '@angular-devkit/schematics'; | ||
import { RemoveSchema } from './schema'; | ||
|
||
export default function remove(options: RemoveSchema): Rule { | ||
return async function (tree: Tree) { | ||
const workspaceFileName = getWorkspaceFileName(tree); | ||
const workspace = JSON.parse(tree.read(workspaceFileName).toString('utf8')); | ||
const normalized = normalize(options, workspace); | ||
|
||
removeBootstrap(normalized, tree); | ||
|
||
updateBuildConfig(normalized); | ||
updateServeConfig(normalized); | ||
|
||
tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, 2)); | ||
|
||
return noop(); | ||
}; | ||
} | ||
|
||
function updateBuildConfig(normalized: { projectConfig: any; projectName: string; }) { | ||
const build = normalized.projectConfig.architect.build; | ||
build.builder = '@angular-devkit/build-angular:browser'; | ||
delete build.options.extraWebpackConfig; | ||
const buildProd = build.configurations.production; | ||
delete buildProd.extraWebpackConfig; | ||
} | ||
|
||
function updateServeConfig(normalized: { projectConfig: any; projectName: string; }) { | ||
const serve = normalized.projectConfig.architect.serve; | ||
serve.builder = '@angular-devkit/build-angular:dev-server'; | ||
delete serve.options.extraWebpackConfig; | ||
|
||
const serveProd = serve.configurations.production; | ||
delete serveProd.extraWebpackConfig; | ||
|
||
const prodTarget = serveProd.browserTarget; | ||
if (prodTarget) { | ||
delete serveProd.browserTarget; | ||
serveProd.buildTarget = prodTarget; | ||
} | ||
|
||
const serveDev = serve.configurations.development; | ||
const devTarget = serveDev.browserTarget; | ||
|
||
if (devTarget) { | ||
delete serveDev.browserTarget; | ||
serveDev.buildTarget = devTarget; | ||
} | ||
|
||
} | ||
|
||
function normalize(options: RemoveSchema, workspace: any) { | ||
|
||
if (!options.project) { | ||
options.project = workspace.defaultProject; | ||
} | ||
|
||
if (!options.project && Object.keys(workspace.projects).length > 0) { | ||
options.project = Object.keys(workspace.projects)[0]; | ||
} | ||
|
||
if (!options.project) { | ||
throw new Error( | ||
`No default project found. Please specifiy a project name!` | ||
); | ||
} | ||
|
||
const projectName = options.project; | ||
const projectConfig = workspace.projects[projectName]; | ||
|
||
if (!projectConfig?.architect?.build?.options?.main) { | ||
throw new Error( | ||
`architect.build.options.main not found for project ` + projectName | ||
); | ||
} | ||
return { projectConfig, projectName }; | ||
} | ||
|
||
function removeBootstrap(normalized, tree) { | ||
const currentMain = normalized.projectConfig.architect.build.options.main; | ||
|
||
const mainPath = path | ||
.join(path.dirname(currentMain), 'main.ts') | ||
.replace(/\\/g, '/'); | ||
|
||
const bootstrapPath = path | ||
.join(path.dirname(currentMain), 'bootstrap.ts') | ||
.replace(/\\/g, '/'); | ||
|
||
const content = tree.readText(bootstrapPath); | ||
tree.overwrite(mainPath, content); | ||
tree.delete(bootstrapPath); | ||
} | ||
|