Skip to content

Commit 758a043

Browse files
committed
Updated gulp file to use specific data from the package.json, so that
the same gulpfile can be used on different projects
1 parent 2207036 commit 758a043

File tree

2 files changed

+91
-63
lines changed

2 files changed

+91
-63
lines changed

gulpfile.js

+41-16
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ var replace = require('gulp-replace');
2323
var moment = require('moment');
2424
var execSync = require('exec-sync');
2525

26-
var NAME = 'JSDB';
27-
var CODENAME = 'jsdb'
26+
var packg = {};
27+
try {
28+
packg = JSON.parse(fs.readFileSync('./package.json'));
29+
} catch (e) {
30+
console.log("Error reading package.json");
31+
console.log(e);
32+
}
33+
var gulpdata = (packg && packg.gulp_data) ? packg.gulp_data : {};
34+
35+
var NAME = gulpdata.fullName || packg.name || 'project';
36+
var CODENAME = gulpdata.codeName || packg.name || 'project';
37+
2838

2939
var paths = {
30-
tests: ['./js/test/Db3Tests.js'],
31-
mainDts: './js/main/Db3.d.ts',
40+
tests: ['./js/test/*.js'],
41+
mainDts: './js/main/index.d.ts',
3242
ts: ['./src/**/*.ts'],
3343
js: ['./js/**/*.js'],
3444
jsApp: ['./js/main/*.js'],
@@ -37,12 +47,19 @@ var paths = {
3747
tsoutApp: './js/main',
3848
tsApp: ['./src/main/**/*.ts'],
3949
tsTest: ['./src/test/**/*.ts'],
40-
remoteBuildFiles: [
41-
'./js/**',
42-
'package.json'
43-
]
4450
};
4551

52+
if (packg && packg.gulp_data && packg.gulp_data.paths) {
53+
var gdpaths = packg.gulp_data.paths;
54+
var ks = Object.keys(paths);
55+
for (var i = 0; i < ks.length; i++) {
56+
var k = ks[i];
57+
if (gdpaths.hasOwnProperty(k)) {
58+
paths[k] = gdpaths[k];
59+
}
60+
}
61+
}
62+
4663
/**
4764
* Used to determine if the gulp operation was launched for a debug or release build.
4865
* This is controlled by the scheme parameter, if no scheme is provided, it will default
@@ -132,8 +149,14 @@ var lastVersionTag = '';
132149
*/
133150
function versionTag() {
134151
if (lastVersionTag) return lastVersionTag;
135-
var gitVer = execSync('git log -1 --pretty=%h');
136-
var gitBranch = execSync('git rev-parse --abbrev-ref HEAD');
152+
var gitVer = '';
153+
var gitBranch = 'local';
154+
try {
155+
gitVer = execSync('git log -1 --pretty=%h');
156+
gitBranch = execSync('git rev-parse --abbrev-ref HEAD');
157+
} catch (e) {
158+
}
159+
gitVer = packg.version + '_' + gitVer;
137160
var ts = moment().format('YYYYMMDD_HHmmss');
138161
lastVersionTag = ts + '_' + gitBranch + '_' + gitVer;
139162
return lastVersionTag;
@@ -189,7 +212,7 @@ gulp.task("test", ["ts"], function (cb) {
189212
* as well as the unit tests.
190213
*/
191214
gulp.task("tsd", function (cb) {
192-
runSequence("tsd:app", "tsd:tests", cb);
215+
runSequence("tsd:app", cb);
193216
});
194217

195218
/**
@@ -260,11 +283,13 @@ gulp.task("ts", ["ts:src"], function () {
260283
.pipe(replace('VERSION_TAG', versionTag()))
261284
.pipe(gulp.dest(paths.tsout))
262285
.on('finish', function() {
263-
dts.bundle({
264-
name: CODENAME,
265-
main: paths.mainDts,
266-
out: CODENAME + '.d.ts'
267-
});
286+
if (paths.mainDts) {
287+
dts.bundle({
288+
name: CODENAME,
289+
main: paths.mainDts,
290+
out: CODENAME + '.d.ts'
291+
});
292+
}
268293
})
269294
]);
270295
});

package.json

+50-47
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
{
2-
"name": "jsdb",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "js/main/Db3.js",
6-
"scripts": {
7-
"test": "gulp test"
8-
},
9-
"author": "Simone Gianni",
10-
"license": "private",
11-
"private": true,
12-
"dependencies": {
13-
"es6-promise": "^2.3.0",
14-
"firebase": "^2.2.5",
15-
"socket.io-client": "^1.3.5"
16-
},
17-
"devDependencies": {
18-
"del": "1.2.0",
19-
"gulp": "3.9.0",
20-
"merge2": "^0.3.6",
21-
"gulp-util": "2.2.14",
22-
"gulp-typescript": "2.8.1",
23-
"dts-bundle": "^0.3.0",
24-
"gulp-tslint": "3.0.1-beta",
25-
"gulp-typedoc": "^1.2.1",
26-
"run-sequence": "1.1.1",
27-
"gulp-mocha": "^2.1.3",
28-
"gulp-istanbul": "^0.10.0",
29-
"gulp-replace": "^0.5.4",
30-
"moment": "^2.10.6",
31-
"exec-sync": "^0.1.6",
32-
"typescript": "1.6.2",
33-
"tsMatchers": "SimoneGianni/tsMatchers#noded"
34-
},
35-
"config": {
36-
"blanket": {
37-
"pattern": [
38-
""
39-
],
40-
"data-cover-never": [
41-
"node_modules"
42-
]
43-
}
44-
},
45-
"typescript": {
46-
"definition": "js/main/jsdb.d.ts"
47-
}
48-
}
2+
"name": "jsdb",
3+
"version": "1.0.0",
4+
"description": "",
5+
"gulp_data": {
6+
"fullName": "TsDb",
7+
"paths": {
8+
"tests": ["./js/test/Db3Tests.js"],
9+
"mainDts": "./js/main/Db3.d.ts"
10+
}
11+
},
12+
"main": "js/main/Db3.js",
13+
"scripts": {
14+
"test": "gulp test"
15+
},
16+
"author": "Simone Gianni",
17+
"license": "private",
18+
"private": true,
19+
"dependencies": {
20+
"es6-promise": "^2.3.0",
21+
"firebase": "^2.2.5",
22+
"socket.io-client": "^1.3.5"
23+
},
24+
"devDependencies": {
25+
"del": "1.2.0",
26+
"gulp": "3.9.0",
27+
"merge2": "^0.3.6",
28+
"gulp-util": "2.2.14",
29+
"gulp-typescript": "2.8.1",
30+
"dts-bundle": "^0.3.0",
31+
"gulp-tslint": "3.0.1-beta",
32+
"gulp-typedoc": "^1.2.1",
33+
"run-sequence": "1.1.1",
34+
"gulp-mocha": "^2.1.3",
35+
"gulp-istanbul": "^0.10.0",
36+
"gulp-replace": "^0.5.4",
37+
"moment": "^2.10.6",
38+
"exec-sync": "^0.1.6",
39+
"typescript": "1.6.2",
40+
"tsMatchers": "SimoneGianni/tsMatchers#noded"
41+
},
42+
"config": {
43+
"blanket": {
44+
"pattern": [""],
45+
"data-cover-never": ["node_modules"]
46+
}
47+
},
48+
"typescript": {
49+
"definition": "js/main/jsdb.d.ts"
50+
}
51+
}

0 commit comments

Comments
 (0)