Skip to content

refactor(all): Repackaging #2056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 12, 2016
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ tmp/
typings/

# Ignore all blueprint files. We e2e tests those later on.
addon/ng2/blueprints/*/files/
packages/angular-cli/blueprints/*/files/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
- DBUS_SESSION_BUS_ADDRESS=/dev/null
matrix:
- SCRIPT=lint
# - SCRIPT=build
- SCRIPT=build
- SCRIPT=e2e
- SCRIPT=e2e:nightly
- SCRIPT=test
Expand Down
37 changes: 0 additions & 37 deletions addon/ng2/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions addon/ng2/package.json

This file was deleted.

45 changes: 1 addition & 44 deletions bin/ng
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,5 @@
// Provide a title to the process in `ps`
process.title = 'angular-cli';

const resolve = require('resolve');
const exit = require('exit');
const packageJson = require('../package.json');
const Leek = require('leek');

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


resolve('angular-cli', { basedir: process.cwd() },
function (error, projectLocalCli) {
var cli;
if (error) {
// If there is an error, resolve could not find the ng-cli
// library from a package.json. Instead, include it from a relative
// path to this script file (which is likely a globally installed
// npm package). Most common cause for hitting this is `ng new`
cli = require('../lib/cli');
} else {
// No error implies a projectLocalCli, which will load whatever
// version of ng-cli you have installed in a local package.json
cli = require(projectLocalCli);
}

if ('default' in cli) {
cli = cli['default'];
}

cli({
cliArgs: process.argv.slice(2),
inputStream: process.stdin,
outputStream: process.stdout,
Leek: CustomLeek
}).then(function (result) {
var exitCode = typeof result === 'object' ? result.exitCode : result;
exit(exitCode);
});

function CustomLeek(options) {
options.trackingCode = packageJson.trackingCode;
options.globalName = packageJson.name;
options.name = packageJson.name;
options.version = packageJson.version;
return new Leek(options);
}
});
require('../packages/angular-cli/bin/ng');
6 changes: 0 additions & 6 deletions index.js

This file was deleted.

8 changes: 8 additions & 0 deletions lib/bootstrap-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const path = require('path');
const ts = require('typescript');


global.angularCliIsLocal = true;

const compilerOptions = JSON.parse(fs.readFileSync(path.join(__dirname, '../tsconfig.json')));

const oldRequireTs = require.extensions['.ts'];
Expand Down Expand Up @@ -51,6 +53,12 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
Module._load = function (request, parent) {
if (request in packages) {
return oldLoad.call(this, packages[request].main, parent);
} 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);
const newRequest = path.relative(dir, path.join(__dirname, '../packages', request));
return oldLoad.call(this, newRequest, parent);
} else {
return oldLoad.apply(this, arguments);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/packages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

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

Expand All @@ -9,7 +11,8 @@ const packages = fs.readdirSync(packageRoot)
.map(pkgName => ({ name: pkgName, root: path.join(packageRoot, pkgName) }))
.filter(pkg => fs.statSync(pkg.root).isDirectory())
.reduce((packages, pkg) => {
packages[`@angular-cli/${pkg.name}`] = {
let name = pkg == 'angular-cli' ? 'angular-cli' : `@angular-cli/${pkg.name}`;
packages[name] = {
root: pkg.root,
main: path.resolve(pkg.root, 'src/index.ts')
};
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "angular-cli",
"version": "1.0.0-beta.11-webpack.8",
"version": "0.0.0",
"description": "CLI tool for Angular",
"main": "lib/cli/index.js",
"main": "packages/angular-cli/lib/cli/index.js",
"trackingCode": "UA-8594346-19",
"bin": {
"ng": "./bin/ng"
},
"keywords": [],
"scripts": {
"build": "npm-run-all -c build:main build:packages",
"build:main": "tsc -p addon/ng2",
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -P $PKG; done",
"build": "node ./scripts/publish/build.js",
"build:patch": "node ./scripts/patch.js",
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -p $PKG; done",
"test": "npm run test:packages && npm run test:cli",
"e2e": "npm run test:e2e",
"e2e:nightly": "node tests/e2e_runner.js --nightly",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@angular/compiler": "^2.0.0-rc.6",
"@angular/compiler-cli": "^0.6.0",
"@angular/core": "^2.0.0-rc.6",
"@angular/tsc-wrapped": "^0.2.2",
"@angular/tsc-wrapped": "^0.3.0",
"angular2-template-loader": "^0.5.0",
"awesome-typescript-loader": "^2.2.3",
"chalk": "^1.1.3",
Expand Down Expand Up @@ -113,13 +113,13 @@
},
"ember-addon": {
"paths": [
"./addon/ng2/"
"./packages/angular-cli/lib/addon"
]
},
"devDependencies": {
"@types/chai": "^3.4.32",
"@types/chalk": "^0.4.28",
"@types/common-tags": "^1.2.3",
"@types/common-tags": "^1.2.4",
"@types/denodeify": "^1.2.29",
"@types/express": "^4.0.32",
"@types/fs-extra": "^0.0.31",
Expand All @@ -143,8 +143,10 @@
"minimist": "^1.2.0",
"mocha": "^2.4.5",
"mock-fs": "3.10.0",
"npm-run": "^4.1.0",
"object-assign": "^4.0.1",
"request": "^2.74.0",
"resolve-bin": "^0.4.0",
"rewire": "^2.5.1",
"sinon": "^1.17.3",
"through": "^2.3.8",
Expand Down
42 changes: 42 additions & 0 deletions packages/angular-cli/addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* jshint node: true */
'use strict';

const config = require('../models/config');
const path = require('path');

module.exports = {
name: 'ng2',

config: function () {
this.project.ngConfig = this.project.ngConfig || config.CliConfig.fromProject().config;
},

blueprintsPath: function () {
return path.join(__dirname, '../blueprints');
},

includedCommands: function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing help command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oopsie. done.

return {
'build': require('../commands/build').default,
'serve': require('../commands/serve').default,
'new': require('../commands/new').default,
'generate': require('../commands/generate').default,
'init': require('../commands/init').default,
'test': require('../commands/test').default,
'e2e': require('../commands/e2e').default,
'help': require('../commands/help').default,
'lint': require('../commands/lint').default,
'version': require('../commands/version').default,
'completion': require('../commands/completion').default,
'doc': require('../commands/doc').default,
'github-pages-deploy': require('../commands/github-pages-deploy').default,

// Easter eggs.
'make-this-awesome': require('../commands/easter-egg').default,

// Configuration.
'set': require('../commands/set').default,
'get': require('../commands/get').default
};
}
};
49 changes: 49 additions & 0 deletions packages/angular-cli/bin/ng
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env node
'use strict';

// Provide a title to the process in `ps`
process.title = 'angular-cli';

const resolve = require('resolve');
const exit = require('exit');
const packageJson = require('../package.json');
const Leek = require('leek');


resolve('angular-cli', { basedir: process.cwd() },
function (error, projectLocalCli) {
var cli;
if (error) {
// If there is an error, resolve could not find the ng-cli
// library from a package.json. Instead, include it from a relative
// path to this script file (which is likely a globally installed
// npm package). Most common cause for hitting this is `ng new`
cli = require('../lib/cli');
} else {
// No error implies a projectLocalCli, which will load whatever
// version of ng-cli you have installed in a local package.json
cli = require(projectLocalCli);
}

if ('default' in cli) {
cli = cli['default'];
}

cli({
cliArgs: process.argv.slice(2),
inputStream: process.stdin,
outputStream: process.stdout,
Leek: CustomLeek
}).then(function (result) {
var exitCode = typeof result === 'object' ? result.exitCode : result;
exit(exitCode);
});

function CustomLeek(options) {
options.trackingCode = packageJson.trackingCode;
options.globalName = packageJson.name;
options.name = packageJson.name;
options.version = packageJson.version;
return new Leek(options);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module.exports = function (config) {
config.set({
basePath: './',
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {

locals: function(options) {
this.styleExt = options.style;
this.version = require(path.resolve(__dirname, '../../../../package.json')).version;
this.version = require(path.resolve(__dirname, '../../package.json')).version;

// Join with / not path.sep as reference to typings require forward slashes.
const relativeRootPath = options.sourceDir.split(path.sep).map(() => '..').join('/');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ const InitCommand: any = Command.extend({
anonymousOptions: ['<glob-pattern>'],

_defaultBlueprint: function () {
if (this.project.isEmberCLIAddon()) {
return 'addon';
} else {
return 'ng2';
}
return 'ng2';
},

run: function (commandOptions: any, rawArgs: string[]) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as denodeify from 'denodeify';
const Command = require('ember-cli/lib/models/command');
const SilentError = require('silent-error');
const PortFinder = require('portfinder');
import ServeWebpackTask from '../tasks/serve-webpack.ts';
import ServeWebpackTask from '../tasks/serve-webpack';

PortFinder.basePort = 49152;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const VersionCommand = Command.extend({

run: function (options: any) {
const versions: any = process.versions;
const pkg = require(path.resolve(__dirname, '..', '..', '..', 'package.json'));
const pkg = require(path.resolve(__dirname, '..', 'package.json'));

versions['os'] = process.platform + ' ' + process.arch;

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/cli/index.js → packages/angular-cli/lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const cli = require('ember-cli/lib/cli');
const path = require('path');

Error.stackTraceLimit = Infinity;

module.exports = function(options) {
const oldStdoutWrite = process.stdout.write;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CliConfig as CliConfigBase} from './config/config';
import {CliConfig as ConfigInterface} from '../../../lib/config/schema';
import {CliConfig as ConfigInterface} from '../lib/config/schema';
import { oneLine } from 'common-tags';
import * as chalk from 'chalk';
import * as fs from 'fs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import {SchemaClass, SchemaClassFactory} from '../json-schema/schema-class-factory';


const DEFAULT_CONFIG_SCHEMA_PATH = path.join(__dirname, '../../../../lib/config/schema.json');
const DEFAULT_CONFIG_SCHEMA_PATH = path.join(__dirname, '../../lib/config/schema.json');


export class InvalidConfigError extends Error {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function findLoadChildren(tsFilePath: string): string[] {
}


export function findLazyModules(projectRoot: any): string[] {
export function findLazyModules(projectRoot: any): {[key: string]: string} {
const result: {[key: string]: string} = {};
glob.sync(path.join(projectRoot, '/**/*.ts'))
.forEach(tsPath => {
Expand Down
File renamed without changes.
Loading