mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 05:52:41 +08:00
refactor(@angular/cli): remove unused ember task abstraction
This commit is contained in:
parent
f6f774a3b0
commit
c84f19bcfa
8
package-lock.json
generated
8
package-lock.json
generated
@ -1127,14 +1127,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.4.tgz",
|
||||||
"integrity": "sha1-8si/GB8qgLkvNgEhQpzmOi8K6uA="
|
"integrity": "sha1-8si/GB8qgLkvNgEhQpzmOi8K6uA="
|
||||||
},
|
},
|
||||||
"core-object": {
|
|
||||||
"version": "3.1.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/core-object/-/core-object-3.1.5.tgz",
|
|
||||||
"integrity": "sha512-sA2/4+/PZ/KV6CKgjrVrrUVBKCkdDO02CUlQ0YKTQoYUwPYNOtOAcWlbYhd5v/1JqYaA6oZ4sDlOU4ppVw6Wbg==",
|
|
||||||
"requires": {
|
|
||||||
"chalk": "2.2.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
"@schematics/update": "0.5.0",
|
"@schematics/update": "0.5.0",
|
||||||
"chalk": "~2.2.0",
|
"chalk": "~2.2.0",
|
||||||
"common-tags": "^1.3.1",
|
"common-tags": "^1.3.1",
|
||||||
"core-object": "^3.1.0",
|
|
||||||
"ember-cli-string-utils": "^1.0.0",
|
"ember-cli-string-utils": "^1.0.0",
|
||||||
"fs-extra": "^4.0.0",
|
"fs-extra": "^4.0.0",
|
||||||
"lodash": "^4.11.1",
|
"lodash": "^4.11.1",
|
||||||
|
@ -14,42 +14,23 @@ process.setMaxListeners(1000);
|
|||||||
|
|
||||||
// Options: Array cliArgs, Stream inputStream, Stream outputStream
|
// Options: Array cliArgs, Stream inputStream, Stream outputStream
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
let UI = options.UI || require('../ui');
|
|
||||||
const CLI = require('./cli');
|
const CLI = require('./cli');
|
||||||
const Project = require('../models/project');
|
const Project = require('../models/project');
|
||||||
|
|
||||||
// TODO: one UI (lib/models/project.js also has one for now...)
|
|
||||||
let ui = new UI({
|
|
||||||
inputStream: options.inputStream,
|
|
||||||
outputStream: options.outputStream,
|
|
||||||
errorStream: options.errorStream || process.stderr,
|
|
||||||
errorLog: options.errorLog || [],
|
|
||||||
ci: process.env.CI || (/^(dumb|emacs)$/).test(process.env.TERM),
|
|
||||||
writeLevel: (process.argv.indexOf('--silent') !== -1) ? 'ERROR' : undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
let defaultUpdateCheckerOptions = {
|
|
||||||
// checkForUpdates: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let cli = new CLI({
|
let cli = new CLI({
|
||||||
ui,
|
|
||||||
testing: options.testing,
|
testing: options.testing,
|
||||||
name: options.cli ? options.cli.name : 'ember',
|
name: options.cli ? options.cli.name : 'ember',
|
||||||
disableDependencyChecker: options.disableDependencyChecker,
|
|
||||||
root: options.cli ? options.cli.root : path.resolve(__dirname, '..', '..'),
|
root: options.cli ? options.cli.root : path.resolve(__dirname, '..', '..'),
|
||||||
npmPackage: options.cli ? options.cli.npmPackage : 'ember-cli',
|
npmPackage: options.cli ? options.cli.npmPackage : 'ember-cli',
|
||||||
});
|
});
|
||||||
|
|
||||||
let project = Project.projectOrnullProject(ui, cli);
|
let project = Project.projectOrnullProject(undefined, cli);
|
||||||
|
|
||||||
let environment = {
|
let environment = {
|
||||||
tasks: options.tasks || {},
|
tasks: options.tasks || {},
|
||||||
cliArgs: options.cliArgs,
|
cliArgs: options.cliArgs,
|
||||||
commands: options.commands || {},
|
commands: options.commands || {},
|
||||||
project,
|
project,
|
||||||
settings: defaultUpdateCheckerOptions,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return cli.run(environment);
|
return cli.run(environment);
|
||||||
|
@ -239,7 +239,6 @@ class Project {
|
|||||||
static closest(pathName, _ui, _cli) {
|
static closest(pathName, _ui, _cli) {
|
||||||
let ui = ensureUI(_ui);
|
let ui = ensureUI(_ui);
|
||||||
|
|
||||||
ui.writeDeprecateLine('`Project.closest` is a private method that will be removed, please use `Project.closestSync` instead.');
|
|
||||||
|
|
||||||
return closestPackageJSON(pathName).then(result => {
|
return closestPackageJSON(pathName).then(result => {
|
||||||
if (result.pkg && result.pkg.name === 'ember-cli') {
|
if (result.pkg && result.pkg.name === 'ember-cli') {
|
||||||
@ -345,17 +344,6 @@ function ensureInstrumentation(cli, ui) {
|
|||||||
function ensureUI(_ui) {
|
function ensureUI(_ui) {
|
||||||
let ui = _ui;
|
let ui = _ui;
|
||||||
|
|
||||||
if (!ui) {
|
|
||||||
// TODO: one UI (lib/cli/index.js also has one for now...)
|
|
||||||
const UI = require('../ui');
|
|
||||||
ui = new UI({
|
|
||||||
inputStream: process.stdin,
|
|
||||||
outputStream: process.stdout,
|
|
||||||
ci: process.env.CI || (/^(dumb|emacs)$/).test(process.env.TERM),
|
|
||||||
writeLevel: (process.argv.indexOf('--silent') !== -1) ? 'ERROR' : undefined,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const CoreObject = require('core-object');
|
|
||||||
|
|
||||||
class Task extends CoreObject {
|
|
||||||
run(/*options*/) {
|
|
||||||
throw new Error('Task needs to have run() defined.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interrupt comamd with an exit code
|
|
||||||
* Called when the process is interrupted from outside, e.g. CTRL+C or `process.kill()`
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @method onInterrupt
|
|
||||||
*/
|
|
||||||
onInterrupt() {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Task;
|
|
@ -1,196 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var EOL = require('os').EOL;
|
|
||||||
var chalk = require('chalk');
|
|
||||||
var writeError = require('./write-error');
|
|
||||||
|
|
||||||
var DEFAULT_WRITE_LEVEL = 'INFO';
|
|
||||||
|
|
||||||
// Note: You should use `ui.outputStream`, `ui.inputStream` and `ui.write()`
|
|
||||||
// instead of `process.stdout` and `console.log`.
|
|
||||||
// Thus the pleasant progress indicator automatically gets
|
|
||||||
// interrupted and doesn't mess up the output! -> Convenience :P
|
|
||||||
|
|
||||||
module.exports = UI;
|
|
||||||
|
|
||||||
/*
|
|
||||||
@constructor
|
|
||||||
|
|
||||||
The UI provides the CLI with a unified mechanism for providing output and
|
|
||||||
requesting input from the user. This becomes useful when wanting to adjust
|
|
||||||
logLevels, or mock input/output for tests.
|
|
||||||
|
|
||||||
new UI({
|
|
||||||
inputStream: process.stdin,
|
|
||||||
outputStream: process.stdout,
|
|
||||||
writeLevel: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR',
|
|
||||||
ci: true | false
|
|
||||||
});
|
|
||||||
|
|
||||||
**/
|
|
||||||
|
|
||||||
function UI(options) {
|
|
||||||
// Output stream
|
|
||||||
this.outputStream = options.outputStream;
|
|
||||||
this.inputStream = options.inputStream;
|
|
||||||
this.errorStream = options.errorStream;
|
|
||||||
|
|
||||||
this.errorLog = options.errorLog || [];
|
|
||||||
this.writeLevel = options.writeLevel || DEFAULT_WRITE_LEVEL;
|
|
||||||
this.ci = !!options.ci;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Unified mechanism to write a string to the console.
|
|
||||||
Optionally include a writeLevel, this is used to decide if the specific
|
|
||||||
logging mechanism should or should not be printed.
|
|
||||||
|
|
||||||
@method write
|
|
||||||
@param {String} data
|
|
||||||
@param {Number} writeLevel
|
|
||||||
*/
|
|
||||||
UI.prototype.write = function(data, writeLevel) {
|
|
||||||
if (writeLevel === 'ERROR') {
|
|
||||||
this.errorStream.write(data);
|
|
||||||
} else if (this.writeLevelVisible(writeLevel)) {
|
|
||||||
this.outputStream.write(data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Unified mechanism to write a string and new line to the console.
|
|
||||||
Optionally include a writeLevel, this is used to decide if the specific
|
|
||||||
logging mechanism should or should not be printed.
|
|
||||||
@method writeLine
|
|
||||||
@param {String} data
|
|
||||||
@param {Number} writeLevel
|
|
||||||
*/
|
|
||||||
UI.prototype.writeLine = function(data, writeLevel) {
|
|
||||||
this.write(data + EOL, writeLevel);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Helper method to write a string with the DEBUG writeLevel and gray chalk
|
|
||||||
@method writeDebugLine
|
|
||||||
@param {String} data
|
|
||||||
*/
|
|
||||||
UI.prototype.writeDebugLine = function(data) {
|
|
||||||
this.writeLine(chalk.gray(data), 'DEBUG');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Helper method to write a string with the INFO writeLevel and cyan chalk
|
|
||||||
@method writeInfoLine
|
|
||||||
@param {String} data
|
|
||||||
*/
|
|
||||||
UI.prototype.writeInfoLine = function(data) {
|
|
||||||
this.writeLine(chalk.cyan(data), 'INFO');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Helper method to write a string with the WARNING writeLevel and yellow chalk.
|
|
||||||
Optionally include a test. If falsy, the warning will be printed. By default, warnings
|
|
||||||
will be prepended with WARNING text when printed.
|
|
||||||
@method writeWarnLine
|
|
||||||
@param {String} data
|
|
||||||
@param {Boolean} test
|
|
||||||
@param {Boolean} prepend
|
|
||||||
*/
|
|
||||||
UI.prototype.writeWarnLine = function(data, test, prepend) {
|
|
||||||
if (test) { return; }
|
|
||||||
|
|
||||||
data = this.prependLine('WARNING', data, prepend);
|
|
||||||
this.writeLine(chalk.yellow(data), 'WARNING', test);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Helper method to write a string with the WARNING writeLevel and yellow chalk.
|
|
||||||
Optionally include a test. If falsy, the deprecation will be printed. By default deprecations
|
|
||||||
will be prepended with DEPRECATION text when printed.
|
|
||||||
@method writeDeprecateLine
|
|
||||||
@param {String} data
|
|
||||||
@param {Boolean} test
|
|
||||||
@param {Boolean} prepend
|
|
||||||
*/
|
|
||||||
UI.prototype.writeDeprecateLine = function(data, test, prepend) {
|
|
||||||
data = this.prependLine('DEPRECATION', data, prepend);
|
|
||||||
this.writeWarnLine(data, test, false);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Utility method to prepend a line with a flag-like string (i.e., WARNING).
|
|
||||||
@method prependLine
|
|
||||||
@param {String} prependData
|
|
||||||
@param {String} data
|
|
||||||
@param {Boolean} prepend
|
|
||||||
*/
|
|
||||||
UI.prototype.prependLine = function(prependData, data, prepend) {
|
|
||||||
if (typeof prepend === 'undefined' || prepend) {
|
|
||||||
data = prependData + ': ' + data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Unified mechanism to an Error to the console.
|
|
||||||
This will occure at a writeLevel of ERROR
|
|
||||||
|
|
||||||
@method writeError
|
|
||||||
@param {Error} error
|
|
||||||
*/
|
|
||||||
UI.prototype.writeError = function(error) {
|
|
||||||
writeError(this, error);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Sets the write level for the UI. Valid write levels are 'DEBUG', 'INFO',
|
|
||||||
'WARNING', and 'ERROR'.
|
|
||||||
|
|
||||||
@method setWriteLevel
|
|
||||||
@param {String} level
|
|
||||||
*/
|
|
||||||
UI.prototype.setWriteLevel = function(level) {
|
|
||||||
if (Object.keys(this.WRITE_LEVELS).indexOf(level) === -1) {
|
|
||||||
throw new Error('Unknown write level. Valid values are \'DEBUG\', \'INFO\', \'WARNING\', and \'ERROR\'.');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.writeLevel = level;
|
|
||||||
};
|
|
||||||
|
|
||||||
UI.prototype.startProgress = function(message/*, stepString*/) {
|
|
||||||
if (this.writeLevelVisible('INFO')) {
|
|
||||||
this.writeLine(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
UI.prototype.stopProgress = function() {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
@property WRITE_LEVELS
|
|
||||||
@private
|
|
||||||
@type Object
|
|
||||||
*/
|
|
||||||
UI.prototype.WRITE_LEVELS = {
|
|
||||||
'DEBUG': 1,
|
|
||||||
'INFO': 2,
|
|
||||||
'WARNING': 3,
|
|
||||||
'ERROR': 4
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Whether or not the specified write level should be printed by this UI.
|
|
||||||
|
|
||||||
@method writeLevelVisible
|
|
||||||
@private
|
|
||||||
@param {String} writeLevel
|
|
||||||
@return {Boolean}
|
|
||||||
*/
|
|
||||||
UI.prototype.writeLevelVisible = function(writeLevel) {
|
|
||||||
var levels = this.WRITE_LEVELS;
|
|
||||||
writeLevel = writeLevel || DEFAULT_WRITE_LEVEL;
|
|
||||||
|
|
||||||
return levels[writeLevel] >= levels[this.writeLevel];
|
|
||||||
};
|
|
@ -1,25 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
var chalk = require('chalk');
|
|
||||||
|
|
||||||
module.exports = function writeError(ui, error) {
|
|
||||||
if (!error) { return; }
|
|
||||||
|
|
||||||
// Uglify errors have a filename instead
|
|
||||||
var fileName = error.file || error.filename;
|
|
||||||
if (fileName) {
|
|
||||||
if (error.line) {
|
|
||||||
fileName += error.col ? ' (' + error.line + ':' + error.col + ')' : ' (' + error.line + ')';
|
|
||||||
}
|
|
||||||
ui.writeLine(chalk.red('File: ' + fileName), 'ERROR');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error.message) {
|
|
||||||
ui.writeLine(chalk.red(error.message), 'ERROR');
|
|
||||||
} else {
|
|
||||||
ui.writeLine(chalk.red(error), 'ERROR');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error.stack) {
|
|
||||||
ui.writeLine(error.stack, 'ERROR');
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,7 +1,6 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const cli = require('../../ember-cli/lib/cli');
|
const cli = require('../../ember-cli/lib/cli');
|
||||||
const UI = require('../../ember-cli/lib/ui');
|
|
||||||
|
|
||||||
|
|
||||||
function loadCommands() {
|
function loadCommands() {
|
||||||
@ -30,10 +29,6 @@ function loadCommands() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function(options: any) {
|
export default function(options: any) {
|
||||||
|
|
||||||
// patch UI to not print Ember-CLI warnings (which don't apply to Angular CLI)
|
|
||||||
UI.prototype.writeWarnLine = function () { };
|
|
||||||
|
|
||||||
options.cli = {
|
options.cli = {
|
||||||
name: 'ng',
|
name: 'ng',
|
||||||
root: path.join(__dirname, '..', '..'),
|
root: path.join(__dirname, '..', '..'),
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
"@schematics/update": "0.5.0",
|
"@schematics/update": "0.5.0",
|
||||||
"chalk": "~2.2.0",
|
"chalk": "~2.2.0",
|
||||||
"common-tags": "^1.3.1",
|
"common-tags": "^1.3.1",
|
||||||
"core-object": "^3.1.0",
|
|
||||||
"ember-cli-string-utils": "^1.0.0",
|
"ember-cli-string-utils": "^1.0.0",
|
||||||
"fs-extra": "^4.0.0",
|
"fs-extra": "^4.0.0",
|
||||||
"lodash": "^4.11.1",
|
"lodash": "^4.11.1",
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
import { requireProjectModule } from '../utilities/require-project-module';
|
|
||||||
import { join } from 'path';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const Task = require('../ember-cli/lib/models/task');
|
|
||||||
|
|
||||||
export interface RenderUniversalTaskOptions {
|
|
||||||
inputIndexPath: string;
|
|
||||||
route: string;
|
|
||||||
serverOutDir: string;
|
|
||||||
outputIndexPath: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Task.extend({
|
|
||||||
run: function(options: RenderUniversalTaskOptions): Promise<any> {
|
|
||||||
requireProjectModule(this.project.root, 'zone.js/dist/zone-node');
|
|
||||||
|
|
||||||
const renderModuleFactory =
|
|
||||||
requireProjectModule(this.project.root, '@angular/platform-server').renderModuleFactory;
|
|
||||||
|
|
||||||
// Get the main bundle from the server build's output directory.
|
|
||||||
const serverDir = fs.readdirSync(options.serverOutDir);
|
|
||||||
const serverMainBundle = serverDir
|
|
||||||
.filter((file: string) => /main\.(?:[a-zA-Z0-9]{20}\.)?js/.test(file))[0];
|
|
||||||
const serverBundlePath = join(options.serverOutDir, serverMainBundle);
|
|
||||||
const AppServerModuleNgFactory = require(serverBundlePath).AppServerModuleNgFactory;
|
|
||||||
|
|
||||||
const index = fs.readFileSync(options.inputIndexPath, 'utf8');
|
|
||||||
// Render to HTML and overwrite the client index file.
|
|
||||||
return renderModuleFactory(AppServerModuleNgFactory, {document: index, url: options.route})
|
|
||||||
.then((html: string) => fs.writeFileSync(options.outputIndexPath, html));
|
|
||||||
}
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user