Skip to content

Commit 640a008

Browse files
committed
chore(lint): lint ts as well as js
1 parent f9df8bb commit 640a008

23 files changed

+257
-162
lines changed

addon/ng2/commands/build.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ module.exports = Command.extend({
1717
aliases: ['b'],
1818

1919
availableOptions: [
20-
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
20+
{
21+
name: 'target',
22+
type: String,
23+
default: 'development',
24+
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
25+
},
2126
{ name: 'environment', type: String, default: '', aliases: ['e'] },
2227
{ name: 'output-path', type: 'Path', default: 'dist/', aliases: ['o'] },
2328
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
@@ -26,13 +31,13 @@ module.exports = Command.extend({
2631
],
2732

2833
run: function (commandOptions: BuildOptions) {
29-
if (commandOptions.environment === ''){
34+
if (commandOptions.environment === '') {
3035
if (commandOptions.target === 'development') {
3136
commandOptions.environment = 'dev';
3237
}
3338
if (commandOptions.target === 'production') {
3439
commandOptions.environment = 'prod';
35-
}
40+
}
3641
}
3742

3843
var project = this.project;

addon/ng2/commands/doc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const DocCommand = Command.extend({
1010
'<keyword>'
1111
],
1212

13-
run: function(commandOptions, rawArgs:Array<string>) {
13+
run: function(commandOptions, rawArgs: Array<string>) {
1414
var keyword = rawArgs[0];
15-
15+
1616
var docTask = new DocTask({
1717
ui: this.ui,
1818
analytics: this.analytics,
@@ -23,4 +23,4 @@ const DocCommand = Command.extend({
2323
}
2424
});
2525

26-
module.exports = DocCommand;
26+
module.exports = DocCommand;

addon/ng2/commands/generate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const GenerateCommand = EmberGenerateCommand.extend({
2121
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
2222
SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
2323
}
24-
24+
2525
// Override default help to hide ember blueprints
2626
EmberGenerateCommand.prototype.printDetailedHelp = function (options) {
2727
var blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
2828
var blueprints = blueprintList
2929
.filter(bp => bp.indexOf('-test') === -1)
3030
.filter(bp => bp !== 'ng2')
3131
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
32-
32+
3333
var output = '';
3434
blueprints
3535
.forEach(function (bp) {
@@ -38,7 +38,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
3838
this.ui.writeLine(chalk.cyan(' Available blueprints'));
3939
this.ui.writeLine(output);
4040
};
41-
41+
4242
return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
4343
}
4444
});

addon/ng2/commands/github-pages-deploy.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path';
99
import * as WebpackBuild from '../tasks/build-webpack';
1010
import * as CreateGithubRepo from '../tasks/create-github-repo';
1111
import { CliConfig } from '../models/config';
12+
import { oneLine } from 'common-tags';
1213

1314
const fsReadFile = Promise.denodeify(fs.readFile);
1415
const fsWriteFile = Promise.denodeify(fs.writeFile);
@@ -18,7 +19,10 @@ const fsCopy = Promise.denodeify(fse.copy);
1819
module.exports = Command.extend({
1920
name: 'github-pages:deploy',
2021
aliases: ['gh-pages:deploy'],
21-
description: 'Build the test app for production, commit it into a git branch, setup GitHub repo and push to it',
22+
description: oneLine`
23+
Build the test app for production, commit it into a git branch,
24+
setup GitHub repo and push to it
25+
`,
2226
works: 'insideProject',
2327

2428
availableOptions: [
@@ -66,7 +70,7 @@ module.exports = Command.extend({
6670
cwd: root
6771
};
6872

69-
if (options.environment === ''){
73+
if (options.environment === '') {
7074
if (options.target === 'development') {
7175
options.environment = 'dev';
7276
}
@@ -137,7 +141,7 @@ module.exports = Command.extend({
137141
}
138142

139143
function build() {
140-
if (options.skipBuild) return Promise.resolve();
144+
if (options.skipBuild) { return Promise.resolve(); }
141145
return buildTask.run(buildOptions);
142146
}
143147

@@ -165,7 +169,7 @@ module.exports = Command.extend({
165169

166170
function checkoutGhPages() {
167171
return execPromise(`git checkout ${ghPagesBranch}`)
168-
.catch(createGhPagesBranch)
172+
.catch(createGhPagesBranch);
169173
}
170174

171175
function createGhPagesBranch() {
@@ -179,16 +183,16 @@ module.exports = Command.extend({
179183
function copyFiles() {
180184
return fsReadDir(outDir)
181185
.then((files) => Promise.all(files.map((file) => {
182-
if (file === '.gitignore'){
186+
if (file === '.gitignore') {
183187
// don't overwrite the .gitignore file
184188
return Promise.resolve();
185189
}
186-
return fsCopy(path.join(outDir, file), path.join('.', file))
190+
return fsCopy(path.join(outDir, file), path.join('.', file));
187191
})));
188192
}
189193

190194
function updateBaseHref() {
191-
if (options.userPage) return Promise.resolve();
195+
if (options.userPage) { return Promise.resolve(); }
192196
let indexHtml = path.join(root, 'index.html');
193197
return fsReadFile(indexHtml, 'utf8')
194198
.then((data) => data.replace(/<base href="\/">/g, `<base href="/${projectName}/">`))
@@ -215,7 +219,8 @@ module.exports = Command.extend({
215219
function printProjectUrl() {
216220
return execPromise('git remote -v')
217221
.then((stdout) => {
218-
let userName = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m)[1].toLowerCase();
222+
let match = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m);
223+
let userName = match[1].toLowerCase();
219224
let url = `https://${userName}.github.io/${options.userPage ? '' : (projectName + '/')}`;
220225
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
221226
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
@@ -225,7 +230,8 @@ module.exports = Command.extend({
225230
function failGracefully(error) {
226231
if (error && (/git clean/.test(error.message) || /Permission denied/.test(error.message))) {
227232
ui.writeLine(error.message);
228-
let msg = 'There was a permissions error during git file operations, please close any open project files/folders and try again.';
233+
let msg = 'There was a permissions error during git file operations, ' +
234+
'please close any open project files/folders and try again.';
229235
msg += `\nYou might also need to return to the ${initialBranch} branch manually.`;
230236
return Promise.reject(new SilentError(msg));
231237
} else {

addon/ng2/commands/serve.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as Command from 'ember-cli/lib/models/command';
33
import * as Promise from 'ember-cli/lib/ext/promise';
44
import * as SilentError from 'silent-error';
55
import * as PortFinder from 'portfinder';
6-
import * as EOL from 'os';
76
import * as ServeWebpackTask from '../tasks/serve-webpack.ts';
87

98
PortFinder.basePort = 49152;
@@ -36,23 +35,54 @@ module.exports = Command.extend({
3635

3736
availableOptions: [
3837
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
39-
{ name: 'host', type: String, default: 'localhost', aliases: ['H'], description: 'Listens on all interfaces by default' },
38+
{
39+
name: 'host',
40+
type: String,
41+
default: 'localhost',
42+
aliases: ['H'],
43+
description: 'Listens on all interfaces by default'
44+
},
4045
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
4146
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
4247
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
43-
{ name: 'live-reload-host', type: String, aliases: ['lrh'], description: 'Defaults to host' },
44-
{ name: 'live-reload-base-url', type: String, aliases: ['lrbu'], description: 'Defaults to baseURL' },
45-
{ name: 'live-reload-port', type: Number, aliases: ['lrp'], description: '(Defaults to port number within [49152...65535])' },
46-
{ name: 'live-reload-live-css', type: Boolean, default: true, description: 'Whether to live reload CSS (default true)' },
47-
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
48+
{
49+
name: 'live-reload-host',
50+
type: String,
51+
aliases: ['lrh'],
52+
description: 'Defaults to host'
53+
},
54+
{
55+
name: 'live-reload-base-url',
56+
type: String,
57+
aliases: ['lrbu'],
58+
description: 'Defaults to baseURL'
59+
},
60+
{
61+
name: 'live-reload-port',
62+
type: Number,
63+
aliases: ['lrp'],
64+
description: '(Defaults to port number within [49152...65535])'
65+
},
66+
{
67+
name: 'live-reload-live-css',
68+
type: Boolean,
69+
default: true,
70+
description: 'Whether to live reload CSS (default true)'
71+
},
72+
{
73+
name: 'target',
74+
type: String,
75+
default: 'development',
76+
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
77+
},
4878
{ name: 'environment', type: String, default: '', aliases: ['e'] },
4979
{ name: 'ssl', type: Boolean, default: false },
5080
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
5181
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' }
5282
],
5383

5484
run: function(commandOptions: ServeTaskOptions) {
55-
if (commandOptions.environment === ''){
85+
if (commandOptions.environment === '') {
5686
if (commandOptions.target === 'development') {
5787
commandOptions.environment = 'dev';
5888
}
@@ -65,19 +95,11 @@ module.exports = Command.extend({
6595

6696
return this._checkExpressPort(commandOptions)
6797
.then(this._autoFindLiveReloadPort.bind(this))
68-
.then((commandOptions: ServeTaskOptions) => {
69-
commandOptions = assign({}, commandOptions, {
98+
.then((opts: ServeTaskOptions) => {
99+
commandOptions = assign({}, opts, {
70100
baseURL: this.project.config(commandOptions.target).baseURL || '/'
71101
});
72102

73-
if (commandOptions.proxy) {
74-
if (!commandOptions.proxy.match(/^(http:|https:)/)) {
75-
var message = 'You need to include a protocol with the proxy URL.' + EOL + 'Try --proxy http://' + commandOptions.proxy;
76-
77-
return Promise.reject(new SilentError(message));
78-
}
79-
}
80-
81103
var serve = new ServeWebpackTask({
82104
ui: this.ui,
83105
analytics: this.analytics,

addon/ng2/models/config.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import {CliConfig as CliConfigBase} from './config/config';
22
import {CliConfig as ConfigInterface} from '../../../lib/config/schema';
3+
import { oneLine } from 'common-tags';
34
import * as chalk from 'chalk';
45
import * as fs from 'fs';
56
import * as path from 'path';
67

7-
const schemaPath = path.resolve(process.env.CLI_ROOT, 'lib/config/schema.json');
8-
const schema = require(schemaPath);
9-
108
export const CLI_CONFIG_FILE_NAME = 'angular-cli.json';
119

1210

@@ -51,11 +49,11 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
5149
const cliConfig = CliConfigBase.fromConfigPath(CliConfig._configFilePath(), [globalConfigPath]);
5250
if (cliConfig.alias('apps.0.root', 'defaults.sourceDir')
5351
+ cliConfig.alias('apps.0.prefix', 'defaults.prefix')) {
54-
console.error(chalk.yellow(
55-
'The "defaults.prefix" and "defaults.sourceDir" properties of angular-cli.json\n'
56-
+ 'are deprecated in favor of "apps[0].root" and "apps[0].prefix".\n'
57-
+ 'Please update in order to avoid errors in future versions of angular-cli.'
58-
));
52+
console.error(chalk.yellow(oneLine`
53+
The "defaults.prefix" and "defaults.sourceDir" properties of angular-cli.json
54+
are deprecated in favor of "apps[0].root" and "apps[0].prefix".\n
55+
Please update in order to avoid errors in future versions of angular-cli.
56+
`));
5957
}
6058

6159
return cliConfig as CliConfig;

addon/ng2/models/config/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class InvalidConfigError extends Error {
1717
export class CliConfig<Config> {
1818
private _config: SchemaClass<Config>;
1919

20-
private constructor(private _configPath: string,
20+
constructor(private _configPath: string,
2121
schema: Object,
2222
configJson: Config,
2323
fallbacks: Config[] = []) {
@@ -29,7 +29,7 @@ export class CliConfig<Config> {
2929
save(path: string = this._configPath) {
3030
return fs.writeFileSync(path, this.serialize(), 'utf-8');
3131
}
32-
serialize(mimetype: string = 'application/json'): string {
32+
serialize(mimetype = 'application/json'): string {
3333
return this._config.$$serialize(mimetype);
3434
}
3535

@@ -73,7 +73,7 @@ export class CliConfig<Config> {
7373
try {
7474
content = JSON.parse(configContent);
7575
schema = JSON.parse(schemaContent);
76-
others = otherContents.map(content => JSON.parse(content));
76+
others = otherContents.map(otherContent => JSON.parse(otherContent));
7777
} catch (err) {
7878
throw new InvalidConfigError(err);
7979
}

addon/ng2/models/find-lazy-modules.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import * as glob from 'glob';
33
import * as path from 'path';
44
import * as ts from 'typescript';
55

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

98

10-
const loadChildrenRegex = /(\{[^{}]+?(loadChildren|['"]loadChildren['"])\s*:\s*)('[^']+'|"[^"]+")/gm;
11-
12-
139
interface Array<T> {
1410
flatMap: <R>(mapFn: (item: T) => Array<R>) => Array<R>;
1511
}
@@ -37,14 +33,15 @@ export function findLoadChildren(tsFilePath: string): string[] {
3733
// key is an expression, can't do anything.
3834
return false;
3935
}
40-
return key == 'loadChildren'
36+
return key == 'loadChildren';
4137
})
4238
// Remove initializers that are not files.
4339
.filter((node: ts.PropertyAssignment) => {
4440
return node.initializer.kind === ts.SyntaxKind.StringLiteral;
4541
})
46-
// Get the full text of the initiliazer.
42+
// Get the full text of the initializer.
4743
.map((node: ts.PropertyAssignment) => {
44+
/* tslint:disable:no-eval */
4845
return eval(node.initializer.getText(source));
4946
})
5047
.flatMap((value: string) => unique[value] ? undefined : unique[value] = value)

0 commit comments

Comments
 (0)