Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Add the following dependencies to your project's `package.json` and run `npm ins
dependencies: {
"@ngrx/store": "4.0.2",
"@ngrx/effects": "4.0.2",
"@nrwl/nx": "https://github.com/nrwl/nx-build"
"@nrwl/nx": "https://github.com/nrwl/nx-build",
"@angular-devkit/schematics": "0.0.17"
}
}
```
Expand Down
14 changes: 7 additions & 7 deletions e2e/addngrx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('addNgRxToModule', () => {

it('should add root configuration', () => {
newApp('new proj --skipInstall');
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts --root', {cwd: 'proj'});
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts --root', {projectName: 'proj'});

checkFilesExists(
`proj/src/app/+state/app.actions.ts`,
Expand All @@ -26,27 +26,27 @@ describe('addNgRxToModule', () => {

addNgRx('proj');

runCLI('build', {cwd: 'proj'});
runCLI('test --single-run', {cwd: 'proj'});
runCLI('build', {projectName: 'proj'});
runCLI('test --single-run', {projectName: 'proj'});

}, 50000);

it('should add empty root configuration', () => {
newApp('new proj2 --skipInstall');
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts --emptyRoot', {cwd: 'proj2'});
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts --emptyRoot', {projectName: 'proj2'});

const contents = readFile('proj2/src/app/app.module.ts');
expect(contents).toContain('StoreModule.forRoot');
expect(contents).not.toContain('EffectsModule.forRoot');

addNgRx('proj2');

runCLI('build', {cwd: 'proj2'});
runCLI('build', {projectName: 'proj2'});
}, 50000);

it('should add feature configuration', () => {
newApp('new proj3 --skipInstall');
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts', {cwd: 'proj3'});
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts', {projectName: 'proj3'});

checkFilesExists(
`proj3/src/app/+state/app.actions.ts`,
Expand All @@ -65,7 +65,7 @@ describe('addNgRxToModule', () => {

it('should generate files without importing them', () => {
newApp('new proj4 --skipInstall');
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts --skipImport', {cwd: 'proj4'});
runSchematic('@nrwl/nx:addNgRxToModule --module=src/app/app.module.ts --skipImport', {projectName: 'proj4'});

checkFilesExists(
`proj4/src/app/+state/app.actions.ts`,
Expand Down
40 changes: 40 additions & 0 deletions e2e/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
addNgRx, checkFilesExists, cleanup, newApp, readFile, runCLI, runCommand, runSchematic,
updateFile
} from './utils';

describe('application', () => {
beforeEach(cleanup);

it('creates a new application in a workspace', () => {
runSchematic('@nrwl/nx:application --name=proj');
runSchematic('@nrwl/nx:app --name=myapp', {projectName: 'proj'});

checkFilesExists(
`proj/tsconfig.json`,
`proj/WORKSPACE`,
`proj/BUILD.bazel`,
`proj/apps/myapp/BUILD.bazel`,
`proj/apps/myapp/src/index.html`,
`proj/apps/myapp/src/app/app.module.ts`,
`proj/apps/myapp/src/app/app.component.ts`
);

expect(readFile('proj/apps/myapp/src/app/app.module.ts')).toContain('bootstrap: [AppComponent]');

const cliConfig = JSON.parse(readFile('proj/.angular-cli.json'));
expect(cliConfig.apps.length).toEqual(1);
});

it('creates multiple applications in a workspace', () => {
runSchematic('@nrwl/nx:application --name=proj2');
runSchematic('@nrwl/nx:app --name=first', {projectName: 'proj2'});
runSchematic('@nrwl/nx:app --name=second', {projectName: 'proj2'});

const cliConfig = JSON.parse(readFile('proj2/.angular-cli.json'));
expect(cliConfig.apps[0].name).toEqual('first');
expect(cliConfig.apps[0].root).toEqual('apps/first/src');
expect(cliConfig.apps[1].name).toEqual('second');
expect(cliConfig.apps[1].root).toEqual('apps/second/src');
});
});
9 changes: 0 additions & 9 deletions e2e/package.json__tmpl__

This file was deleted.

21 changes: 11 additions & 10 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import {readFileSync, statSync, writeFileSync} from 'fs';
export function newApp(command: string): string {
return execSync(`../node_modules/.bin/ng ${command}`, {cwd: `./tmp`}).toString();
}
export function runCLI(command: string, {cwd}: {cwd: string}): string {
cwd = cwd === undefined ? '' : cwd;
return execSync(`../../node_modules/.bin/ng ${command}`, {cwd: `./tmp/${cwd}`}).toString();
export function runCLI(command: string, {projectName: projectName}: {projectName: string}): string {
projectName = projectName === undefined ? '' : projectName;
return execSync(`../../node_modules/.bin/ng ${command}`, {cwd: `./tmp/${projectName}`}).toString();
}
export function runSchematic(command: string, {cwd}: {cwd: string}): string {
cwd = cwd === undefined ? '' : cwd;
return execSync(`../../node_modules/.bin/schematics ${command}`, {cwd: `./tmp/${cwd}`}).toString();
export function runSchematic(command: string, {projectName}: {projectName?: string} = {}): string {
const up = projectName ? '../' : '';
projectName = projectName === undefined ? '' : projectName;
return execSync(`../${up}node_modules/.bin/schematics ${command}`, {cwd: `./tmp/${projectName}`}).toString();
}
export function runCommand(command: string, {cwd}: {cwd: string}): string {
cwd = cwd === undefined ? '' : cwd;
return execSync(command, {cwd: `./tmp/${cwd}`}).toString();
export function runCommand(command: string, {projectName}: {projectName: string}): string {
projectName = projectName === undefined ? '' : projectName;
return execSync(command, {cwd: `./tmp/${projectName}`}).toString();
}

export function updateFile(f: string, content: string): void {
Expand Down Expand Up @@ -70,5 +71,5 @@ export function addNgRx(path: string): string {
p['dependencies']['@ngrx/effects'] = '4.0.2';
p['dependencies']['jasmine-marbles'] = '0.1.0';
updateFile(`${path}/package.json`, JSON.stringify(p, null, 2));
return runCommand('npm install', {cwd: path});
return runCommand('npm install', {projectName: path});
}
18 changes: 18 additions & 0 deletions e2e/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
addNgRx, checkFilesExists, cleanup, newApp, readFile, runCLI, runCommand, runSchematic,
updateFile
} from './utils';

describe('workspace', () => {
beforeEach(cleanup);

it('creates a new workspace for developing angular applications', () => {
runSchematic('@nrwl/nx:application --name=proj --version=0.1');

checkFilesExists(
`proj/tsconfig.json`,
`proj/WORKSPACE`,
`proj/BUILD.bazel`
);
});
});
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
"scripts": {
"build": "./scripts/build.sh",
"e2e": "yarn build && ./scripts/e2e.sh",
"release": "yarn build && ./scripts/release.sh"
"package": "./scripts/package.sh",
"release": "./scripts/release.sh"
},
"dependencies" :{
"@angular-devkit/schematics": "0.0.16",
"jasmine-marbles": "0.1.0"
},
"peerDependencies" :{
"@angular-devkit/schematics": "*",
"rxjs": "*"
},
"devDependencies": {
"rxjs": "5.4.3",
"typescript": "2.4.2",
"@types/node": "8.0.7",
"@types/jasmine": "2.5.53",
"jest": "20.0.4"
"jest": "20.0.4",
"@angular-devkit/schematics": "0.0.17",
"@schematics/angular": "git+https://github.com/Brocco/zzz-ng-schematics.git"
},
"author": "Victor Savkin",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions scripts/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

./scripts/build.sh
cp package.json build/src/package.json
cp README.md build/src/README.md
cp LICENSE build/src/LICENSE
4 changes: 1 addition & 3 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash

cp package.json build/src/package.json
cp README.md build/src/README.md
cp LICENSE build/src/LICENSE
./scripts/package.sh
cd build/src
git init
git add .
Expand Down
8 changes: 8 additions & 0 deletions src/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@build_bazel_rules_typescript//:defs.bzl", "nodejs_binary")
exports_files(["webpack.config.js", "test.js"])

nodejs_binary(
name = "webpack",
entry_point = "webpack/bin/webpack",
visibility = ["//visibility:public"],
)
Empty file added src/bazel/WORKSPACE
Empty file.
109 changes: 109 additions & 0 deletions src/bazel/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Warning: the testing rule will change.
*
* Instead of running karma outside of bazel against the bin_dir directory, we will run it as part of the bazel process.
*/
module.exports = function(config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a warning comment about how the testing rule will change? (ppl might come browse this repo to find out what we are planning)

const webpackConfig = {
resolveLoader: {
alias: {
"template-loader": '@nrwl/nx/bazel/template-loader'
}
},
module: {
rules: [
{
test: /\.component\.js$/,
use: [
{loader: 'template-loader' }
]
},
{
test: /\.html$/,
use: [
{loader: 'raw-loader' }
]
},
{
test: /\.css$/,
use: [
{loader: 'raw-loader' }
]
}
]
}
};

config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: `${config.opts.bin_dir}/${config.opts.app}`,

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: [
{ pattern: 'test.js', watched: false}
],

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test.js': ['webpack']
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: config.opts.reporters ? config.opts.reporters : (config.opts.progress ? ['progress'] : ['dots']),

webpack: webpackConfig,

webpackMiddleware: {
stats: 'errors-only'
},

plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-webpack')
],

coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},

client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},

// web server port
port: config.opts.port ? config.opts.port : 9876,

// enable / disable colors in the output (reporters and logs)
colors: config.opts.colors,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.opts.log ? config.opts.log: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// browsers: ['PhantomJS'],
browsers: ['Chrome'],

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
};
30 changes: 30 additions & 0 deletions src/bazel/template-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*([,}]))/gm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file only used with karma, right? seems like there should be a karma subdirectory

var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

function replaceStringsWithRequires(string) {
return string.replace(stringRegex, function (match, quote, url) {
if (url.charAt(0) !== ".") {
url = "./" + url;
}
return "require('" + url + "')";
});
}

module.exports = function(source, sourcemap) {
// Not cacheable during unit tests;
this.cacheable && this.cacheable();

var newSource = source.replace(templateUrlRegex, function (match, url) {
return "template:" + replaceStringsWithRequires(url);
}).replace(stylesRegex, function (match, urls) {
return "styles:" + replaceStringsWithRequires(urls);
});

// Support for tests
if (this.callback) {
this.callback(null, newSource, sourcemap)
} else {
return newSource;
}
};
Loading