-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
173 lines (143 loc) · 5.16 KB
/
gulpfile.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
var browserify = require('browserify');
var gulp = require('gulp');
var util = require('util');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var watch = require('gulp-watch');
var run = require('gulp-run');
var notify = require("gulp-notify");
var copy = require("gulp-copy");
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync');
var shell = require('gulp-shell');
var electron = require('gulp-electron');
var del = require('del');
var packageJson = require('./package.json');
//var electron = require('gulp-atom-electron');
process.NODE_ENV = 'dev';
var getBundleName = function () {
var version = require('./package.json').version;
var name = require('./package.json').name;
return name + '.' + version + '.' + 'min';
};
var baseFile = './src/languages/index.js';
gulp.task('watch', function () {
watch(['./{bin,src/languages}/*.js', './{src/languages,lib}/**/*.{js,swig}'], function () {
gulp.start('build:js');
});
});
gulp.task('watch:dist', function () {
watch(['./dist/*.js', './test/*.html', './test/**/*.{raml,schema}'], function () {
browserSync.reload();
});
});
gulp.task('watch:build-fixtures', function () {
watch(['./{bin,src/languages}/*.js', './{src/languages,lib}/**/*.{js,swig}', './test/**/*.{raml,schema}'], function () {
var fixtureName = process.env.GENERATOR_FIXTURE || 'movies';
var outputDir = process.env.GENERATOR_OUTPUT || __dirname + '/test/output/' + fixtureName;
var command = util.format('node %s/bin/raml-to-webservice.js %s/test/fixtures/%s/api.raml -l phpSilex -o %s', __dirname, __dirname, fixtureName, outputDir);
run(command).exec();
});
});
gulp.task('lint', function () {
return gulp.src(['./{bin,src/languages}/*.js', './{src/languages,lib}/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('build:js', ['lint'], function () {
var bundler = browserify([baseFile], {
debug: true,
detectGlobals: true,
standalone: 'RAML.Generator.WebService',
extensions: ['js', 'json', 'swig']
});
//bundler.require(baseFile, {expose: 'raml-schema-generators'});
bundler.transform('folderify');
var bundle = function () {
return bundler
.bundle()
.pipe(source(getBundleName() + '.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'));
};
return bundle();
});
gulp.task('serve', ['watch:dist'], function () {
browserSync({
host: process.env.IP || 'localhost',
port: process.env.PORT || 3000,
server: {
baseDir: './',
index: 'test/parser.html'
}
});
});
gulp.task('build:all', ['build:js', 'build:apps']);
gulp.task('build:apps', ['copy:modules'], function () {
var packageJson = require('./src/package.json');
process.NODE_ENV = 'prod';
return gulp.src("")
.pipe(electron({
src: './src',
packageJson: packageJson,
release: './release',
cache: './cache',
version: 'v0.36.7',
packaging: true,
platforms: ['win32-x64', 'darwin-x64', 'linux-x64'],
platformResources: {
darwin: {
CFBundleDisplayName: packageJson.name,
CFBundleIdentifier: packageJson.name,
CFBundleName: packageJson.name,
CFBundleVersion: packageJson.version,
icon: 'src/ui/generator/favicon.icns'
},
win: {
"version-string": packageJson.version,
"file-version": packageJson.version,
"product-version": packageJson.version,
"icon": 'src/ui/generator/favicon.ico'
}
}
}))
.pipe(gulp.dest(""))
.on('end', function () {
del([
'src/node_modules'
]);
});
});
gulp.task('copy:modules', function (cb) {
return gulp.src([
'./node_modules/q/**',
'./node_modules/json-lint/**',
'./node_modules/uritemplate/**',
'./node_modules/inflection/**',
'./node_modules/underscore/**',
'./node_modules/folderify/**',
'./node_modules/include-folder/**',
'./node_modules/raml-parser/**',
'./node_modules/string/**',
'./node_modules/sugar/**',
'./node_modules/swig/**',
'./node_modules/yargs/**',
'./node_modules/bluebird/**',
'./node_modules/require-dir/**',
'./node_modules/json-schema/**',
'./node_modules/mkdirp/**'
])
.pipe(copy('./src/', {}));
});
gulp.task('default', ['build:js', 'watch', 'serve'], function () {
});
gulp.task('fixtures', ['lint', 'watch:build-fixtures'], function () {
});
gulp.task('test', function () {
console.log("Mock test");
});