This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
186 lines (157 loc) · 7.03 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
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// Copyright 2016 Kary Foundation, Inc.
// Author: Pouya Kary <k@karyfoundation.org>
//
//
// ─── IMPORTS ────────────────────────────────────────────────────────────────────
//
var gulp = require('gulp');
var exec = require('child_process').exec;
var util = require('util');
var fs = require('fs-extra');
var path = require('path');
var ugly = require('gulp-uglify');
var less = require('less');
var mv = require('mv');
//
// ─── P ──────────────────────────────────────────────────────────────────────────
//
function p ( message ) {
console.log( message );
}
//
// ─── CONSTS ─────────────────────────────────────────────────────────────────────
//
const resultDirPath = '_compiled';
//
// ─── TOOLS ──────────────────────────────────────────────────────────────────────
//
/** Run shell commands easy! */
function shell ( command , callback ) {
exec( command, err => {
if ( err ) return callback( err );
callback( );
});
}
//
// ─── COPY DIR FILES ─────────────────────────────────────────────────────────────
//
/** Copy to binary from dir */
function copyToBinaryFromDir ( dir ) {
fs.readdir( dir , ( err , files ) => {
// if error
if ( err ) {
console.log(`Could not get files from directory ${ dir }`);
}
// if right
files.forEach( name => {
copyFile(
getLocalPath( path.join( dir , name ) ),
getLocalPath( path.join( resultDirPath , name ) )
);
});
});
}
//
// ─── COPY SINGLE FILE ───────────────────────────────────────────────────────────
//
/** Copy file `A` to `B` */
function copyFile ( A, B ) {
if ( /\.DS_Store/.test( A ) ) {
return;
}
fs.copy( A, B, err => {
if ( err ) {
console.log(`Could not copy file ${ A }`);
}
});
}
//
// ─── GET LOCAL PATH ─────────────────────────────────────────────────────────────
//
/** Get Local Path in the current directory */
function getLocalPath ( address ) {
return path.join( __dirname , address );
}
//
// ─── COMPILING TYPE SCRIPT ──────────────────────────────────────────────────────
//
/** Compiles the TypeScript code */
gulp.task('typescript', callback => {
shell('tsc', callback);
});
//
// ─── UGLIFYING ──────────────────────────────────────────────────────────────────
//
/** Minify the result code from TypeScript */
gulp.task( 'minifyCore', ['typescript'], callback => {
callback();
});
//
// ─── COPY FILES ─────────────────────────────────────────────────────────────────
//
/** Copies static resource files into the result directory */
gulp.task( 'copyResourceFiles', callback => {
copyToBinaryFromDir( 'resources' );
copyToBinaryFromDir( 'view' );
copyToBinaryFromDir( 'electron' );
copyToBinaryFromDir( 'wrappers' );
copyToBinaryFromDir( 'libs' );
copyToBinaryFromDir( 'javascript' );
copyToBinaryFromDir( path.join( 'node_modules', 'monaco-editor', 'min' ) );
callback();
});
//
// ─── COPY NODE RESOURCES ────────────────────────────────────────────────────────
//
gulp.task( 'resources', ['copyResourceFiles'], callback => {
// fixing monaco folders name
/*mv(
path.join( resultDirPath , 'vs' ),
path.join( resultDirPath , 'monaco' ),
{
mkdirp: true,
clobber: false
},
error => {
if ( error ) {
console.log('could not fix the name of monaco folder...');
}
}
);*/
});
//
// ─── SHEETS ─────────────────────────────────────────────────────────────────────
//
/** Compiles the Less style sheets */
gulp.task( 'sheets', callback => {
try {
let lessSourceCode = fs.readFileSync(
path.join( __dirname, 'sheets', 'ui.less' ), 'utf8' );
less.render( lessSourceCode, ( err, output ) => {
if ( err ) {
console.log(`Less failure: ${ err }`); return;
}
fs.writeFile(
path.join( __dirname, '_compiled/style.css' ),
output.css,
error => {
if ( error ) {
console.log('could not store the less file');
} else {
console.log('compiled less source codes successfully...');
callback();
}
}
);
});
} catch ( err ) {
console.log('Compiling less failed ' + err );
}
});
//
// ─── MAIN ───────────────────────────────────────────────────────────────────────
//
/** Where everything starts */
gulp.task('default', ['typescript', 'resources', 'sheets']);
// ────────────────────────────────────────────────────────────────────────────────