-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
127 lines (111 loc) · 3.98 KB
/
gulpfile.js
File metadata and controls
127 lines (111 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"use strict";
var fs = require("fs");
var path = require("path");
var merge = require('merge2');
var gulp = require("gulp"),
runSequence = require("run-sequence"),
del = require("del"),
jasmine = require("gulp-jasmine"),
tslint = require("gulp-tslint"),
ts = require("gulp-typescript"),
sourcemaps = require("gulp-sourcemaps");
gulp.task("lint", function () {
return gulp.src([
"**",
"!**/*.d.ts",
"!**/typings/**"
])
.pipe(tslint({}))
.pipe(tslint.report("verbose"));
});
var sourceMapsConfig = {
includeContent: false,
mapSources: function (sourcePath) {
// HACK: The sourcemaps do not reference source files correctly!
// The recieved sourcePath always starts with '../../source/lib/',
// resulting from the current folder structure!
// This indeed is not feasable for files nested on different levels.
// Therefor we need to count the folder depth of the current file.
// This is done by counting the overall slashes within the path.
// To get the additional ones, we need to subtract the initial path count.
// For this project setting it is the magic number of 4. Please adjust
// this to your project needs.
const initialPathCount = 4;
let depthCount = (sourcePath.match(/\//g) || []).length;
let pathUps = "../".repeat(Math.max(depthCount, initialPathCount) - initialPathCount);
return pathUps + sourcePath;
}
};
var tsProject = ts.createProject("tsconfig.json");
function build(sourcePath, base, targetPath) {
var tsResult = gulp.src(sourcePath, { base: base })
.pipe(sourcemaps.init())
.pipe(tsProject(ts.reporter.longReporter()));
return merge([
tsResult.dts
.pipe(gulp.dest("build/")),
tsResult.js
.pipe(sourcemaps.write(".", sourceMapsConfig))
.pipe(gulp.dest("build/"))
]);
};
gulp.task("build-spec", function () {
return build(["source/**/*.ts", "typings/**.d.ts", "!./node_modules/**"], "./source", "");
});
gulp.task("build-lib", function () {
return build(["source/lib/**/*.ts", "typings/**.d.ts", "!./node_modules/**"], "./source", "lib");
});
gulp.task("build-turtle", function () {
var seed = require("./build/db/seed/seeder.js").seed;
return seed();
})
gulp.task("build-seeder", function () {
return build(["source/db/**/*.ts", "typings/**.d.ts", "!./node_modules/**"], "./source", "db");
});
gulp.task("build-fuseki-conf", function () {
var conf = fs.readFileSync("./fuseki-conf.ttl", "utf8");
conf = conf.replace(/<file:.\/([^>]*)>/g, "<file:" + __dirname + "/$1>");
fs.writeFileSync(path.join(__dirname, "build", "db", "fuseki-conf.ttl"), conf);
});
gulp.task("build-db", function () {
return runSequence("build-seeder", "build-turtle", "build-fuseki-conf");
});
gulp.task("build-package.json", function () {
var appPackageJson = JSON.parse(fs.readFileSync(__dirname + "/package.json", "utf8"));
var npmPackageJson = {
"name": appPackageJson.name,
"description": appPackageJson.description,
"version": appPackageJson.version,
"author": appPackageJson.author,
"repository": appPackageJson.repository,
"main": "server.js", // TODO: generate this from app package.json
"typings": "server.d.ts", // TODO: generate this from app package.json
"dependencies": appPackageJson.dependencies,
"keywords": appPackageJson.keywords,
"license": appPackageJson.license,
"bugs": appPackageJson.bugs
}
// fs.mkdirSync(path.join(__dirname, "build"));
// fs.mkdirSync(path.join(__dirname, "build", "lib"));
fs.writeFileSync(path.join(__dirname, "build", "lib", "package.json"), JSON.stringify(npmPackageJson, null, 2));
});
gulp.task("copy", function () {
return gulp.src([
"./source/**/*.json",
"./source/**/*.xml",
"README.md",
"LICENSE"
])
.pipe(gulp.dest("build/"));
});
gulp.task("build", function (cb) {
return runSequence(
"clean-all",
"copy", "build-lib", "build-db", "build-package.json",
cb
);
});
gulp.task("clean-all", function () {
return del(["./build"]);
});
gulp.task("specs");