From 0d0ac9ea4f76e7aa06c9050d4705f2569d54da2c Mon Sep 17 00:00:00 2001 From: vsavkin Date: Sat, 19 Aug 2017 10:15:22 -0400 Subject: [PATCH] feat: add workspace schematic --- e2e/workspace.test.ts | 18 +++++++ .../workspace/files/BUILD.bazel__tmpl__ | 40 ++++++++++++++ .../workspace/files/README.md__tmpl__ | 28 ++++++++++ .../workspace/files/WORKSPACE__tmpl__ | 36 +++++++++++++ .../files/__dot__angular-cli.json__tmpl__ | 41 ++++++++++++++ .../workspace/files/__dot__bazelrc__tmpl__ | 5 ++ .../files/__dot__editorconfig__tmpl__ | 13 +++++ .../workspace/files/__dot__gitignore__tmpl__ | 42 +++++++++++++++ .../workspace/files/package.json__tmpl__ | 53 +++++++++++++++++++ .../files/protractor.conf.js__tmpl__ | 28 ++++++++++ .../workspace/files/tsconfig.json__tmpl__ | 8 +++ src/schematics/workspace/index.ts | 18 +++++++ src/schematics/workspace/schema.d.ts | 4 ++ src/schematics/workspace/schema.json | 18 +++++++ 14 files changed, 352 insertions(+) create mode 100644 e2e/workspace.test.ts create mode 100644 src/schematics/workspace/files/BUILD.bazel__tmpl__ create mode 100755 src/schematics/workspace/files/README.md__tmpl__ create mode 100644 src/schematics/workspace/files/WORKSPACE__tmpl__ create mode 100644 src/schematics/workspace/files/__dot__angular-cli.json__tmpl__ create mode 100644 src/schematics/workspace/files/__dot__bazelrc__tmpl__ create mode 100644 src/schematics/workspace/files/__dot__editorconfig__tmpl__ create mode 100755 src/schematics/workspace/files/__dot__gitignore__tmpl__ create mode 100644 src/schematics/workspace/files/package.json__tmpl__ create mode 100644 src/schematics/workspace/files/protractor.conf.js__tmpl__ create mode 100644 src/schematics/workspace/files/tsconfig.json__tmpl__ create mode 100644 src/schematics/workspace/index.ts create mode 100644 src/schematics/workspace/schema.d.ts create mode 100644 src/schematics/workspace/schema.json diff --git a/e2e/workspace.test.ts b/e2e/workspace.test.ts new file mode 100644 index 0000000000..91005a8673 --- /dev/null +++ b/e2e/workspace.test.ts @@ -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` + ); + }); +}); diff --git a/src/schematics/workspace/files/BUILD.bazel__tmpl__ b/src/schematics/workspace/files/BUILD.bazel__tmpl__ new file mode 100644 index 0000000000..60a4458d8b --- /dev/null +++ b/src/schematics/workspace/files/BUILD.bazel__tmpl__ @@ -0,0 +1,40 @@ +package(default_visibility = ["//visibility:public"]) +exports_files(["tsconfig.json"]) + +load("@build_bazel_rules_angular//:defs.bzl", "ng_external_libraries") + +filegroup(name = "node_modules", srcs = glob([ + # should not be whitelisted + "node_modules/@angular/**", + "node_modules/typescript/**", + "node_modules/zone.js/**", + "node_modules/rxjs/**/*.d.ts", + "node_modules/rxjs/**/*.js", + "node_modules/@types/**/*.d.ts", + "node_modules/tsickle/**", + "node_modules/hammerjs/**/*.d.ts", + "node_modules/protobufjs/**", + "node_modules/bytebuffer/**", + "node_modules/reflect-metadata/**", + "node_modules/minimist/**/*.js", + "node_modules/webpack/**" +], exclude=["node_modules/@angular/cli/**"])) + +ng_external_libraries(name = "ng_libs", srcs = glob([ + "node_modules/@angular/**" +], exclude = [ + "node_modules/@angular/cli/**", + "node_modules/@angular/platform-browser/animations*", + "node_modules/@angular/platform-browser/animations/**", + + # Alex E? + "node_modules/@angular/router*", + "node_modules/@angular/router/**", +])) + +filegroup( + name= "init", + srcs = [ + ":ng_libs" + ] +) diff --git a/src/schematics/workspace/files/README.md__tmpl__ b/src/schematics/workspace/files/README.md__tmpl__ new file mode 100755 index 0000000000..313785e797 --- /dev/null +++ b/src/schematics/workspace/files/README.md__tmpl__ @@ -0,0 +1,28 @@ +# <%= className %> + +This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version <%= version %>. + +## Development server + +Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. + +## Code scaffolding + +Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. + +## Build + +Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. + +## Running unit tests + +Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Running end-to-end tests + +Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). +Before running the tests make sure you are serving the app via `ng serve`. + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). diff --git a/src/schematics/workspace/files/WORKSPACE__tmpl__ b/src/schematics/workspace/files/WORKSPACE__tmpl__ new file mode 100644 index 0000000000..49ca1f58fe --- /dev/null +++ b/src/schematics/workspace/files/WORKSPACE__tmpl__ @@ -0,0 +1,36 @@ +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "build_bazel_rules_typescript", + remote = "https://github.com/vsavkin/rules_typescript", + commit = "9a6c806", +) + +git_repository( + name = "build_bazel_rules_angular", + remote = "https://github.com/alexeagle/rules_angular", + commit = "ce85fe6", +) + +git_repository( + name = "io_bazel_rules_sass", + remote = "https://github.com/bazelbuild/rules_sass.git", + tag = "0.0.2", +) + +git_repository( + name = "build_bazel_rules_nodejs", + remote = "https://github.com/alexeagle/rules_nodejs.git", + commit = "4924d7b", +) + +local_repository( + name = "build_bazel_rules_nrwl", + path = "node_modules/@nrwl/nx/bazel", +) + +load("@build_bazel_rules_typescript//:defs.bzl", "node_repositories") +load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories") + +node_repositories(package_json = "//:package.json") +sass_repositories() diff --git a/src/schematics/workspace/files/__dot__angular-cli.json__tmpl__ b/src/schematics/workspace/files/__dot__angular-cli.json__tmpl__ new file mode 100644 index 0000000000..296a43eb2b --- /dev/null +++ b/src/schematics/workspace/files/__dot__angular-cli.json__tmpl__ @@ -0,0 +1,41 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "project": { + "name": "<%= fileName %>" + }, + "apps": [ + ], + "test": { + "karma": { + "config": "node_modules/@nrwl/nx/bazel/karma.conf.js" + } + }, + "defaults": { + "schematics": { + "collection": "@nrwl/nx" + }, + "component": { + "spec": true, + "inlineStyle": false, + "inlineTemplate": false + }, + "directive": { + "spec": true + }, + "class": { + "spec": true + }, + "guard": { + "spec": true + }, + "module": { + "spec": true + }, + "pipe": { + "spec": true + }, + "service": { + "spec": true + } + } +} diff --git a/src/schematics/workspace/files/__dot__bazelrc__tmpl__ b/src/schematics/workspace/files/__dot__bazelrc__tmpl__ new file mode 100644 index 0000000000..be2334697f --- /dev/null +++ b/src/schematics/workspace/files/__dot__bazelrc__tmpl__ @@ -0,0 +1,5 @@ +build --strategy=AngularTemplateCompile=standalone +build --strategy=TypeScriptCompile=worker +build --spawn_strategy=standalone +build --watchfs +build --symlink_prefix=/ \ No newline at end of file diff --git a/src/schematics/workspace/files/__dot__editorconfig__tmpl__ b/src/schematics/workspace/files/__dot__editorconfig__tmpl__ new file mode 100644 index 0000000000..6e87a003da --- /dev/null +++ b/src/schematics/workspace/files/__dot__editorconfig__tmpl__ @@ -0,0 +1,13 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/src/schematics/workspace/files/__dot__gitignore__tmpl__ b/src/schematics/workspace/files/__dot__gitignore__tmpl__ new file mode 100755 index 0000000000..54bfd2001e --- /dev/null +++ b/src/schematics/workspace/files/__dot__gitignore__tmpl__ @@ -0,0 +1,42 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp +/out-tsc + +# dependencies +/node_modules + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +testem.log +/typings + +# e2e +/e2e/*.js +/e2e/*.map + +# System Files +.DS_Store +Thumbs.db diff --git a/src/schematics/workspace/files/package.json__tmpl__ b/src/schematics/workspace/files/package.json__tmpl__ new file mode 100644 index 0000000000..945c951199 --- /dev/null +++ b/src/schematics/workspace/files/package.json__tmpl__ @@ -0,0 +1,53 @@ +{ + "name": "<%= fileName %>", + "version": "0.0.0", + "license": "MIT", + "scripts": { + "ng": "ng", + "start": "ng serve", + "build": "ng build", + "test": "ng test", + "lint": "ng lint", + "e2e": "ng e2e" + }, + "private": true, + "dependencies": { + "@angular/animations": "4.3.0", + "@angular/common": "4.3.0", + "@angular/compiler": "4.3.0", + "@angular/core": "4.3.0", + "@angular/forms": "4.3.0", + "@angular/http": "4.3.0", + "@angular/platform-browser": "4.3.0", + "@angular/platform-browser-dynamic": "4.3.0", + "@angular/router": "4.3.0", + "core-js": "^2.4.1", + "rxjs": "^5.4.2", + "zone.js": "^0.8.14" + }, + "devDependencies": { + "@angular/cli": "https://github.com/nrwl/bazel-cli-build", + "@nrwl/nx": "https://github.com/nrwl/nx-build", + "@angular/compiler-cli": "4.3.0", + "@angular/language-service": "4.3.0", + "@types/jasmine": "~2.5.53", + "@types/jasminewd2": "~2.0.2", + "@types/node": "~6.0.60", + "codelyzer": "~3.1.1", + "jasmine-core": "~2.6.2", + "jasmine-spec-reporter": "~4.1.0", + "karma": "~1.7.0", + "karma-chrome-launcher": "~2.1.1", + "karma-cli": "~1.0.1", + "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": "~3.2.0", + "tslint": "~5.3.2", + "typescript": "2.3.4", + "protobufjs": "5.0.0", + "karma-spec-reporter": "0.0.31", + "karma-webpack": "2.0.4" + } +} diff --git a/src/schematics/workspace/files/protractor.conf.js__tmpl__ b/src/schematics/workspace/files/protractor.conf.js__tmpl__ new file mode 100644 index 0000000000..7ee3b5ee86 --- /dev/null +++ b/src/schematics/workspace/files/protractor.conf.js__tmpl__ @@ -0,0 +1,28 @@ +// Protractor configuration file, see link for more information +// https://github.com/angular/protractor/blob/master/lib/config.ts + +const { SpecReporter } = require('jasmine-spec-reporter'); + +exports.config = { + allScriptsTimeout: 11000, + specs: [ + './e2e/**/*.e2e-spec.ts' + ], + capabilities: { + 'browserName': 'chrome' + }, + directConnect: true, + baseUrl: 'http://localhost:4200/', + framework: 'jasmine', + jasmineNodeOpts: { + showColors: true, + defaultTimeoutInterval: 30000, + print: function() {} + }, + onPrepare() { + require('ts-node').register({ + project: 'e2e/tsconfig.e2e.json' + }); + jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); + } +}; diff --git a/src/schematics/workspace/files/tsconfig.json__tmpl__ b/src/schematics/workspace/files/tsconfig.json__tmpl__ new file mode 100644 index 0000000000..a691b62486 --- /dev/null +++ b/src/schematics/workspace/files/tsconfig.json__tmpl__ @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "strict": true, + "skipLibCheck": true, + "experimentalDecorators": true, + "baseUrl": "." + } +} diff --git a/src/schematics/workspace/index.ts b/src/schematics/workspace/index.ts new file mode 100644 index 0000000000..8192829692 --- /dev/null +++ b/src/schematics/workspace/index.ts @@ -0,0 +1,18 @@ +import {apply, chain, mergeWith, move, Rule, schematic, template, url,} from '@angular-devkit/schematics'; +import {Schema} from './schema'; +import {names} from '../name-utils'; + +export default function (options: Schema): Rule { + return chain([ + mergeWith( + apply(url('./files'), [ + template({ + ...options, + ...names(options.name), + 'dot': '.', + 'tmpl': '' + }), + move(options.name !) + ])) + ]); +} diff --git a/src/schematics/workspace/schema.d.ts b/src/schematics/workspace/schema.d.ts new file mode 100644 index 0000000000..39035da6f3 --- /dev/null +++ b/src/schematics/workspace/schema.d.ts @@ -0,0 +1,4 @@ +export interface Schema { + name: string; + version?: string; +} diff --git a/src/schematics/workspace/schema.json b/src/schematics/workspace/schema.json new file mode 100644 index 0000000000..59bb7177e4 --- /dev/null +++ b/src/schematics/workspace/schema.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/schema", + "id": "SchematicsAngularBazelWorkspace", + "title": "Angular Bazel Workspace Options Schema", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "required": [ + "name", + "version" + ] +}