Rebasing issues resolved

This commit is contained in:
mrmeku 2018-03-15 19:54:46 -07:00 committed by Victor Savkin
parent de138bb26c
commit 4184bb2d13
51 changed files with 9567 additions and 940 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ dist
build
.DS_Store
tmp
yarn-error
.ng_pkg_build

View File

@ -1,4 +1,11 @@
import { newApp, newLib, newProject, runCLI, updateFile } from '../utils';
import {
newApp,
newLib,
newProject,
runCLI,
updateFile,
cleanup
} from '../utils';
describe('Nrwl Workspace', () => {
it(

View File

@ -20,3 +20,132 @@ xdescribe('Nrwl Workspace (Bazel)', () => {
1000000
);
});
// afterEach(() => {
// runCommand('bazel build ...');
// });
// itShould('create a bazel project', () => {
// newBazelProject();
// checkFilesExist('WORKSPACE', 'BUILD.bazel');
// });
// itShould('create an app', () => {
// newApp('myApp --directory=myDir');
// });
// itShould('create a lib', () => {
// newLib('myLib --directory=myDir');
// runCommand('bazel test //libs/my-dir/my-lib/src:test');
// });
// itShould('allow adding a lib to a module', () => {
// updateFile(
// 'apps/my-dir/my-app/src/app/app.module.ts',
// `import { NgModule } from '@angular/core';
// import { BrowserModule } from '@angular/platform-browser';
// import { MyLibModule } from 'proj/libs/my-dir/my-lib/src/my-lib.module';
// import { AppComponent } from './app.component';
// import { StoreModule } from '@ngrx/store';
// import { NxModule } from '@nrwl/nx';
// @NgModule({
// imports: [BrowserModule, MyLibModule, StoreModule.forRoot({}),
// NxModule.forRoot()], declarations: [AppComponent], bootstrap: [AppComponent]
// })
// export class AppModule {}
// `);
// // TODO: Replace this with a buildozer command to add the lib as a dep.
// updateFile('apps/my-dir/my-app/src/app/BUILD.bazel', `
// package(default_visibility = ["//visibility:public"])
// load("@angular//:index.bzl", "ng_module")
// ng_module(
// name = "app",
// srcs = glob(
// ["*.ts"],
// exclude = ["*.spec.ts"],
// ),
// assets = [
// "app.component.css",
// "app.component.html",
// ],
// deps = [
// "//libs/my-dir/my-lib/src",
// "@rxjs",
// ],
// )
// `);
// });
// itShould('add a module', () => {
// newModule('helloWorld --directory=myDir');
// });
// itShould('run protractor', () => {
// const prodServerPort = 8080;
// headlessProtractorConfig(prodServerPort);
// runCommand([
// 'node', 'node_modules/concurrently/src/main.js',
// '"bazel run //apps/my-dir/my-app/src:prodserver"',
// `"while ! nc -z 127.0.0.1 ${prodServerPort}; do sleep 1; done && ng
// e2e -s=false --app=my-dir/my-app"`,
// '--kill-others', '--success', 'first'
// ].join(' '));
// const devServerPort = 5432;
// headlessProtractorConfig(devServerPort);
// runCommand([
// 'node', 'node_modules/concurrently/src/main.js',
// '"bazel run //apps/my-dir/my-app/src:devserver"',
// `"while ! nc -z 127.0.0.1 ${devServerPort}; do sleep 1; done && ng
// e2e -s=false --app=my-dir/my-app"`,
// '--kill-others', '--success', 'first'
// ].join(' '));
// });
// });
// function headlessProtractorConfig(port: number): void {
// return updateFile(
// 'protractor.conf.js',
// `const { SpecReporter } = require('jasmine-spec-reporter');
// const { getAppDirectoryUsingCliConfig } =
// require('@nrwl/schematics/src/utils/cli-config-utils'); const appDir =
// getAppDirectoryUsingCliConfig();
// exports.config = {
// allScriptsTimeout: 11000,
// specs: [
// appDir + '/e2e/**/*.e2e-spec.ts'
// ],
// multiCapabilities: {
// 'browserName': 'chrome',
// chromeOptions: {
// args: [
// '--headless',
// '--disable-gpu',
// '--window-size=1280x720',
// ],
// },
// },
// directConnect: true,
// baseUrl: 'http://localhost:${port}/',
// framework: 'jasmine',
// jasmineNodeOpts: {
// showColors: true,
// defaultTimeoutInterval: 30000,
// print: function() {}
// },
// onPrepare() {
// require('ts-node').register({
// project: appDir + '/e2e/tsconfig.e2e.json'
// });
// jasmine.getEnv().addReporter(new SpecReporter({ spec: {
// displayStacktrace: true } }));
// }
// };`);
// }

View File

@ -14,7 +14,7 @@ export function runNgNew(command?: string, silent?: boolean): string {
export function newProject(): void {
cleanup();
if (!directoryExists('./tmp/proj_backup')) {
//TODO delete the try catch after 0.8.0 is released
// TODO delete the try catch after 0.8.0 is released
try {
runNgNew('--collection=@nrwl/schematics --npmScope=proj', true);
} catch (e) {}
@ -27,8 +27,8 @@ export function newProject(): void {
export function newBazelProject(): void {
cleanup();
if (!directoryExists('./tmp/proj_backup')) {
//TODO delete the try catch after 0.8.0 is released
if (!directoryExists('./tmp/proj_bazel_backup')) {
// TODO delete the try catch after 0.8.0 is released
try {
runNgNew('--collection=@nrwl/bazel --npmScope=proj', true);
} catch (e) {}
@ -36,16 +36,14 @@ export function newBazelProject(): void {
execSync('npm run postinstall', { cwd: './tmp/proj' });
execSync('mv ./tmp/proj ./tmp/proj_backup');
}
execSync('cp -a ./tmp/proj_backup ./tmp/proj');
execSync('cp -a ./tmp/proj_bazel_backup ./tmp/proj');
}
export function createNxWorkspace(command: string): string {
cleanup();
return execSync(
`node ../node_modules/@nrwl/schematics/bin/create-nx-workspace.js ${command}`,
{
cwd: `./tmp`
}
`node ../node_modules/@nrwl/schematics/bin/create-nx-workspace.js --yarn ${command}`,
{ cwd: `./tmp` }
).toString();
}
@ -98,6 +96,10 @@ export function newLib(name: string): string {
return runCLI(`generate lib ${name}`);
}
export function newModule(name: string): string {
return runCLI(`generate module ${name}`);
}
export function runSchematic(command: string): string {
return execSync(`./node_modules/.bin/schematics ${command}`, {
cwd: `./tmp/${projectName}`
@ -132,6 +134,10 @@ export function cleanup() {
execSync('rm -rf ./tmp/proj');
}
export function purge() {
execSync('rm -rf ./tmp');
}
export function getCwd(): string {
return process.cwd();
}

View File

@ -5,7 +5,7 @@
"main": "index.js",
"private": true,
"scripts": {
"build": "./scripts/build.sh",
"build": "ng-packagr -p packages/nx/ng-package.json && ./scripts/build.sh",
"e2e": "./scripts/e2e.sh",
"format": "precise-commits --whitelist=\"{packages,e2e}/**/*.ts\"",
"linknpm": "./scripts/link.sh",
@ -13,8 +13,9 @@
"release": "./scripts/release.sh",
"copy": "./scripts/copy.sh",
"test:schematics": "yarn linknpm && ./scripts/test_schematics.sh",
"test:nx": "yarn linknpm && ./scripts/test_nx.sh",
"test": "yarn linknpm && ./scripts/test_nx.sh && ./scripts/test_schematics.sh",
"test:nx": "./scripts/link-spec.sh && ./scripts/test_nx.sh",
"test":
"./scripts/link-spec.sh && ./scripts/test_nx.sh && ./scripts/test_schematics.sh",
"checkformat": "echo 1",
"publish_npm": "./scripts/publish.sh",
"precommit": "yarn checkformat"
@ -32,10 +33,10 @@
"@angular/platform-browser-dynamic": "5.2.7",
"@angular/router": "5.2.7",
"@angular/upgrade": "5.2.7",
"@ngrx/effects": "5.1.0",
"@ngrx/router-store": "5.0.1",
"@ngrx/store": "5.1.0",
"@ngrx/store-devtools": "5.1.0",
"@ngrx/effects": "5.2.0",
"@ngrx/router-store": "5.2.0",
"@ngrx/store": "5.2.0",
"@ngrx/store-devtools": "5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
@ -43,6 +44,7 @@
"angular": "1.6.6",
"app-root-path": "^2.0.1",
"cosmiconfig": "^4.0.0",
"ng-packagr": "2.2.0",
"husky": "^0.14.3",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
@ -64,9 +66,6 @@
"author": "Victor Savkin",
"license": "MIT",
"jest": {
"modulePathIgnorePatterns": [
"tmp",
"files"
]
"modulePathIgnorePatterns": ["tmp", "files"]
}
}

41
packages/bazel/README.md Normal file
View File

@ -0,0 +1,41 @@
Bazel Commands
## Add new app
node_modules/.bin/ng generate app [name]
Example: node_modules/.bin/ng generate app test
## Add new component
node_modules/.bin/ng generate component [name] --directory=[dir]
Example: node_modules/.bin/ng generate component friends --directory=myDir
* must manually import the component's Bazel rule in the consuming Bazel rule
## Add new lib
node_modules/.bin/ng generate lib [name]
Example: node_modules/.bin/ng generate lib mylib
* must manually import the lib's Bazel rule in the consuming Bazel rule
## Run dev server
ibazel run apps/[app specific path]]/src:devserver (anything between apps/\*\*/src points to a specific app)
Example: ibazel run apps/my-dir/my-app/src:devserver
## Run prod server
bazel run apps/[app specific path]]/src:prodserver (anything between apps/\*\*/src points to a specific app)
Example: bazel run apps/my-dir/my-app/src:prodserver
## Run unit tests
ibazel test //libs/mylib/src:test
* currently works for libs

View File

@ -11,6 +11,19 @@
"factory": "./collection/app",
"schema": "./collection/app/schema.json",
"description": "Create an application."
},
"lib": {
"factory": "./collection/lib",
"schema": "./collection/lib/schema.json",
"description": "Create a library"
},
"module": {
"aliases": [
"m"
],
"factory": "./collection/module",
"schema": "./collection/module/schema.json",
"description": "Create a Module"
}
}
}
}

View File

@ -1,236 +0,0 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '../../../../schematics/src/utils/testing-utils';
import { getFileContent } from '@schematics/angular/utility/test';
import * as stripJsonComments from 'strip-json-comments';
describe('app', () => {
const schematicRunner = new SchematicTestRunner(
'@nrwl/bazel',
path.join(__dirname, '../../collection.json')
);
let appTree: Tree;
beforeEach(() => {
appTree = new VirtualTree();
appTree = createEmptyWorkspace(appTree);
});
describe('not nested', () => {
it('should update angular-cli.json', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl' },
appTree
);
const updatedAngularCLIJson = JSON.parse(
getFileContent(tree, '/.angular-cli.json')
);
expect(updatedAngularCLIJson.apps).toEqual([
{
assets: ['assets', 'favicon.ico'],
environmentSource: 'environments/environment.ts',
environments: {
dev: 'environments/environment.ts',
prod: 'environments/environment.prod.ts'
},
index: 'index.html',
main: 'main.ts',
name: 'my-app',
outDir: 'dist/apps/my-app',
polyfills: 'polyfills.ts',
prefix: 'app',
root: 'apps/my-app/src',
scripts: [],
styles: ['styles.css'],
test: '../../../test.js',
testTsconfig: '../../../tsconfig.spec.json',
tsconfig: 'tsconfig.app.json'
}
]);
expect(updatedAngularCLIJson.lint).toEqual([
{
project: `apps/my-app/src/tsconfig.app.json`,
exclude: '**/node_modules/**'
},
{
project: `apps/my-app/e2e/tsconfig.e2e.json`,
exclude: '**/node_modules/**'
}
]);
});
it('should generate files', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl' },
appTree
);
expect(tree.exists('apps/my-app/src/main.ts')).toBeTruthy();
expect(tree.exists('apps/my-app/src/app/app.module.ts')).toBeTruthy();
expect(tree.exists('apps/my-app/src/app/app.component.ts')).toBeTruthy();
expect(tree.exists('apps/my-app/e2e/app.po.ts')).toBeTruthy();
expect(
getFileContent(tree, 'apps/my-app/src/app/app.module.ts')
).toContain('class AppModule');
const tsconfigApp = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-app/src/tsconfig.app.json')
)
);
expect(tsconfigApp.compilerOptions.outDir).toEqual(
'../../../dist/out-tsc/apps/my-app'
);
const tsconfigE2E = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-app/e2e/tsconfig.e2e.json')
)
);
expect(tsconfigE2E.compilerOptions.outDir).toEqual(
'../../../dist/out-tsc/e2e/my-app'
);
});
});
describe('nested', () => {
it('should update angular-cli.json', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl', directory: 'myDir' },
appTree
);
const updatedAngularCLIJson = JSON.parse(
getFileContent(tree, '/.angular-cli.json')
);
expect(updatedAngularCLIJson.apps).toEqual([
{
assets: ['assets', 'favicon.ico'],
environmentSource: 'environments/environment.ts',
environments: {
dev: 'environments/environment.ts',
prod: 'environments/environment.prod.ts'
},
index: 'index.html',
main: 'main.ts',
name: 'my-dir/my-app',
outDir: 'dist/apps/my-dir/my-app',
polyfills: 'polyfills.ts',
prefix: 'app',
root: 'apps/my-dir/my-app/src',
scripts: [],
styles: ['styles.css'],
test: '../../../../test.js',
testTsconfig: '../../../../tsconfig.spec.json',
tsconfig: 'tsconfig.app.json'
}
]);
expect(updatedAngularCLIJson.lint).toEqual([
{
project: `apps/my-dir/my-app/src/tsconfig.app.json`,
exclude: '**/node_modules/**'
},
{
project: `apps/my-dir/my-app/e2e/tsconfig.e2e.json`,
exclude: '**/node_modules/**'
}
]);
});
it('should generate files', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl', directory: 'myDir' },
appTree
);
expect(tree.exists('apps/my-dir/my-app/src/main.ts')).toBeTruthy();
expect(
tree.exists('apps/my-dir/my-app/src/app/app.module.ts')
).toBeTruthy();
expect(
tree.exists('apps/my-dir/my-app/src/app/app.component.ts')
).toBeTruthy();
expect(tree.exists('apps/my-dir/my-app/e2e/app.po.ts')).toBeTruthy();
expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')
).toContain('class AppModule');
const tsconfigApp = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-dir/my-app/src/tsconfig.app.json')
)
);
expect(tsconfigApp.compilerOptions.outDir).toEqual(
'../../../../dist/out-tsc/apps/my-dir/my-app'
);
const tsconfigE2E = JSON.parse(
stripJsonComments(
getFileContent(tree, 'apps/my-dir/my-app/e2e/tsconfig.e2e.json')
)
);
expect(tsconfigE2E.compilerOptions.outDir).toEqual(
'../../../../dist/out-tsc/e2e/my-dir/my-app'
);
});
});
it('should import NgModule', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl', directory: 'myDir' },
appTree
);
expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')
).toContain('NxModule.forRoot()');
});
describe('routing', () => {
it('should include RouterTestingModule', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl', directory: 'myDir', routing: true },
appTree
);
expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.module.ts')
).toContain('RouterModule.forRoot');
expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.spec.ts')
).toContain('imports: [RouterTestingModule]');
});
});
describe('view encapsulation', () => {
it('should not set Component encapsulation metadata if option flag not included', () => {
const tree = schematicRunner.runSchematic(
'app',
{ name: 'myApp', npmScope: 'nrwl', directory: 'myDir' },
appTree
);
expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts')
).not.toContain('encapsulation: ');
});
it('should set Component encapsulation metadata if option flag is included', () => {
const tree = schematicRunner.runSchematic(
'app',
{
name: 'myApp',
npmScope: 'nrwl',
directory: 'myDir',
viewEncapsulation: 'Native'
},
appTree
);
expect(
getFileContent(tree, 'apps/my-dir/my-app/src/app/app.component.ts')
).toContain('encapsulation: ViewEncapsulation.Native');
});
});
});

View File

@ -0,0 +1,57 @@
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
package(default_visibility = ["//visibility:public"])
ng_module(
name = "<%= sourceDir %>",
srcs = glob(["main.ts"]),
deps = [
"//apps/<%= fullName %>/src/app",
"@rxjs",
],
)
# Needed because the devserver only loads static files that appear under this
# package.
genrule(
name = "zone.js",
srcs = ["//:node_modules/zone.js/dist/zone.min.js"],
outs = ["zone.min.js"],
cmd = "cp $< $@",
)
STATIC_FILES = [
"favicon.ico",
"index.html",
"styles.css",
":zone.js",
]
ts_devserver(
name = "devserver",
data = ["//apps/<%= fullName %>/src/assets"],
entry_module = "proj/apps/<%= fullName %>/src/main",
scripts = ["//:angular_bundles"],
serving_path = "/bundle.min.js",
static_files = STATIC_FILES,
deps = [":<%= sourceDir %>"],
)
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "nodejs_binary")
rollup_bundle(
name = "bundle",
entry_point = "proj/apps/<%= fullName %>/src/main",
deps = [":<%= sourceDir %>"],
)
nodejs_binary(
name = "prodserver",
args = ["./apps/<%= fullName %>/src"],
data = STATIC_FILES + [
":bundle",
"//apps/<%= fullName %>/src/assets",
],
entry_point = "http-server/bin/http-server",
)

View File

@ -0,0 +1,6 @@
package(default_visibility = ["//visibility:public"])
filegroup(
name = "assets",
srcs = glob(["*"]),
)

View File

@ -1,3 +0,0 @@
export const environment = {
production: true
};

View File

@ -1,8 +0,0 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = {
production: false
};

View File

@ -4,11 +4,14 @@
<meta charset="utf-8">
<title><%= utils.classify(name) %></title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<<%= prefix %>-root></<%= prefix %>-root>
<script src="/zone.min.js"></script>
<script src="/bundle.min.js"></script>
</body>
</html>

View File

@ -1,12 +1,7 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { platformBrowser } from '@angular/platform-browser';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import {AppModuleNgFactory} from './app/app.module.ngfactory';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory)
.catch(err => console.log(err));

View File

@ -134,6 +134,7 @@ function addAppToAngularCliJson(options: NormalizedSchema): Rule {
function addRouterRootConfiguration(path: string): Rule {
return (host: Tree) => {
const modulePath = `${path}/app/app.module.ts`;
console.log(modulePath);
const moduleSource = host.read(modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(
modulePath,
@ -202,6 +203,52 @@ function updateComponentTemplate(options: NormalizedSchema): Rule {
};
}
function addBazelBuildFile(path: string): Rule {
return (host: Tree) => {
const ngModule = `package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "app",
srcs = glob(
["*.ts"],
exclude = ["*.spec.ts"],
),
assets = [
"app.component.css",
"app.component.html",
],
deps = [
"@rxjs",
],
)
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["*.spec.ts"]),
deps = [
":app",
],
)
ts_web_test(
name = "test",
bootstrap = ["//:angular_bootstrap_scripts"],
deps = [
":test_lib",
"//:angular_bundles",
"//:angular_test_bundles",
],
)
`;
const sourceFile = host.create(`${path}/app/BUILD.bazel`, ngModule);
};
}
export default function(schema: Schema): Rule {
return wrapIntoFormat(() => {
let npmScope = schema.npmScope;
@ -249,6 +296,8 @@ export default function(schema: Schema): Rule {
addBootstrap(options.fullPath),
addNxModule(options.fullPath),
addAppToAngularCliJson(options),
addBazelBuildFile(options.fullPath),
addAppToAngularCliJson(options),
options.routing ? addRouterRootConfiguration(options.fullPath) : noop()
]);
});

View File

@ -31,9 +31,11 @@ describe('application', () => {
'/my-app/apps/.gitkeep',
'/my-app/karma.conf.js',
'/my-app/libs/.gitkeep',
'/my-app/ngc.tsconfig.json',
'/my-app/package.json',
'/my-app/protractor.conf.js',
'/my-app/test.js',
'/my-app/tools/bazel.rc',
'/my-app/tsconfig.json',
'/my-app/tsconfig.spec.json',
'/my-app/tslint.json'
@ -57,24 +59,4 @@ describe('application', () => {
expect(packageJson.dependencies['@ngrx/router-store']).toBeDefined();
expect(packageJson.dependencies['@ngrx/store-devtools']).toBeDefined();
});
it('should set right npmScope', () => {
const tree = schematicRunner.runSchematic(
'application',
{ name: 'myApp', directory: 'my-app' },
appTree
);
const angularCliJson = JSON.parse(
getFileContent(tree, '/my-app/.angular-cli.json')
);
expect(angularCliJson.project.npmScope).toEqual('myApp');
const tsconfigJson = JSON.parse(
getFileContent(tree, '/my-app/tsconfig.json')
);
expect(tsconfigJson.compilerOptions.paths).toEqual({
'@myApp/*': ['libs/*']
});
});
});

View File

@ -0,0 +1,81 @@
package(default_visibility = ["//visibility:public"])
exports_files(["tsconfig.json"])
# NOTE: this will move to node_modules/BUILD in a later release
filegroup(
name = "node_modules",
# NB: rxjs is not in this list, because we build it from sources using the
# label @rxjs//:rxjs
srcs = glob(["/".join([
"node_modules",
pkg,
"**",
ext,
]) for pkg in [
"@angular",
"@nrwl",
"@ngrx",
"tsickle",
"tsutils",
"typescript",
"@types",
] for ext in [
"*.js",
"*.json",
"*.d.ts",
]] + [
"node_modules/http-server/**",
]),
)
ANGULAR_TESTING = [
"node_modules/@angular/*/bundles/*-testing.umd.js",
# We use AOT, so the compiler and the dynamic platform-browser should be
# visible only in tests
"node_modules/@angular/compiler/bundles/*.umd.js",
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
]
# TODO: it's messy for users to need to specify the following
# Angular dependency lists. It should live somewhere else.
# See https://github.com/angular/angular/issues/21048
filegroup(
name = "angular_bundles",
srcs = glob(
[
"node_modules/@angular/*/bundles/*.umd.js",
"node_modules/@ngrx/store/bundles/store.umd.js",
"node_modules/@ngrx/router-store/bundles/router-store.umd.js",
"node_modules/@ngrx/effects/bundles/effects.umd.js",
"node_modules/@nrwl/nx/bundles/nrwl-nx.umd.js",
],
exclude = ANGULAR_TESTING + [
"node_modules/@angular/bazel/**/*",
"node_modules/@angular/cli/**/*",
"node_modules/@angular/compiler-cli/**/*",
"node_modules/@angular/language-service/**/*",
],
),
)
filegroup(
name = "angular_test_bundles",
testonly = 1,
srcs = glob(ANGULAR_TESTING),
)
filegroup(
name = "angular_bootstrap_scripts",
# do not sort
srcs = [
"//:node_modules/zone.js/dist/zone.min.js",
"//:node_modules/zone.js/dist/async-test.js",
"//:node_modules/zone.js/dist/sync-test.js",
"//:node_modules/zone.js/dist/proxy.min.js",
"//:node_modules/zone.js/dist/jasmine-patch.js",
],
)

View File

@ -0,0 +1,74 @@
workspace(name = "<%= name %>")
####################################
# The Bazel buildtools repo contains tools like the BUILD file formatter, buildifier
http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "4d8d6244320dd751590f9100cf39fd7a4b75cd901e1f3ffdfd6f048328883695",
# Note, this commit matches the version of buildifier in angular/ngcontainer
url = "https://github.com/bazelbuild/buildtools/archive/b3b620e8bcff18ed3378cd3f35ebeb7016d71f71.zip",
)
####################################
# Fetch and install the NodeJS rules
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "e9bc013417272b17f302dc169ad597f05561bb277451f010043f4da493417607",
strip_prefix = "rules_nodejs-0.4.1",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.4.1.zip",
)
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
node_repositories(package_json = ["//:package.json"])
####################################
# Fetch and install the Sass rules
git_repository(
name = "io_bazel_rules_sass",
remote = "https://github.com/bazelbuild/rules_sass.git",
tag = "0.0.3",
)
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")
sass_repositories()
####################################
# Fetch and install the TypeScript rules
http_archive(
name = "build_bazel_rules_typescript",
sha256 = "a2c81776a4a492ff9f878f9705639f5647bef345f7f3e1da09c9eeb8dec80485",
strip_prefix = "rules_typescript-0.10.1",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.10.1.zip",
)
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
ts_setup_workspace()
# Some of the TypeScript is written in Go.
# Bazel doesn't support transitive WORKSPACE deps, so we must repeat them here.
http_archive(
name = "io_bazel_rules_go",
sha256 = "4b14d8dd31c6dbaf3ff871adcd03f28c3274e42abc855cb8fb4d01233c0154dc",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.1/rules_go-0.10.1.tar.gz",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
####################################
# Tell Bazel about some workspaces that were installed from npm.
local_repository(
name = "angular",
path = "node_modules/@angular/bazel",
)
local_repository(
name = "rxjs",
path = "node_modules/rxjs/src",
)

View File

@ -30,7 +30,7 @@
],
"defaults": {
"schematics": {
"collection": "@nrwl/schematics"
"collection": "@nrwl/bazel"
},
"styleExt": "<%= style %>",<% if (!minimal) { %>
"component": {}<% } else { %>

View File

@ -0,0 +1,27 @@
// WORKAROUND https://github.com/angular/angular/issues/18810
// This file is required to run ngc on angular libraries, to write files like
// node_modules/@angular/core/core.ngsummary.json
{
"compilerOptions": {
"lib": [
"dom",
"es2015"
],
"experimentalDecorators": true,
"types": []
},
"include": [
"node_modules/@angular/**/*",
"node_modules/@nrwl/**/*",
"node_modules/@ngrx/**/*",
],
"exclude": [
"node_modules/@angular/bazel/**",
"node_modules/@angular/router/**",
"node_modules/@angular/cli/**",
"node_modules/@angular/compiler-cli/**",
"node_modules/@angular/tsc-wrapped/**",
"node_modules/@nrwl/bazel/**",
"node_modules/@nrwl/schematics/**",
]
}

View File

@ -9,24 +9,21 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"affected:apps": "./node_modules/.bin/nx affected apps",
"affected:build": "./node_modules/.bin/nx affected build",
"affected:e2e": "./node_modules/.bin/nx affected e2e",
"format": "./node_modules/.bin/nx format write",
"format:write": "./node_modules/.bin/nx format write",
"format:check": "./node_modules/.bin/nx format check",
"update": "./node_modules/.bin/nx update",
"update:check": "./node_modules/.bin/nx update check",
"update:skip": "./node_modules/.bin/nx update skip",
"postinstall": "./node_modules/.bin/nx postinstall"
"postinstall": "ngc -p ngc.tsconfig.json"
},
"private": true,
"dependencies": {
"@angular/animations": "<%= angularVersion %>",
"@angular/bazel": "angular/bazel-builds#d09df98b39658463fdfe3567b25a20cdd7130661",
"@angular/common": "<%= angularVersion %>",
"@angular/compiler": "<%= angularVersion %>",
"@angular/core": "<%= angularVersion %>",
@ -34,35 +31,39 @@
"@angular/platform-browser": "<%= angularVersion %>",
"@angular/platform-browser-dynamic": "<%= angularVersion %>",
"@angular/router": "<%= angularVersion %>",
"concurrently": "3.5.1",
"core-js": "^2.4.1",
"rxjs": "<%= rxjsVersion %>",
"zone.js": "^0.8.19",
"@nrwl/nx": "<%= nxVersion %>",
"@ngrx/effects": "<%= ngrxVersion %>",
"@ngrx/router-store": "<%= routerStoreVersion %>",
"@ngrx/store": "<%= ngrxVersion %>",
"@ngrx/store-devtools": "<%= ngrxVersion %>"
"@ngrx/effects": "5.2.0",
"@ngrx/router-store": "5.2.0",
"@ngrx/store": "5.2.0",
"@ngrx/store-devtools": "5.2.0"
},
"devDependencies": {
"@angular/cli": "<%= angularCliVersion %>",
"@angular/compiler-cli": "<%= angularVersion %>",
"@nrwl/schematics": "<%= schematicsVersion %>",
"@angular/language-service": "<%= angularVersion %>",<% if (!minimal) { %>
"@angular/language-service": "<%= angularVersion %>",
"@bazel/ibazel": "^0.3.1",<% if (!minimal) { %>
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",<% } %>
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",<%
} %>
"typescript": "<%= typescriptVersion %>",
"prettier": "<%= prettierVersion %>"
"prettier": "<%= prettierVersion %>",
"http-server": "0.11.1"
}
}

View File

@ -14,7 +14,7 @@ exports.config = {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
baseUrl: 'http://localhost:8080/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,

View File

@ -0,0 +1,19 @@
# Make TypeScript compilation fast, by keeping a few copies of the compiler
# running as daemons, and cache SourceFile AST's to reduce parse time.
build --strategy=TypeScriptCompile=worker
# Don't create bazel-* symlinks in the WORKSPACE directory.
# These require .gitignore and may scare users.
# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12
# which affects the common case of having `tsconfig.json` in the WORKSPACE directory.
#
# Instead, you should run `bazel info bazel-bin` to find out where the outputs went.
build --symlink_prefix=dist/
test --test_output=errors
# Workaround https://github.com/bazelbuild/bazel/issues/3645
# Limit Bazel to consuming 3072K of RAM
build:ci --local_resources=3072,2.0,1.0
build:ci --noshow_progress

View File

@ -7,22 +7,9 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"baseUrl": ".",
"paths": {
"@<%= npmScope %>/*": [
"libs/*"
]
}
},
"exclude": [
"node_modules",
"tmp"
]
}
}
}

View File

@ -0,0 +1,35 @@
# TODO: Make this private when we can import from the root index.ts
package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "<%= sourceDir %>",
srcs = glob(
["*.ts"],
exclude = ["*.spec.ts"],
),
deps = [
"@rxjs",
],
)
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["*.spec.ts"]),
deps = [
":<%= sourceDir %>",
],
)
ts_web_test(
name = "test",
bootstrap = ["//:angular_bootstrap_scripts"],
deps = [
":test_lib",
"//:angular_bundles",
"//:angular_test_bundles",
],
)

View File

@ -0,0 +1,7 @@
import { <%= className %> } from './<%=fileName%>';
describe('<%= className %>', () => {
it('should work', () => {
expect(new <%= className %>()).toBeDefined();
});
});

View File

@ -0,0 +1,2 @@
export class <%= className %> {
}

View File

@ -0,0 +1,15 @@
import {branchAndMerge, chain, mergeWith, Rule,} from '@angular-devkit/schematics';
import {validateLibSchema} from '../../../../schematics/src/collection/lib';
import {wrapIntoFormat} from '../../../../schematics/src/utils/tasks';
import {Schema} from './schema';
export default function(schema: Schema): Rule {
return wrapIntoFormat(() => {
const {templateSource, routingRules} = validateLibSchema(schema);
return chain(
[branchAndMerge(chain([mergeWith(templateSource)])), ...routingRules]);
});
}

View File

@ -0,0 +1,35 @@
# TODO: Make this private when we can import from the root index.ts
package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "<%= sourceDir %>",
srcs = glob(
["*.ts"],
exclude = ["*.spec.ts"],
),
deps = [
"@rxjs",
],
)
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["*.spec.ts"]),
deps = [
":<%= sourceDir %>",
],
)
ts_web_test(
name = "test",
bootstrap = ["//:angular_bootstrap_scripts"],
deps = [
":test_lib",
"//:angular_bundles",
"//:angular_test_bundles",
],
)

View File

@ -0,0 +1,7 @@
import { <%= className %>Module } from './<%=fileName%>.module';
describe('<%= className %>Module', () => {
it('should work', () => {
expect(new <%= className %>Module()).toBeDefined();
});
});

View File

@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [CommonModule]
})
export class <%= className %>Module {
}

View File

@ -0,0 +1,14 @@
export interface Schema {
name: string;
directory?: string;
sourceDir?: string;
nomodule: boolean;
spec?: boolean;
flat?: boolean;
commonModule?: boolean;
routing?: boolean;
lazy?: boolean;
parentModule?: string;
}

View File

@ -0,0 +1,38 @@
{
"$schema": "http://json-schema.org/schema",
"id": "library",
"title": "Create a library",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Library name"
},
"directory": {
"type": "string",
"description": "A directory where the app is placed"
},
"nomodule": {
"type": "boolean",
"default": false,
"description": "Generate a simple TS library when set to true."
},
"routing": {
"type": "boolean",
"default": false,
"description": "Add router configuration. See lazy for more information."
},
"lazy": {
"type": "boolean",
"default": false,
"description": "Add RouterModule.forChild when set to true, and a simple array of routes when set to false."
},
"parentModule": {
"type": "string",
"description": "Update the router configuration of the parent module using loadChildren or children, depending on what `lazy` is set to."
}
},
"required": [
"name"
]
}

View File

@ -0,0 +1,24 @@
package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ng_module(
name = "<%= dasherize(name) %>",
srcs = glob(
["*.ts"],
exclude = ["*.spec.ts"],
),
deps = [
"@rxjs",
],
)
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["*.spec.ts"]),
deps = [
":<%= dasherize(name) %>",
],
)

View File

@ -0,0 +1,34 @@
import {normalize, strings} from '@angular-devkit/core';
import {apply, branchAndMerge, chain, externalSchematic, mergeWith, move, Rule, SchematicsException, template, url,} from '@angular-devkit/schematics';
import {wrapIntoFormat} from '../../../../schematics/src/utils/tasks';
import {Schema} from './schema';
interface NormalizedSchema extends Schema {
fullName: string;
fullPath: string;
}
export default function(schema: Schema): Rule {
return wrapIntoFormat(() => {
schema.path = schema.path ? normalize(schema.path) : schema.path;
const sourceDir = schema.sourceDir;
if (!sourceDir) {
throw new SchematicsException(`sourceDir option is required.`);
}
const templateSource = apply(url('./files'), [
template({
...strings,
'if-flat': (s: string) => (schema.flat ? '' : s),
...schema
}),
move(sourceDir)
]);
return chain([
branchAndMerge(chain([mergeWith(templateSource)])),
externalSchematic('@schematics/angular', 'module', schema)
]);
});
}

View File

@ -0,0 +1,50 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export interface Schema {
/**
* The name of the module.
*/
name: string;
/**
* The path to create the module.
*/
path?: string;
/**
* The path of the source directory.
*/
sourceDir?: string;
/**
* The root of the application.
*/
appRoot?: string;
/**
* Generates a routing module.
*/
routing?: boolean;
/**
* The scope for the generated routing.
*/
routingScope?: 'Child' | 'Root';
/**
* Specifies if a spec file is generated.
*/
spec?: boolean;
/**
* Flag to indicate if a dir is created.
*/
flat?: boolean;
/**
* Flag to control whether the CommonModule is imported.
*/
commonModule?: boolean;
/**
* Allows specification of the declaring module.
*/
module?: string;
}

View File

@ -0,0 +1,70 @@
{
"$schema": "http://json-schema.org/schema",
"id": "module",
"title": "NX Module Options Schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the module."
},
"path": {
"type": "string",
"format": "path",
"description": "The path to create the module.",
"default": "app",
"visible": false
},
"sourceDir": {
"type": "string",
"format": "path",
"description": "The path of the source directory.",
"default": "src",
"visible": false
},
"appRoot": {
"type": "string",
"format": "path",
"description": "The root of the application.",
"visible": false
},
"routing": {
"type": "boolean",
"description": "Generates a routing module.",
"default": false
},
"routingScope": {
"enum": [
"Child",
"Root"
],
"type": "string",
"description": "The scope for the generated routing.",
"default": "Child"
},
"spec": {
"type": "boolean",
"description": "Specifies if a spec file is generated.",
"default": true
},
"flat": {
"type": "boolean",
"description": "Flag to indicate if a dir is created.",
"default": false
},
"commonModule": {
"type": "boolean",
"description": "Flag to control whether the CommonModule is imported.",
"default": true,
"visible": false
},
"module": {
"type": "string",
"description": "Allows specification of the declaring module.",
"alias": "m"
}
},
"required": [
"name"
]
}

View File

@ -0,0 +1,11 @@
{
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "index.ts",
"umdModuleIds": {
"@ngrx/effects" : "ngrx.effects",
"@ngrx/router-store": "ngrx.routerStore",
"@ngrx/store": "ngrx.store"
}
}
}

View File

@ -2,8 +2,10 @@
"name": "@nrwl/nx",
"version": "0.0.1",
"description": "Nrwl Extensions for Angular",
"main": "index.js",
"types": "index.d.js",
"main": "bundles/nrwl-nx.umd.js",
"types": "nrwl-nx.d.ts",
"module": "esm5/nrwl-nx.js",
"es2015": "esm2015/nrwl-nx.js",
"dependencies": {
"jasmine-marbles": "0.2.0"
},

View File

@ -1,5 +1,5 @@
import { from } from 'rxjs/observable/from';
import { readAll, readFirst } from '../src/testing-utils';
import { readAll, readFirst } from '../testing/src/testing-utils';
describe('TestingUtils', () => {
describe('readAll', () => {

View File

@ -0,0 +1,15 @@
{
"name": "@nrwl/nx/testing",
"typings": "./index.d.ts",
"main": "../bundles/nrwl-nx-testing.umd.js",
"module": "../esm5/nrwl-nx-testing.js",
"es2015": "../esm2015/nrwl-nx-testing.js",
"ngPackage": {
"lib": {
"entryFile": "index.ts",
"umdModuleIds": {
"jasmine-marbles" : "jasmine-marbles"
}
}
}
}

View File

@ -44,6 +44,7 @@ function addBootstrap(path: string): Rule {
const modulePath = `${path}/app/app.module.ts`;
const moduleSource = host.read(modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(
<<<<<<< HEAD
modulePath,
moduleSource,
ts.ScriptTarget.Latest,
@ -63,6 +64,15 @@ function addBootstrap(path: string): Rule {
'AppComponent',
'./app.component'
)
=======
modulePath, moduleSource, ts.ScriptTarget.Latest, true);
insert(host, modulePath, [
insertImport(
sourceFile, modulePath, 'BrowserModule', '@angular/platform-browser'),
...addImportToModule(sourceFile, modulePath, 'BrowserModule'),
...addBootstrapToModule(
sourceFile, modulePath, 'AppComponent', './app.component')
>>>>>>> Rebasing issues resolved
]);
return host;
};
@ -73,11 +83,15 @@ function addNxModule(path: string): Rule {
const modulePath = `${path}/app/app.module.ts`;
const moduleSource = host.read(modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(
<<<<<<< HEAD
modulePath,
moduleSource,
ts.ScriptTarget.Latest,
true
);
=======
modulePath, moduleSource, ts.ScriptTarget.Latest, true);
>>>>>>> Rebasing issues resolved
insert(host, modulePath, [
insertImport(sourceFile, modulePath, 'NxModule', '@nrwl/nx'),
...addImportToModule(sourceFile, modulePath, 'NxModule.forRoot()')
@ -117,8 +131,7 @@ function addAppToAngularCliJson(options: NormalizedSchema): Rule {
});
json.lint = [
...(json.lint || []),
{
...(json.lint || []), {
project: `${options.fullPath}/tsconfig.app.json`,
exclude: '**/node_modules/**'
},
@ -138,6 +151,7 @@ function addRouterRootConfiguration(path: string): Rule {
const modulePath = `${path}/app/app.module.ts`;
const moduleSource = host.read(modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(
<<<<<<< HEAD
modulePath,
moduleSource,
ts.ScriptTarget.Latest,
@ -150,18 +164,23 @@ function addRouterRootConfiguration(path: string): Rule {
modulePath,
`RouterModule.forRoot([], {initialNavigation: 'enabled'})`
)
=======
modulePath, moduleSource, ts.ScriptTarget.Latest, true);
insert(host, modulePath, [
insertImport(sourceFile, modulePath, 'RouterModule', '@angular/router'),
...addImportToModule(
sourceFile, modulePath,
`RouterModule.forRoot([], {initialNavigation: 'enabled'})`)
>>>>>>> Rebasing issues resolved
]);
const componentSpecPath = `${path}/app/app.component.spec.ts`;
const componentSpecSource = host.read(componentSpecPath)!.toString('utf-8');
const componentSpecSourceFile = ts.createSourceFile(
componentSpecPath,
componentSpecSource,
ts.ScriptTarget.Latest,
true
);
componentSpecPath, componentSpecSource, ts.ScriptTarget.Latest, true);
insert(host, componentSpecPath, [
insertImport(
<<<<<<< HEAD
componentSpecSourceFile,
componentSpecPath,
'RouterTestingModule',
@ -172,6 +191,12 @@ function addRouterRootConfiguration(path: string): Rule {
componentSpecPath,
`RouterTestingModule`
)
=======
componentSpecSourceFile, componentSpecPath, 'RouterTestingModule',
'@angular/router/testing'),
...addImportToTestBed(
componentSpecSourceFile, componentSpecPath, `RouterTestingModule`)
>>>>>>> Rebasing issues resolved
]);
return host;
};
@ -197,9 +222,9 @@ Nx is designed to help you create and build enterprise grade Angular application
function updateComponentTemplate(options: NormalizedSchema): Rule {
return (host: Tree) => {
const content = options.routing
? `${staticComponentContent}\n<router-outlet></router-outlet>`
: staticComponentContent;
const content = options.routing ?
`${staticComponentContent}\n<router-outlet></router-outlet>` :
staticComponentContent;
host.overwrite(`${options.fullPath}/app/app.component.html`, content);
};
}
@ -212,16 +237,15 @@ export default function(schema: Schema): Rule {
}
const options = normalizeOptions(schema);
const templateSource = apply(url('./files'), [
template({
utils: strings,
dot: '.',
tmpl: '',
offsetFromRoot: offsetFromRoot(options.fullPath),
...(options as object),
npmScope
})
]);
const templateSource =
apply(url('./files'), [template({
utils: strings,
dot: '.',
tmpl: '',
offsetFromRoot: offsetFromRoot(options.fullPath),
...(options as object),
npmScope
})]);
const selector = `${options.prefix}-root`;
@ -247,10 +271,8 @@ export default function(schema: Schema): Rule {
viewEncapsulation: options.viewEncapsulation,
changeDetection: options.changeDetection
}),
updateComponentTemplate(options),
addBootstrap(options.fullPath),
addNxModule(options.fullPath),
addAppToAngularCliJson(options),
updateComponentTemplate(options), addBootstrap(options.fullPath),
addNxModule(options.fullPath), addAppToAngularCliJson(options),
options.routing ? addRouterRootConfiguration(options.fullPath) : noop()
]);
});
@ -258,9 +280,14 @@ export default function(schema: Schema): Rule {
function normalizeOptions(options: Schema): NormalizedSchema {
const name = toFileName(options.name);
<<<<<<< HEAD
const fullName = options.directory
? `${toFileName(options.directory)}/${name}`
: name;
=======
const fullName =
options.directory ? `${toFileName(options.directory)}/${name}` : name;
>>>>>>> Rebasing issues resolved
const fullPath = `apps/${fullName}/src`;
return { ...options, sourceDir: 'src', name, fullName, fullPath };
return {...options, sourceDir: 'src', name, fullName, fullPath};
}

View File

@ -31,7 +31,7 @@ import {
toPropertyName
} from '../../utils/name-utils';
interface NormalizedSchema extends Schema {
export interface NormalizedSchema extends Schema {
name: string;
fullName: string;
fullPath: string;
@ -65,25 +65,18 @@ function addLazyLoadedRouterConfiguration(modulePath: string): Rule {
);
insert(host, modulePath, [
insertImport(sourceFile, modulePath, 'RouterModule', '@angular/router'),
...addImportToModule(
sourceFile,
modulePath,
`
...addImportToModule(sourceFile, modulePath, `
RouterModule.forChild([
/* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
]) `
)
]) `)
]);
return host;
};
}
function addRouterConfiguration(
schema: NormalizedSchema,
indexFilePath: string,
moduleFileName: string,
modulePath: string
): Rule {
schema: NormalizedSchema, indexFilePath: string, moduleFileName: string,
modulePath: string): Rule {
return (host: Tree) => {
const indexSource = host.read(indexFilePath)!.toString('utf-8');
const indexSourceFile = ts.createSourceFile(
@ -232,49 +225,70 @@ function addChildren(schema: NormalizedSchema): Rule {
};
}
export interface LibSchema {
options: NormalizedSchema;
moduleFileName: string;
modulePath: string;
indexFile: string;
templateSource: Source;
routingRules: Rule[];
}
export function validateLibSchema(schema): LibSchema {
const options = normalizeOptions(schema);
const moduleFileName = `${toFileName(options.name)}.module`;
const modulePath = `${options.fullPath}/${moduleFileName}.ts`;
const indexFile = `libs/${toFileName(options.fullName)}/index.ts`;
if (options.routing && options.nomodule) {
throw new Error(`nomodule and routing cannot be used together`);
}
if (!options.routing && options.lazy) {
throw new Error(`routing must be set`);
}
const routingRules: Array<Rule> = [
options.routing && options.lazy ?
addLazyLoadedRouterConfiguration(modulePath) :
noop(),
options.routing && options.lazy && options.parentModule ?
addLoadChildren(options) :
noop(),
options.routing && !options.lazy ?
addRouterConfiguration(options, indexFile, moduleFileName, modulePath) :
noop(),
options.routing && !options.lazy && options.parentModule ?
addChildren(options) :
noop()
];
const templateSource =
apply(url(options.nomodule ? './files' : './ngfiles'), [template({
...names(options.name),
dot: '.',
tmpl: '',
...(options as object)
})]);
return {
options,
moduleFileName,
modulePath,
indexFile,
templateSource,
routingRules
};
}
export default function(schema: Schema): Rule {
return wrapIntoFormat(() => {
const options = normalizeOptions(schema);
const moduleFileName = `${toFileName(options.name)}.module`;
const modulePath = `${options.fullPath}/${moduleFileName}.ts`;
const indexFile = `libs/${toFileName(options.fullName)}/index.ts`;
if (options.routing && options.nomodule) {
throw new Error(`nomodule and routing cannot be used together`);
}
if (!options.routing && options.lazy) {
throw new Error(`routing must be set`);
}
const templateSource = apply(
url(options.nomodule ? './files' : './ngfiles'),
[
template({
...names(options.name),
dot: '.',
tmpl: '',
...(options as object)
})
]
);
const {options, templateSource, routingRules} = validateLibSchema(schema);
return chain([
branchAndMerge(chain([mergeWith(templateSource)])),
addLibToAngularCliJson(options),
options.routing && options.lazy
? addLazyLoadedRouterConfiguration(modulePath)
: noop(),
options.routing && options.lazy && options.parentModule
? addLoadChildren(options)
: noop(),
options.routing && !options.lazy
? addRouterConfiguration(options, indexFile, moduleFileName, modulePath)
: noop(),
options.routing && !options.lazy && options.parentModule
? addChildren(options)
: noop()
addLibToAngularCliJson(options), ...routingRules
]);
});
}
@ -285,5 +299,5 @@ function normalizeOptions(options: Schema): NormalizedSchema {
? `${toFileName(options.directory)}/${name}`
: name;
const fullPath = `libs/${fullName}/src`;
return { ...options, sourceDir: 'src', name, fullName, fullPath };
return {...options, sourceDir: 'src', name, fullName, fullPath};
}

View File

@ -2,9 +2,30 @@
rm -rf build
./node_modules/.bin/ngc
#Nx client side lib
cp -r packages/nx/dist build/packages/nx
rm -rf build/packages/nx/dist
#TODO This is a temporary hack until we can publish named umds
sed -i.bak "s/define(\[/define('@nrwl\/nx',\[/" build/packages/nx/bundles/nrwl-nx.umd.js
sed -i.bak "s/define(\[/define('@nrwl\/nx',\[/" build/packages/nx/bundles/nrwl-nx.umd.min.js
rm -rf build/packages/nx/bundles/nrwl-nx.umd.js.bak
rm -rf build/packages/nx/bundles/nrwl-nx.umd.min.js.bak
sed -i.bak "s/define(\[/define('@nrwl\/nx\/testing',\[/" build/packages/nx/bundles/nrwl-nx-testing.umd.js
sed -i.bak "s/define(\[/define('@nrwl\/nx\/testing',\[/" build/packages/nx/bundles/nrwl-nx-testing.umd.min.js
rm -rf build/packages/nx/bundles/nrwl-nx-testing.umd.js.bak
rm -rf build/packages/nx/bundles/nrwl-nx-testing.umd.min.js.bak
rsync -a --exclude=*.ts packages/ build/packages
chmod +x build/packages/schematics/bin/create-nx-workspace.js
chmod +x build/packages/schematics/src/command-line/nx.js
rm -rf build/packages/install
rm -rf build/packages/nx/dist
rm -rf build/packages/nx/spec
cp README.md build/packages/schematics
cp README.md build/packages/nx
cp README.md build/packages/nx

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bash
npm run build
./scripts/link.sh
rm -rf tmp
mkdir tmp

9
scripts/link-spec.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
rm -rf build/
tsc
rsync -a --exclude=*.ts packages/ build/packages
rm -rf node_modules/@nrwl
cp -r build/packages node_modules/@nrwl

View File

@ -8,25 +8,15 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"lib": [
"es2017"
],
"lib": ["es2017"],
"declaration": true,
"baseUrl": ".",
"paths": {
"@nrwl/schematics": [
"./packages/schematics"
],
"@nrwl/schematics/*": [
"./packages/schematics/*"
]
"@nrwl/schematics": ["./packages/schematics"],
"@nrwl/schematics/*": ["./packages/schematics/*"]
}
},
"exclude": [
"tmp",
"node_modules",
"packages/schematics/src/*/files/**/*"
],
"exclude": ["tmp", "node_modules"],
"angularCompilerOptions": {
"strictMetadataEmit": true,
"skipTemplateCodegen": true,

7495
yarn-error.log Normal file

File diff suppressed because it is too large Load Diff

1490
yarn.lock

File diff suppressed because it is too large Load Diff