Skip to content

Introduce tslint npm script task #1835

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

Closed
wants to merge 28 commits into from
Closed
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
13 changes: 9 additions & 4 deletions addon/ng2/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ module.exports = Command.extend({
aliases: ['b'],

availableOptions: [
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
{ name: 'environment', type: String, default: '', aliases: ['e'] },
{ name: 'target', type: String, default: 'development', aliases: [
't',
{ 'dev': 'development' },
{ 'prod': 'production' }
]
},
{ name: 'environment', type: String, default: '', aliases: ['e'] },
{ name: 'output-path', type: 'Path', default: 'dist/', aliases: ['o'] },
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
{ name: 'watcher', type: String },
{ name: 'suppress-sizes', type: Boolean, default: false }
],

run: function (commandOptions: BuildOptions) {
if (commandOptions.environment === ''){
if (commandOptions.environment === '') {
if (commandOptions.target === 'development') {
commandOptions.environment = 'dev';
}
if (commandOptions.target === 'production') {
commandOptions.environment = 'prod';
}
}
}

var project = this.project;
Expand Down
6 changes: 3 additions & 3 deletions addon/ng2/commands/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const DocCommand = Command.extend({
'<keyword>'
],

run: function(commandOptions, rawArgs:Array<string>) {
run: function(commandOptions, rawArgs: Array<string>) {
var keyword = rawArgs[0];

var docTask = new DocTask({
ui: this.ui,
analytics: this.analytics,
Expand All @@ -23,4 +23,4 @@ const DocCommand = Command.extend({
}
});

module.exports = DocCommand;
module.exports = DocCommand;
6 changes: 3 additions & 3 deletions addon/ng2/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const GenerateCommand = EmberGenerateCommand.extend({
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
}

// Override default help to hide ember blueprints
EmberGenerateCommand.prototype.printDetailedHelp = function (options) {
var blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
var blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));

var output = '';
blueprints
.forEach(function (bp) {
Expand All @@ -38,7 +38,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
this.ui.writeLine(chalk.cyan(' Available blueprints'));
this.ui.writeLine(output);
};

return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
}
});
Expand Down
25 changes: 16 additions & 9 deletions addon/ng2/commands/github-pages-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const fsCopy = Promise.denodeify(fse.copy);
module.exports = Command.extend({
name: 'github-pages:deploy',
aliases: ['gh-pages:deploy'],
description: 'Build the test app for production, commit it into a git branch, setup GitHub repo and push to it',
description: 'Build the test app for production, \
commit it into a git branch, setup GitHub repo and push to it',
works: 'insideProject',

availableOptions: [
Expand Down Expand Up @@ -66,7 +67,7 @@ module.exports = Command.extend({
cwd: root
};

if (options.environment === ''){
if (options.environment === '') {
if (options.target === 'development') {
options.environment = 'dev';
}
Expand Down Expand Up @@ -137,7 +138,9 @@ module.exports = Command.extend({
}

function build() {
if (options.skipBuild) return Promise.resolve();
if (options.skipBuild) {
return Promise.resolve();
}
return buildTask.run(buildOptions);
}

Expand Down Expand Up @@ -165,7 +168,7 @@ module.exports = Command.extend({

function checkoutGhPages() {
return execPromise(`git checkout ${ghPagesBranch}`)
.catch(createGhPagesBranch)
.catch(createGhPagesBranch);
}

function createGhPagesBranch() {
Expand All @@ -179,16 +182,18 @@ module.exports = Command.extend({
function copyFiles() {
return fsReadDir(outDir)
.then((files) => Promise.all(files.map((file) => {
if (file === '.gitignore'){
if (file === '.gitignore') {
// don't overwrite the .gitignore file
return Promise.resolve();
}
return fsCopy(path.join(outDir, file), path.join('.', file))
return fsCopy(path.join(outDir, file), path.join('.', file));
})));
}

function updateBaseHref() {
if (options.userPage) return Promise.resolve();
if (options.userPage) {
return Promise.resolve();
}
let indexHtml = path.join(root, 'index.html');
return fsReadFile(indexHtml, 'utf8')
.then((data) => data.replace(/<base href="\/">/g, `<base href="/${projectName}/">`))
Expand All @@ -215,7 +220,8 @@ module.exports = Command.extend({
function printProjectUrl() {
return execPromise('git remote -v')
.then((stdout) => {
let userName = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m)[1].toLowerCase();
let userName = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m)
[1].toLowerCase();
let url = `https://${userName}.github.io/${options.userPage ? '' : (projectName + '/')}`;
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
Expand All @@ -225,7 +231,8 @@ module.exports = Command.extend({
function failGracefully(error) {
if (error && (/git clean/.test(error.message) || /Permission denied/.test(error.message))) {
ui.writeLine(error.message);
let msg = 'There was a permissions error during git file operations, please close any open project files/folders and try again.';
let msg = 'There was a permissions error during git file operations, \
please close any open project files/folders and try again.';
msg += `\nYou might also need to return to the ${initialBranch} branch manually.`;
return Promise.reject(new SilentError(msg));
} else {
Expand Down
32 changes: 21 additions & 11 deletions addon/ng2/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,32 @@ module.exports = Command.extend({

availableOptions: [
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
{ name: 'host', type: String, default: 'localhost', aliases: ['H'], description: 'Listens on all interfaces by default' },
{ name: 'host', type: String, default: 'localhost', aliases: ['H'],
description: 'Listens on all interfaces by default' },
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
{ name: 'live-reload-host', type: String, aliases: ['lrh'], description: 'Defaults to host' },
{ name: 'live-reload-base-url', type: String, aliases: ['lrbu'], description: 'Defaults to baseURL' },
{ name: 'live-reload-port', type: Number, aliases: ['lrp'], description: '(Defaults to port number within [49152...65535])' },
{ name: 'live-reload-live-css', type: Boolean, default: true, description: 'Whether to live reload CSS (default true)' },
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
{ name: 'live-reload-host', type: String, aliases: ['lrh'],
description: 'Defaults to host' },
{ name: 'live-reload-base-url', type: String, aliases: ['lrbu'],
description: 'Defaults to baseURL' },
{ name: 'live-reload-port', type: Number, aliases: ['lrp'],
description: '(Defaults to port number within [49152...65535])' },
{ name: 'live-reload-live-css', type: Boolean, default: true,
description: 'Whether to live reload CSS (default true)' },
{ name: 'target', type: String, default: 'development', aliases: [
't',
{ 'dev': 'development' },
{ 'prod': 'production' }
] },
{ name: 'environment', type: String, default: '', aliases: ['e'] },
{ name: 'ssl', type: Boolean, default: false },
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' }
],

run: function(commandOptions: ServeTaskOptions) {
if (commandOptions.environment === ''){
if (commandOptions.environment === '') {
if (commandOptions.target === 'development') {
commandOptions.environment = 'dev';
}
Expand All @@ -65,14 +74,15 @@ module.exports = Command.extend({

return this._checkExpressPort(commandOptions)
.then(this._autoFindLiveReloadPort.bind(this))
.then((commandOptions: ServeTaskOptions) => {
commandOptions = assign({}, commandOptions, {
baseURL: this.project.config(commandOptions.target).baseURL || '/'
.then((options: ServeTaskOptions) => {
commandOptions = assign({}, options, {
baseURL: this.project.config(options.target).baseURL || '/'
});

if (commandOptions.proxy) {
if (!commandOptions.proxy.match(/^(http:|https:)/)) {
var message = 'You need to include a protocol with the proxy URL.' + EOL + 'Try --proxy http://' + commandOptions.proxy;
var message = 'You need to include a protocol with the proxy URL.' + EOL +
'Try --proxy http://' + commandOptions.proxy;

return Promise.reject(new SilentError(message));
}
Expand Down
6 changes: 3 additions & 3 deletions addon/ng2/custom-typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interface IWebpackDevServerConfigurationOptions {
hot?: boolean;
historyApiFallback?: boolean;
compress?: boolean;
proxy?: {[key: string] : string};
proxy?: {[key: string]: string};
staticOptions?: any;
quiet?: boolean;
noInfo?: boolean;
Expand All @@ -14,8 +14,8 @@ interface IWebpackDevServerConfigurationOptions {
poll?: number;
};
publicPath?: string;
headers?: { [key:string]: string };
stats?: { [key:string]: boolean };
headers?: { [key: string]: string };
stats?: { [key: string]: boolean };
inline: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions addon/ng2/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';

const schemaPath = path.resolve(process.env.CLI_ROOT, 'lib/config/schema.json');
const schema = require(schemaPath);
// const schemaPath = path.resolve(process.env.CLI_ROOT, 'lib/config/schema.json');
// const schema = require(schemaPath);

export const CLI_CONFIG_FILE_NAME = 'angular-cli.json';

Expand Down
4 changes: 2 additions & 2 deletions addon/ng2/models/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CliConfig<Config> {
save(path: string = this._configPath) {
return fs.writeFileSync(path, this.serialize(), 'utf-8');
}
serialize(mimetype: string = 'application/json'): string {
serialize(mimetype = 'application/json'): string {
return this._config.$$serialize(mimetype);
}

Expand Down Expand Up @@ -73,7 +73,7 @@ export class CliConfig<Config> {
try {
content = JSON.parse(configContent);
schema = JSON.parse(schemaContent);
others = otherContents.map(content => JSON.parse(content));
others = otherContents.map(content_ => JSON.parse(content_));
} catch (err) {
throw new InvalidConfigError(err);
}
Expand Down
7 changes: 4 additions & 3 deletions addon/ng2/models/find-lazy-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import * as glob from 'glob';
import * as path from 'path';
import * as ts from 'typescript';

import {Observable} from 'rxjs/Observable';
// import {Observable} from 'rxjs/Observable';
import {getSource, findNodes, getContentOfKeyLiteral} from '../utilities/ast-utils';


const loadChildrenRegex = /(\{[^{}]+?(loadChildren|['"]loadChildren['"])\s*:\s*)('[^']+'|"[^"]+")/gm;
// const loadChildrenRegex =
// /(\{[^{}]+?(loadChildren|['"]loadChildren['"])\s*:\s*)('[^']+'|"[^"]+")/gm;


interface Array<T> {
Expand Down Expand Up @@ -37,7 +38,7 @@ export function findLoadChildren(tsFilePath: string): string[] {
// key is an expression, can't do anything.
return false;
}
return key == 'loadChildren'
return key == 'loadChildren';
})
// Remove initializers that are not files.
.filter((node: ts.PropertyAssignment) => {
Expand Down
6 changes: 3 additions & 3 deletions addon/ng2/models/json-schema/schema-class-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class SchemaClassBase<T> implements SchemaClass<T> {
$$set(path: string, value: any) {
const node = _getSchemaNodeForPath(this[kSchemaNode], path);
if (node) {
node.set(value)
node.set(value);
} else {
// This might be inside an object that can have additionalProperties, so
// a TreeNode would not exist.
Expand Down Expand Up @@ -137,15 +137,15 @@ class SchemaClassBase<T> implements SchemaClass<T> {
return node ? node.defined : false;
}

$$delete(path: string){
$$delete(path: string) {
const node = _getSchemaNodeForPath(this[kSchemaNode], path);
if (node) {
node.destroy();
}
}

/** Serialize into a string. */
$$serialize(mimetype: string = 'application/json', ...options: any[]): string {
$$serialize(mimetype = 'application/json', ...options: any[]): string {
let str = '';
const serializer = Serializer.fromMimetype(mimetype, (s) => str += s, ...options);

Expand Down
20 changes: 10 additions & 10 deletions addon/ng2/models/json-schema/schema-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export abstract class SchemaTreeNode<T> {
get parent<ParentType>(): SchemaTreeNode<ParentType> { return this._parent; }
get children<ChildType>(): { [key: string]: SchemaTreeNode<ChildType>} { return null; }

abstract get() : T;
abstract get(): T;
set(v: T) {
if (!this.readOnly) {
throw new MissingImplementationError();
Expand Down Expand Up @@ -130,22 +130,22 @@ abstract class NonLeafSchemaTreeNode<T> extends SchemaTreeNode<T> {
protected _createChildProperty<T>(name: string, value: T, forward: SchemaTreeNode<T>,
schema: Object, define = true): SchemaTreeNode<T> {
const type = schema['type'];
let Klass: TreeNodeConstructor = null;
let klass: TreeNodeConstructor = null;

switch(type) {
case 'object': Klass = ObjectSchemaTreeNode; break;
case 'array': Klass = ArraySchemaTreeNode; break;
case 'string': Klass = StringSchemaTreeNode; break;
case 'boolean': Klass = BooleanSchemaTreeNode; break;
case 'number': Klass = NumberSchemaTreeNode; break;
case 'integer': Klass = IntegerSchemaTreeNode; break;
switch (type) {
case 'object': klass = ObjectSchemaTreeNode; break;
case 'array': klass = ArraySchemaTreeNode; break;
case 'string': klass = StringSchemaTreeNode; break;
case 'boolean': klass = BooleanSchemaTreeNode; break;
case 'number': klass = NumberSchemaTreeNode; break;
case 'integer': klass = IntegerSchemaTreeNode; break;

default:
console.error('Type ' + type + ' not understood by SchemaClassFactory.');
return null;
}

const metaData = new Klass({ parent: this, forward, value, schema, name });
const metaData = new klass({ parent: this, forward, value, schema, name });
if (define) {
SchemaTreeNode._defineProperty(this._value, metaData);
}
Expand Down
6 changes: 3 additions & 3 deletions addon/ng2/models/json-schema/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class JsonSerializer implements Serializer {
private _top() {
return this._state[this._state.length - 1] || {};
}
private _topIsArray() {
return this._top().type == 'array';
}
// private _topIsArray() {
// return this._top().type == 'array';
// }

private _indent(): string {
if (this._indentDelta == 0) {
Expand Down
Loading