Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 1cbbf40

Browse files
Added skyux lint command (#205)
* Update angular (#189) * Updated dependencies * Updated skyux2 version * Updated dependencies * Using template branch for testing * Reverted protractor config * Pointing to dev branch for local testing * Updated package json * Using explicit types * Updated version of skyux * Updated dependencies * Fixed linting errors * Added fontfaceobserver to types * Fixed tslint errors * Fixed tslint errors * Ensure that the files are not directories * Update tests for file processor * Update plugin-file-processor.js * Update plugin-file-processor.spec.js * Updated version of skyux * Updated config * Added specific version of firefox * Updated tsconfig * Updating travis version * Updated version of firefox * Updated directconnect * Updated protractor * Added firfox launcher * Removed directConnect * Reverting back to directConnect * Removed firefox * Re-added firefox * Accepting insecure certs * Enabled directconnect * use chrome with chromOptions in protractor-dev.conf.js * add sources to travis.yml * add dist: trusty * Removed tsconfig paths * Update typescript-loader * Simpler method for avoiding directories * As ts-node option and fix e2e test * updates for rc.0 release (#190) * Omnibar config (#193) * Using omnibarConfigMap for envid/svcid * Fixing implicit any * Fixed codelyzer path (#192) * Fixed codelyzer path * Added node_modules to excludes * Readded node_modules * Ignore public directory when generating components (#187) * Added ignore pattern to component generator * Component generator should ignore public folder * Updated ignore pattern * Plugin File Processor should not check directories (#186) * Do not check directories * Added nodir option * Updated CHANGELOG.md and package.json for 1.0.0-rc.1 (#194) * Updated template branch, bug fix for component pattern (#195) * Updated branch to master * Fixed bug with ignore components pattern * Updated unit tests * Release 1.0.0 rc.2 (#196) * Update CHANGELOG.md * Update package.json * Remove extra s. (#197) * Fixed type error, updated SKY UX (#199) * Fixed type error * Updated skyux * Updated skyux * Release 1.0.0 rc.3 (#200) * Fixed type error * Updated skyux * Updated skyux * Update package.json * Update CHANGELOG.md * Param functionality (#201) * Fixed typo in OmnibarConfigMap. Allowing querystring params to be case insensitive * Test cleanup * Removed unnecessary mapping functionality * Added lint command * Fixed `skyux test/watch` performance (#202) * Removed tslint-loader * Created custom sky-tslint loader * Release 1.0.0-rc.4 (#207) * Updated changelog, version * Update CHANGELOG.md * Update CHANGELOG.md * Added to skyux builder (#204) * Updated package dependencies (#208) * Updated package dependencies * Update skyux version * use appropriate template branch * Add hash routing option for easy mode. (#206) * Updates rc5 (#209) * Updates for rc.5 * Capitalize Angular. (#211) * Wrote failing test. Then made config property public for template (#212) * Added skyux lint files * Update CHANGELOG.md * Updated unit tests * Updated unit tests * Fixed e2e test * Fixed e2e tests * Update build.js * Added colors to logger * Updated linter result * Added error log after karma reporter * Update test.js * Added errors to linter result
1 parent 8a49f46 commit 1cbbf40

28 files changed

+480
-375
lines changed

cli/build-public-library.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ const preparePackage = require('./utils/prepare-library-package');
99
const webpackConfig = require('../config/webpack/build-public-library.webpack.config.js');
1010
const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config');
1111
const runCompiler = require('./utils/run-compiler');
12+
const tsLinter = require('./utils/ts-linter');
13+
14+
function runLinter() {
15+
const lintResult = tsLinter.lintSync();
16+
if (lintResult.exitCode > 0) {
17+
process.exit(lintResult.exitCode);
18+
}
19+
}
1220

1321
function cleanTemp() {
1422
rimraf.sync(skyPagesConfigUtil.spaPathTemp());
@@ -61,6 +69,7 @@ function transpile(skyPagesConfig, webpack) {
6169
}
6270

6371
module.exports = (skyPagesConfig, webpack) => {
72+
runLinter();
6473
cleanAll();
6574
stageTypeScriptFiles();
6675
writeTSConfig();

cli/build.js

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const generator = require('../lib/sky-pages-module-generator');
88
const assetsProcessor = require('../lib/assets-processor');
99
const pluginFileProcessor = require('../lib/plugin-file-processor');
1010
const runCompiler = require('./utils/run-compiler');
11+
const tsLinter = require('./utils/ts-linter');
1112

1213
function writeTSConfig() {
1314
var config = {
@@ -127,6 +128,12 @@ function build(argv, skyPagesConfig, webpack) {
127128
const assetsBaseUrl = argv.assets || '';
128129
const assetsRel = argv.assetsrel;
129130

131+
const lintResult = tsLinter.lintSync();
132+
if (lintResult.exitCode > 0) {
133+
process.exit(lintResult.exitCode);
134+
return;
135+
}
136+
130137
if (compileModeIsAoT) {
131138
stageAot(skyPagesConfig, assetsBaseUrl, assetsRel);
132139
buildConfig = require('../config/webpack/build-aot.webpack.config');

cli/lint.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*jslint node: true */
2+
'use strict';
3+
4+
function lint() {
5+
const tsLinter = require('./utils/ts-linter');
6+
const result = tsLinter.lintSync();
7+
8+
process.exit(result.exitCode);
9+
}
10+
11+
module.exports = lint;

cli/test.js

+41-30
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,52 @@
22
'use strict';
33

44
/**
5-
* Spawns the karam start command.
5+
* Spawns the karma test command.
66
* @name test
77
*/
88
function test(command, argv) {
9-
const path = require('path');
10-
const spawn = require('cross-spawn');
11-
12-
const karmaConfigPath = path.resolve(
13-
__dirname,
14-
'..',
15-
'config/karma/' + command + '.karma.conf.js'
16-
);
17-
18-
const flags = [
19-
'--max-old-space-size=4096',
20-
'node_modules/karma/bin/karma',
21-
'start',
22-
karmaConfigPath,
23-
'--command',
24-
command
25-
];
26-
27-
if (argv && argv.coverage === false) {
28-
flags.push('--no-coverage');
29-
} else {
30-
flags.push('--coverage');
31-
}
32-
33-
const options = {
34-
stdio: 'inherit'
9+
const logger = require('../utils/logger');
10+
const Server = require('karma').Server;
11+
const tsLinter = require('./utils/ts-linter');
12+
const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config');
13+
14+
argv = argv || process.argv;
15+
argv.command = command;
16+
17+
const karmaConfigUtil = require('karma').config;
18+
const karmaConfigPath = skyPagesConfigUtil.outPath(`config/karma/${command}.karma.conf.js`);
19+
const karmaConfig = karmaConfigUtil.parseConfig(karmaConfigPath);
20+
21+
let lintResult;
22+
23+
const onRunStart = () => {
24+
lintResult = tsLinter.lintSync();
25+
};
26+
27+
const onRunComplete = () => {
28+
if (lintResult.exitCode > 0) {
29+
// Pull the logger out of the execution stream to let it print
30+
// after karma's coverage reporter.
31+
setTimeout(() => {
32+
logger.error('Process failed due to linting errors:');
33+
lintResult.errors.forEach(error => logger.error(error));
34+
}, 10);
35+
}
36+
};
37+
38+
const onExit = (exitCode) => {
39+
if (exitCode === 0) {
40+
exitCode = lintResult.exitCode;
41+
}
42+
43+
logger.info(`Karma has exited with ${exitCode}.`);
44+
process.exit(exitCode);
3545
};
3646

37-
// Pass our exitCode up
38-
const test = spawn('node', flags, options);
39-
test.on('exit', exitCode => process.exit(exitCode));
47+
const server = new Server(karmaConfig, onExit);
48+
server.on('run_start', onRunStart);
49+
server.on('run_complete', onRunComplete);
50+
server.start();
4051
}
4152

4253
module.exports = test;

cli/utils/ts-linter.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*jslint node: true */
2+
'use strict';
3+
4+
const spawn = require('cross-spawn');
5+
const skyPagesConfigUtil = require('../../config/sky-pages/sky-pages.config');
6+
const logger = require('../../utils/logger');
7+
8+
const flags = [
9+
'--max-old-space-size=4096',
10+
'--type-check',
11+
'--project',
12+
skyPagesConfigUtil.spaPath('tsconfig.json'),
13+
'--config',
14+
skyPagesConfigUtil.spaPath('tslint.json')
15+
];
16+
17+
function lintSync() {
18+
logger.info('Starting TSLint...');
19+
20+
const spawnResult = spawn.sync('./node_modules/.bin/tslint', flags);
21+
const errorString = spawnResult.stderr.toString().trim();
22+
23+
let errors = [];
24+
if (errorString) {
25+
errors = errorString.split(/\r?\n/);
26+
}
27+
28+
// Print linting results to console.
29+
errors.forEach(error => logger.error(error));
30+
const plural = (errors.length === 1) ? '' : 's';
31+
logger.info(`TSLint finished with ${errors.length} error${plural}.`);
32+
33+
return {
34+
exitCode: spawnResult.status,
35+
errors: errors
36+
};
37+
}
38+
39+
module.exports = {
40+
lintSync
41+
};

config/webpack/test.webpack.config.js

-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const DefinePlugin = require('webpack/lib/DefinePlugin');
66
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
77
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
88
const ProcessExitCode = require('../../plugin/process-exit-code');
9-
const SkyTsLintCheckerPlugin = require('../../loader/sky-tslint/checker-plugin');
109
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config');
1110
const aliasBuilder = require('./alias-builder');
1211

@@ -77,12 +76,6 @@ function getWebpackConfig(skyPagesConfig, argv) {
7776
loader: outPath('loader', 'sky-processor', 'preload'),
7877
exclude: excludes
7978
},
80-
{
81-
enforce: 'pre',
82-
test: /\.ts$/,
83-
loader: outPath('loader', 'sky-tslint'),
84-
exclude: excludes
85-
},
8679
{
8780
test: /\.ts$/,
8881
use: [
@@ -142,9 +135,6 @@ function getWebpackConfig(skyPagesConfig, argv) {
142135
{}
143136
),
144137

145-
// Handles watch-mode maintenance for TSLint.
146-
new SkyTsLintCheckerPlugin(),
147-
148138
// Webpack 2 behavior does not correctly return non-zero exit code.
149139
new ProcessExitCode()
150140
]

e2e/skyux-build-aot.e2e-spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Injectable } from '@angular/core';
3333
3434
@Injectable()
3535
export class AboutGuard {
36-
canActivate(next: any, state: any) {
36+
public canActivate(next: any, state: any): boolean {
3737
return false;
3838
}
3939
}
@@ -62,7 +62,7 @@ import { Injectable } from '@angular/core';
6262
6363
@Injectable()
6464
export class RootGuard {
65-
canActivateChild(next: any, state: any) {
65+
public canActivateChild(next: any, state: any): boolean {
6666
return false;
6767
}
6868
}

e2e/skyux-build-jit.e2e-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Injectable } from '@angular/core';
3333
3434
@Injectable()
3535
export class AboutGuard {
36-
canActivate(next: any, state: any) {
36+
public canActivate(next: any, state: any): boolean {
3737
return false;
3838
}
3939
}

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = {
2222
case 'serve':
2323
require('./cli/serve')(argv, skyPagesConfig, webpack, WebpackDevServer);
2424
break;
25+
case 'lint':
26+
require('./cli/lint')();
27+
break;
2528
case 'test':
2629
case 'watch':
2730
require('./cli/test')(command, argv);

loader/sky-tslint/checker-plugin.js

-14
This file was deleted.

loader/sky-tslint/index.js

-32
This file was deleted.

loader/sky-tslint/program.js

-25
This file was deleted.

runtime/i18n/resources.pipe.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Resources pipe', () => {
2424

2525
return Observable.of(value);
2626
}
27-
};
27+
} as SkyAppResourcesService;
2828
});
2929

3030
it('should return the expected string', () => {

runtime/i18n/resources.service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import {
88
import { Http } from '@angular/http';
99

1010
import { Observable } from 'rxjs/Observable';
11+
import 'rxjs/add/operator/publishReplay';
12+
import 'rxjs/add/operator/switchMap';
13+
import 'rxjs/add/operator/catch';
14+
import 'rxjs/add/operator/map';
15+
import 'rxjs/add/observable/of';
1116

1217
import { SkyAppAssetsService } from '@blackbaud/skyux-builder/runtime/assets.service';
1318
import { SkyAppLocaleProvider } from '@blackbaud/skyux-builder/runtime/i18n/locale-provider';

src/app/sky-pages.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// File dynamically generated via webpack.
22
// Matching definition makes IDE's happy.
3-
export let SkyPagesModule: any;
3+
export class SkyPagesModule {}
44

55
// The following comment is used to track timestamps in `skyux serve`
66
// TS (1492006796510 END

0 commit comments

Comments
 (0)