Skip to content

Commit 068c646

Browse files
committed
Initial checkin.
0 parents  commit 068c646

17 files changed

Lines changed: 3403 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
npm*.log
4+
lib

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
src
2+
node_modules
3+
.vscode
4+
5+
.gitignore
6+
.gitattributes
7+
.editorconfig
8+
gulpfile.js

.vscode/launch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "node_modules/gulp/bin/gulp.js",
9+
"stopOnEntry": false,
10+
"args": [],
11+
"cwd": ".",
12+
"runtimeExecutable": null,
13+
"runtimeArgs": [
14+
"--nolazy"
15+
],
16+
"env": {
17+
"NODE_ENV": "development"
18+
},
19+
"externalConsole": false,
20+
"sourceMaps": false,
21+
"outDir": null
22+
},
23+
{
24+
"name": "Attach",
25+
"type": "node",
26+
"request": "attach",
27+
"port": 5858
28+
}
29+
]
30+
}

.vscode/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Controls the rendering size of tabs in characters. Accepted values: "auto", 2, 4, 6, etc. If set to "auto", the value will be guessed when a file is opened.
3+
"editor.tabSize": 2,
4+
// When enabled, will trim trailing whitespace when you save a file.
5+
"files.trimTrailingWhitespace": true,
6+
// Controls whether the editor should render whitespace characters
7+
"editor.renderWhitespace": true,
8+
"editor.insertSpaces": true,
9+
// Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the file.exclude setting.
10+
"files.exclude": {
11+
"**/.git": true,
12+
"**/.DS_Store": true
13+
},
14+
// Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the file.exclude setting.
15+
"search.exclude": {
16+
}
17+
}

gulpfile.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
let gulp = require('gulp');
4+
5+
let config = {
6+
paths: {
7+
libFolder: 'lib',
8+
sourceMatch: [
9+
'src/**/*.ts',
10+
'typings/tsd.d.ts'
11+
],
12+
testMatch: [
13+
'lib/**/*.test.js'
14+
]
15+
}
16+
}
17+
18+
gulp.task('build', () => {
19+
let ts = require('gulp-typescript');
20+
let plumber = require('gulp-plumber');
21+
let merge = require('merge2');
22+
let lint = require('gulp-tslint');
23+
let tsConfig = require('./tsconfig.json');
24+
let paths = config.paths;
25+
let errorCount = 0;
26+
let allStreams = [];
27+
let tsProject = ts.createProject(tsConfig.compilerOptions);
28+
let gutil = require('gulp-util');
29+
let sourceStream = gulp.src(paths.sourceMatch);
30+
31+
sourceStream
32+
.pipe(lint({
33+
configuration: require('./tslint.json')
34+
}))
35+
.pipe(lint.report('full', {
36+
emitError: false
37+
}));
38+
39+
let tsResult = sourceStream
40+
.pipe(plumber({
41+
errorHandler: function(error) {
42+
// console.log(error);
43+
errorCount++;
44+
}
45+
}))
46+
.pipe(ts(tsProject, undefined, ts.reporter.longReporter()));
47+
48+
allStreams.push(tsResult.js.pipe(gulp.dest(paths.libFolder)));
49+
allStreams.push(tsResult.dts.pipe(gulp.dest(paths.libFolder)));
50+
51+
let mergedStream = merge(allStreams);
52+
53+
mergedStream.on('queueDrain', function() {
54+
if (errorCount) {
55+
// throw new gutil.PluginError('msg', `[gulp-typescript] TypeScript error(s): ${ chalk.red(errorCount) }`, { showStack: false });
56+
}
57+
});
58+
59+
return mergedStream;
60+
});
61+
62+
gulp.task('test', ['build'], () => {
63+
let mocha = require('gulp-mocha');
64+
65+
return gulp.src(config.paths.testMatch, { read: false })
66+
.pipe(mocha());
67+
});
68+
69+
gulp.task('default', ['build']);

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "gulp-core-build-webpack",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "lib/index.js",
6+
"typings": "lib/index.d.ts",
7+
"license": "MIT",
8+
"peerDependencies": {
9+
"gulp-core-build": "^0.3.0",
10+
"gulp": "^3.9.1",
11+
"webpack": "^1.12.14"
12+
},
13+
"dependencies": {
14+
"gulp-util": "^3.0.7"
15+
},
16+
"devDependencies": {
17+
"gulp-plumber": "^1.1.0",
18+
"gulp-tslint": "^4.3.3",
19+
"gulp-typescript": "^2.12.1",
20+
"merge2": "^1.0.1",
21+
"tslint": "^3.5.0",
22+
"typescript": "^1.8.7"
23+
}
24+
}

src/WebpackTask.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { GulpTask } from 'gulp-core-build';
2+
3+
export interface IWebpackConfig {
4+
configPaths: string[];
5+
}
6+
7+
export class WebpackTask extends GulpTask<IWebpackConfig> {
8+
public name = 'webpack';
9+
10+
public taskConfig: IWebpackConfig = {
11+
configPaths: ['./webpack.config.js']
12+
};
13+
14+
public executeTask(gulp, completeCallback): any {
15+
// let isProduction = (process.argv.indexOf('--production') > -1);
16+
// let streams = [];
17+
let completeEntries = 0;
18+
19+
if (completeEntries === this.taskConfig.configPaths.length) {
20+
completeCallback();
21+
} else {
22+
23+
for (let configPath of this.taskConfig.configPaths) {
24+
configPath = this.resolvePath(configPath);
25+
26+
if (!this.fileExists(configPath)) {
27+
let path = require('path');
28+
let relativeConfigPath = path.relative(this.buildConfig.rootPath, configPath);
29+
30+
this.logWarning(`The webpack config location '${relativeConfigPath}' doesn't exist.`);
31+
completeEntries++;
32+
} else {
33+
let webpack = require('webpack');
34+
let path = require('path');
35+
let gutil = require('gulp-util');
36+
37+
let webpackConfig = require(configPath);
38+
let startTime = new Date().getTime();
39+
let outputDir = this.buildConfig.distFolder;
40+
41+
webpack(
42+
webpackConfig,
43+
(error, stats) => {
44+
let statsResult = stats.toJson({
45+
hash: false,
46+
source: false
47+
});
48+
49+
if (statsResult.errors && statsResult.errors.length) {
50+
this.logError(`'${outputDir}':` + '\n' + statsResult.errors.join('\n') + '\n');
51+
}
52+
53+
if (statsResult.warnings && statsResult.warnings.length) {
54+
this.logWarning(`'${outputDir}':` + '\n' + statsResult.warnings.join('\n') + '\n');
55+
}
56+
57+
completeEntries++;
58+
59+
let duration = (new Date().getTime() - startTime);
60+
61+
statsResult.chunks.forEach(chunk => chunk.files.forEach(file => (
62+
this.log(`Bundled: '${gutil.colors.cyan(path.basename(file))}', ` +
63+
`size: ${gutil.colors.magenta(chunk.size)} bytes, ` +
64+
`took ${gutil.colors.magenta(duration)} ms.`)
65+
)));
66+
67+
let chunk;
68+
69+
for (let i = 0; i < statsResult.chunks.length; i++) {
70+
let chunkStats = {
71+
chunk: null,
72+
modules: null
73+
};
74+
75+
chunkStats.chunk = chunk = statsResult.chunks[i];
76+
77+
let statsPath = path.join(outputDir, chunk.files[0]) + '.stats.json';
78+
79+
if (statsResult.modules) {
80+
chunkStats.modules = statsResult.modules
81+
.filter(mod => (mod.chunks && mod.chunks.indexOf(chunk.id) > -1))
82+
.map(mod => ({ name: mod.name, size: mod.size }))
83+
.sort((a, b) => (a.size < b.size ? 1 : -1));
84+
}
85+
86+
let fs = require('fs');
87+
88+
fs.writeFileSync(
89+
statsPath,
90+
JSON.stringify(chunkStats, null, 2),
91+
'utf8'
92+
);
93+
}
94+
});
95+
}
96+
97+
if (completeEntries === this.taskConfig.configPaths.length) {
98+
completeCallback();
99+
}
100+
101+
}
102+
}
103+
}
104+
}

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { WebpackTask } from './WebpackTask';
2+
3+
export const webpack = new WebpackTask();
4+
export default webpack;

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"jsx": "react",
6+
"declaration": true,
7+
"sourceMap": true
8+
}
9+
}

tsd.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "v4",
3+
"repo": "borisyankov/DefinitelyTyped",
4+
"ref": "master",
5+
"path": "typings",
6+
"bundle": "typings/tsd.d.ts",
7+
"installed": {
8+
"node/node.d.ts": {
9+
"commit": "9f0f926a12026287b5a4a229e5672c01e7549313"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)