Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Schematics #1

Merged
merged 12 commits into from
Jun 7, 2017
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
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Disable sandboxing because it's too slow.
# https://github.com/bazelbuild/bazel/issues/2424
# TODO(alexeagle): do use the sandbox on CI
#build --spawn_strategy=standalone

# Performance: avoid stat'ing input files
build --watchfs

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Outputs
bazel-*
build/
dist/

Expand All @@ -11,6 +12,7 @@ jsconfig.json
typings/

# Misc
coverage/
node_modules/
tmp/
npm-debug.log*
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
dist: trusty

language: node_js

env:
global:
- DBUS_SESSION_BUS_ADDRESS=/dev/null

matrix:
fast_finish: true
include:
- node_js: "6"
os: linux
env: SCRIPT=lint
- node_js: "6"
os: linux
env: SCRIPT=test

before_install:
# Install yarn.
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"
- yarn config set spin false
- yarn config set progress false

script:
- if [[ "$SCRIPT" ]]; then npm run $SCRIPT; fi
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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", srcs = glob(["node_modules/**/*"]))
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "io_bazel_rules_typescript",
remote = "https://github.com/bazelbuild/rules_typescript.git",
tag = "0.0.2",
)

load("@io_bazel_rules_typescript//:defs.bzl", "node_repositories", "yarn_install")

node_repositories()
yarn_install(package_json = "//:package.json")
18 changes: 18 additions & 0 deletions bin/devkit-admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
'use strict';

/**
* This file is useful for not having to load bootstrap-local in various javascript.
* Simply use package.json to have npm scripts that use this script as well, or use
* this script directly.
*/

require('../lib/bootstrap-local');

const minimist = require('minimist');
const path = require('path');

const args = minimist(process.argv.slice(2));
const scriptName = path.join('../scripts', args._.shift());

require(scriptName).default(args);
6 changes: 6 additions & 0 deletions bin/schematics
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node
'use strict';
require('../lib/bootstrap-local');
const packages = require('../lib/packages').packages;

require(packages['@angular/schematics-cli'].bin['schematics']);
90 changes: 90 additions & 0 deletions lib/bootstrap-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* @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
*/
/* eslint-disable no-console */
'use strict';

const fs = require('fs');
const path = require('path');
const ts = require('typescript');


Error.stackTraceLimit = Infinity;

global._DevKitIsLocal = true;
global._DevKitRoot = path.resolve(__dirname, '..');
global._DevKitPackages = require('./packages').packages;
global._DevKitTools = require('./packages').tools;

global._DevKitRequireHook = null;


const compilerOptions = ts.readConfigFile(path.join(__dirname, '../tsconfig.json'), p => {
return fs.readFileSync(p, 'utf-8');
}).config;


const oldRequireTs = require.extensions['.ts'];
require.extensions['.ts'] = function (m, filename) {
// If we're in node module, either call the old hook or simply compile the
// file without transpilation. We do not touch node_modules/**.
// We do touch `Angular DevK` files anywhere though.
if (!filename.match(/@angular\/cli\b/) && filename.match(/node_modules/)) {
if (oldRequireTs) {
return oldRequireTs(m, filename);
}
return m._compile(fs.readFileSync(filename), filename);
}

// Node requires all require hooks to be sync.
const source = fs.readFileSync(filename).toString();

try {
let result = ts.transpile(source, compilerOptions['compilerOptions'], filename);

if (global._DevKitRequireHook) {
result = global._DevKitRequireHook(result, filename);
}

// Send it to node to execute.
return m._compile(result, filename);
} catch (err) {
console.error('Error while running script "' + filename + '":');
console.error(err.stack);
throw err;
}
};


// If we're running locally, meaning npm linked. This is basically "developer mode".
if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
const packages = require('./packages').packages;

// We mock the module loader so that we can fake our packages when running locally.
const Module = require('module');
const oldLoad = Module._load;
const oldResolve = Module._resolveFilename;

Module._resolveFilename = function (request, parent) {
if (request in packages) {
return packages[request].main;
} else if (request.startsWith('@angular/cli/')) {
// We allow deep imports (for now).
// TODO: move tests to inside @angular/cli package so they don't have to deep import.
const dir = path.dirname(parent.filename);
return path.relative(dir, path.join(__dirname, '../packages', request));
} else {
let match = Object.keys(packages).find(pkgName => request.startsWith(pkgName + '/'));
if (match) {
const p = path.join(packages[match].root, request.substr(match.length));
return oldResolve.call(this, p, parent);
} else {
return oldResolve.apply(this, arguments);
}
}
};
}
72 changes: 72 additions & 0 deletions lib/packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @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
*/
'use strict';

const fs = require('fs');
const glob = require('glob');
const path = require('path');

const packageRoot = path.join(__dirname, '../packages');
const toolsRoot = path.join(__dirname, '../tools');
const distRoot = path.join(__dirname, '../dist');


// All the supported packages. Go through the packages directory and create a _map of
// name => fullPath.
const packages =
[].concat(
glob.sync(path.join(packageRoot, '*/package.json')),
glob.sync(path.join(packageRoot, '*/*/package.json')))
.filter(p => !p.match(/blueprints/))
.map(pkgPath => [pkgPath, path.relative(packageRoot, path.dirname(pkgPath))])
.map(([pkgPath, pkgName]) => {
return { name: pkgName, root: path.dirname(pkgPath) };
})
.reduce((packages, pkg) => {
let pkgJson = JSON.parse(fs.readFileSync(path.join(pkg.root, 'package.json'), 'utf8'));
let name = pkgJson['name'];
let bin = {};
Object.keys(pkgJson['bin'] || {}).forEach(binName => {
bin[binName] = path.resolve(pkg.root, pkgJson['bin'][binName]);
});

packages[name] = {
dist: path.join(distRoot, pkg.name),
packageJson: path.join(pkg.root, 'package.json'),
root: pkg.root,
relative: path.relative(path.dirname(__dirname), pkg.root),
main: path.resolve(pkg.root, 'src/index.ts'),
bin: bin
};
return packages;
}, {});

const tools = glob.sync(path.join(toolsRoot, '**/package.json'))
.map(toolPath => path.relative(toolsRoot, path.dirname(toolPath)))
.map(toolName => {
const root = path.join(toolsRoot, toolName);
const pkgJson = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
const name = pkgJson['name'];
const dist = path.join(distRoot, toolName);

return {
name,
main: path.join(dist, pkgJson['main']),
mainTs: path.join(toolsRoot, toolName, pkgJson['main'].replace(/\.js$/, '.ts')),
root,
packageJson: path.join(toolsRoot, toolName, 'package.json'),
dist
};
})
.reduce((tools, tool) => {
tools[tool.name] = tool;
return tools;
}, {});


module.exports = { packages, tools };
35 changes: 24 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
"name": "@angular/sdk",
"name": "@angular/devkit",
"version": "0.0.0",
"description": "Software Development Kit for Angular",
"bin": {
"sdk-admin": "./bin/sdk-admin"
"devkit-admin": "./bin/devkit-admin",
"schematics": "./bin/schematics"
},
"keywords": [],
"scripts": {},
"scripts": {
"admin": "./bin/devkit-admin",
"build": "tsc -p tsconfig.json",
"fix": "npm run lint -- --fix",
"lint": "tslint --config tslint.json --project tsconfig.json --type-check",
"test": "./bin/devkit-admin test"
},
"repository": {
"type": "git",
"url": "https://github.com/angular/sdk.git"
"url": "https://github.com/angular/devkit.git"
},
"engines": {
"node": ">= 6.9.0",
Expand All @@ -18,32 +25,38 @@
"author": "Angular Authors",
"license": "MIT",
"bugs": {
"url": "https://github.com/angular/sdk/issues"
"url": "https://github.com/angular/devkit/issues"
},
"homepage": "https://github.com/angular/sdk",
"homepage": "https://github.com/angular/devkit",
"dependencies": {
"@ngtools/json-schema": "^1.0.9",
"@ngtools/logger": "^1.0.1",
"@types/chalk": "^0.4.28",
"@types/common-tags": "^1.2.4",
"@types/glob": "^5.0.29",
"@types/jasmine": "~2.2.0",
"@types/istanbul": "^0.4.29",
"@types/jasmine": "^2.5.47",
"@types/minimist": "^1.2.0",
"@types/node": "^6.0.36",
"@types/semver": "^5.3.30",
"chai": "^3.5.0",
"@types/source-map": "^0.5.0",
"chalk": "^1.1.3",
"common-tags": "^1.3.1",
"conventional-changelog": "^1.1.0",
"glob": "^7.0.3",
"jasmine": "^2.4.1",
"istanbul": "^0.4.5",
"jasmine": "^2.6.0",
"jasmine-spec-reporter": "^3.2.0",
"minimatch": "^3.0.3",
"marked-terminal": "^2.0.0",
"minimist": "^1.2.0",
"npm-run": "^4.1.0",
"npm-run-all": "^4.0.0",
"rxjs": "^5.0.1",
"semver": "^5.3.0",
"source-map": "^0.5.6",
"temp": "^0.8.3",
"ts-node": "^2.0.0",
"tslint": "^4.0.2",
"typescript": "~2.2.0"
"typescript": "~2.3.0"
}
}
24 changes: 24 additions & 0 deletions packages/schematics/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package(default_visibility=["//visibility:private"])
load("@io_bazel_rules_typescript//:defs.bzl", "ts_library")

exports_files(["tsconfig.json"])


ts_library(
name = "schematics",
srcs = [
"src/index.ts",
],
deps = [
"//packages/schematics/src/engine",
"//packages/schematics/src/exception",
"//packages/schematics/src/rules",
"//packages/schematics/src/sink",
"//packages/schematics/src/tree",
"//packages/schematics/tooling",
],
tsconfig = "//:tsconfig.json",
visibility = [ "//visibility:public" ],
module_name = "@angular/schematics",
module_root = "src"
)
Loading