Skip to content

Commit

Permalink
chore(lint): lint ts as well as js (#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Aug 25, 2016
1 parent b5e86c9 commit d17bc71
Show file tree
Hide file tree
Showing 40 changed files with 376 additions and 251 deletions.
17 changes: 11 additions & 6 deletions addon/ng2/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ module.exports = Command.extend({
aliases: ['b'],

availableOptions: [
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
{
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'] },
Expand All @@ -26,18 +31,18 @@ module.exports = Command.extend({
],

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;
var ui = this.ui;
var buildTask = commandOptions.watch ?
const project = this.project;
const ui = this.ui;
const buildTask = commandOptions.watch ?
new WebpackBuildWatch({
cliProject: project,
ui: ui,
Expand Down
10 changes: 5 additions & 5 deletions addon/ng2/commands/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const DocCommand = Command.extend({
'<keyword>'
],

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

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

module.exports = DocCommand;
module.exports = DocCommand;
2 changes: 1 addition & 1 deletion addon/ng2/commands/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = Command.extend({
run: function () {
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();

var e2eTask = new E2ETask({
const e2eTask = new E2ETask({
ui: this.ui,
analytics: this.analytics,
project: this.project
Expand Down
16 changes: 8 additions & 8 deletions addon/ng2/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as EmberGenerateCommand from 'ember-cli/lib/commands/generate';
import * as fs from 'fs';
import * as path from 'path';
import * as SilentError from 'silent-error';
var chalk = require('chalk');
import * as Blueprint from 'ember-cli/lib/models/blueprint';
var EOL = require('os').EOL;
const chalk = require('chalk');
const EOL = require('os').EOL;

const GenerateCommand = EmberGenerateCommand.extend({
name: 'generate',
Expand All @@ -21,24 +21,24 @@ 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
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
const blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
var output = '';

let output = '';
blueprints
.forEach(function (bp) {
output += bp.printBasicHelp(false) + EOL;
});
this.ui.writeLine(chalk.cyan(' Available blueprints'));
this.ui.writeLine(output);
};

return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
}
});
Expand Down
40 changes: 23 additions & 17 deletions addon/ng2/commands/github-pages-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as path from 'path';
import * as WebpackBuild from '../tasks/build-webpack';
import * as CreateGithubRepo from '../tasks/create-github-repo';
import { CliConfig } from '../models/config';
import { oneLine } from 'common-tags';

const fsReadFile = Promise.denodeify(fs.readFile);
const fsWriteFile = Promise.denodeify(fs.writeFile);
Expand All @@ -18,7 +19,10 @@ 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: oneLine`
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 @@ -60,13 +64,13 @@ module.exports = Command.extend({
}],

run: function(options, rawArgs) {
var ui = this.ui;
var root = this.project.root;
var execOptions = {
const ui = this.ui;
const root = this.project.root;
const execOptions = {
cwd: root
};

if (options.environment === ''){
if (options.environment === '') {
if (options.target === 'development') {
options.environment = 'dev';
}
Expand All @@ -75,7 +79,7 @@ module.exports = Command.extend({
}
}

var projectName = this.project.pkg.name;
const projectName = this.project.pkg.name;

const outDir = CliConfig.fromProject().config.apps[0].outDir;

Expand All @@ -86,7 +90,7 @@ module.exports = Command.extend({
// declared here so that tests can stub exec
const execPromise = Promise.denodeify(exec);

var buildTask = new WebpackBuild({
const buildTask = new WebpackBuild({
ui: this.ui,
analytics: this.analytics,
cliProject: this.project,
Expand All @@ -95,19 +99,19 @@ module.exports = Command.extend({
outputPath: outDir
});

var buildOptions = {
const buildOptions = {
target: options.target,
environment: options.environment,
outputPath: outDir
};

var createGithubRepoTask = new CreateGithubRepo({
const createGithubRepoTask = new CreateGithubRepo({
ui: this.ui,
analytics: this.analytics,
project: this.project
});

var createGithubRepoOptions = {
const createGithubRepoOptions = {
projectName,
ghUsername: options.ghUsername,
ghToken: options.ghToken
Expand Down Expand Up @@ -137,7 +141,7 @@ 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 +169,7 @@ module.exports = Command.extend({

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

function createGhPagesBranch() {
Expand All @@ -179,16 +183,16 @@ 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 +219,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 match = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m);
let userName = match[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 +230,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
2 changes: 1 addition & 1 deletion addon/ng2/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = Command.extend({
description: 'Lints code in existing project',
works: 'insideProject',
run: function () {
var lintTask = new LintTask({
const lintTask = new LintTask({
ui: this.ui,
analytics: this.analytics,
project: this.project
Expand Down
62 changes: 42 additions & 20 deletions addon/ng2/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Command from 'ember-cli/lib/models/command';
import * as Promise from 'ember-cli/lib/ext/promise';
import * as SilentError from 'silent-error';
import * as PortFinder from 'portfinder';
import * as EOL from 'os';
import * as ServeWebpackTask from '../tasks/serve-webpack.ts';

PortFinder.basePort = 49152;
Expand Down Expand Up @@ -36,23 +35,54 @@ 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,20 +95,12 @@ module.exports = Command.extend({

return this._checkExpressPort(commandOptions)
.then(this._autoFindLiveReloadPort.bind(this))
.then((commandOptions: ServeTaskOptions) => {
commandOptions = assign({}, commandOptions, {
.then((opts: ServeTaskOptions) => {
commandOptions = assign({}, opts, {
baseURL: this.project.config(commandOptions.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;

return Promise.reject(new SilentError(message));
}
}

var serve = new ServeWebpackTask({
const serve = new ServeWebpackTask({
ui: this.ui,
analytics: this.analytics,
project: this.project,
Expand All @@ -93,7 +115,7 @@ module.exports = Command.extend({
.then((foundPort: number) => {

if (commandOptions.port !== foundPort && commandOptions.port !== 0) {
var message = 'Port ' + commandOptions.port + ' is already in use.';
const message = 'Port ' + commandOptions.port + ' is already in use.';
return Promise.reject(new SilentError(message));
}

Expand Down
2 changes: 1 addition & 1 deletion addon/ng2/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = TestCommand.extend({
run: function (commandOptions) {
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();

var testTask = new TestTask({
const testTask = new TestTask({
ui: this.ui,
analytics: this.analytics,
project: this.project
Expand Down
Loading

0 comments on commit d17bc71

Please sign in to comment.