Skip to content

Commit 5c1dc24

Browse files
committed
build: add build script for making the right npm package format
Bazel is not ready yet to be used.
1 parent 7833f74 commit 5c1dc24

File tree

19 files changed

+395
-143
lines changed

19 files changed

+395
-143
lines changed

bin/devkit-admin

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/usr/bin/env node
2+
/**
3+
* @license
4+
* Copyright Google Inc. All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.io/license
8+
*/
29
'use strict';
310

411
/**

bin/schematics

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env node
2+
/**
3+
* @license
4+
* Copyright Google Inc. All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.io/license
8+
*/
29
'use strict';
10+
11+
312
require('../lib/bootstrap-local');
413
const packages = require('../lib/packages').packages;
5-
6-
require(packages['@angular/schematics-cli'].bin['schematics']);
14+
require(packages['@_/schematics-cli'].bin['schematics']);

lib/bootstrap-local.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Error.stackTraceLimit = Infinity;
1717

1818
global._DevKitIsLocal = true;
1919
global._DevKitRoot = path.resolve(__dirname, '..');
20-
global._DevKitPackages = require('./packages').packages;
21-
global._DevKitTools = require('./packages').tools;
2220

2321
global._DevKitRequireHook = null;
2422

lib/packages.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

lib/packages.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
'use strict';
9+
10+
import * as fs from 'fs';
11+
import * as glob from 'glob';
12+
import * as path from 'path';
13+
14+
const packageRoot = path.join(__dirname, '../packages');
15+
const distRoot = path.join(__dirname, '../dist');
16+
17+
18+
export interface PackageInfo {
19+
name: string;
20+
root: string;
21+
bin: { [name: string]: string};
22+
relative: string;
23+
main: string;
24+
dist: string;
25+
tsConfig?: string;
26+
packageJson: string;
27+
dependencies: string[];
28+
}
29+
export type PackageMap = { [name: string]: PackageInfo };
30+
31+
32+
const packageJsonPaths =
33+
glob.sync(path.join(packageRoot, '**/package.json'))
34+
// Removing all files from templates.
35+
.filter(p => !p.match(/\/angular.*files\//));
36+
37+
38+
// All the supported packages. Go through the packages directory and create a _map of
39+
// name => fullPath.
40+
export const packages: PackageMap =
41+
packageJsonPaths
42+
.map(pkgPath => [pkgPath, path.relative(packageRoot, path.dirname(pkgPath))])
43+
.map(([pkgPath, pkgName]) => {
44+
return { name: pkgName, root: path.dirname(pkgPath) };
45+
})
46+
.reduce((packages: PackageMap, pkg) => {
47+
const pkgRoot = pkg.root;
48+
let pkgJson = require(path.join(pkgRoot, 'package.json'));
49+
let name = pkgJson['name'];
50+
let bin: {[name: string]: string} = {};
51+
Object.keys(pkgJson['bin'] || {}).forEach(binName => {
52+
bin[binName] = path.resolve(pkg.root, pkgJson['bin'][binName]);
53+
});
54+
55+
let tsConfig: string | undefined = path.resolve(pkgRoot, 'tsconfig.json');
56+
if (!fs.existsSync(tsConfig)) {
57+
tsConfig = undefined;
58+
}
59+
60+
packages[name] = {
61+
dist: path.join(distRoot, name),
62+
packageJson: path.join(pkgRoot, 'package.json'),
63+
root: pkgRoot,
64+
relative: path.relative(path.dirname(__dirname), pkgRoot),
65+
main: path.resolve(pkgRoot, 'src/index.ts'),
66+
bin,
67+
tsConfig,
68+
name,
69+
dependencies: []
70+
};
71+
return packages;
72+
}, {});
73+
74+
75+
// Update with dependencies.
76+
for (const pkgName of Object.keys(packages)) {
77+
const pkg = packages[pkgName];
78+
const pkgJson = require(path.join(pkg.root, 'package.json'));
79+
pkg.dependencies = Object.keys(packages).filter(name => {
80+
return name in (pkgJson.dependencies || {})
81+
|| name in (pkgJson.devDependencies || {})
82+
|| name in (pkgJson.peerDependencies || {});
83+
});
84+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"jasmine-spec-reporter": "^3.2.0",
5050
"marked-terminal": "^2.0.0",
5151
"minimist": "^1.2.0",
52-
"npm-run": "^4.1.0",
52+
"npm-run": "^4.1.2",
5353
"npm-run-all": "^4.0.0",
5454
"rxjs": "^5.0.1",
5555
"semver": "^5.3.0",

packages/_schematics_cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@angular/schematics-cli",
2+
"name": "@_/schematics-cli",
33
"version": "0.0.0",
44
"description": "CLI tool for Angular",
55
"main": "src/cli.js",
@@ -30,6 +30,7 @@
3030
},
3131
"homepage": "https://github.com/angular/devkit",
3232
"dependencies": {
33-
"@angular/schematics": "0.0.0"
33+
"@angular/schematics": "0.0.0",
34+
"@angular/schematics-tools": "0.0.0"
3435
}
3536
}

packages/_schematics_cli/src/index.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
4+
"compilerOptions": {
5+
"outDir": "../../dist/@_/schematics-cli",
6+
"rootDir": ".",
7+
"baseUrl": "",
8+
"paths": {
9+
"@angular/schematics": [ "../../dist/@angular/schematics/src/index" ],
10+
"@angular/schematics-tools": [ "../../dist/@angular/schematics-tools/src/index" ]
11+
}
12+
}
13+
}

packages/angular/schematics/src/sink/virtual-filesystem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import {UpdateBuffer} from '../utility/update-buffer';
1313
import {Observable} from 'rxjs/Observable';
1414
import 'rxjs/add/observable/empty';
1515
import 'rxjs/add/observable/of';
16-
import 'rxjs/add/observable/map';
1716
import 'rxjs/add/observable/merge';
1817
import 'rxjs/add/observable/concat';
19-
import 'rxjs/add/operator/reduce';
2018
import 'rxjs/add/operator/do';
19+
import 'rxjs/add/operator/map';
20+
import 'rxjs/add/operator/reduce';
2121

2222

2323
export interface VirtualFileSystemSinkHost {

0 commit comments

Comments
 (0)