-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
187 lines (163 loc) · 3.73 KB
/
gulpfile.mjs
File metadata and controls
187 lines (163 loc) · 3.73 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
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
187
import dotconfig from '@dotenvx/dotenvx'
import { deleteSync as del } from 'del'
import fs from 'fs'
import { dest, series, src, watch } from 'gulp'
import eslint from 'gulp-eslint-new'
import prettier from 'gulp-prettier'
import ts from 'gulp-typescript'
import zip from 'gulp-zip'
dotconfig.config()
/**
* Different paths we use...
* Don't modify this directly, use the environment variables
*/
const paths = {
/**
* ACARS scripts/config directory. This, by default, points to the home directory
* But you can change this to point to a local directory
*/
acars: process.env.ACARS_SCRIPTS_PATH,
src: './src',
out: './dist',
export: './dist',
}
/**
* Build the project, copy the appropriate files over
* @public
*/
export const build = series(buildTsTask, copySoundsTask, copyPackageJsonTask)
/**
* Clean the build directories
* @public
*/
export const clean = cleanTask
/**
* Build a distribution zip file, which can be easily uploaded
* @public
*/
export const dist = series(clean, build, buildZipTask)
/**
* Watch the files and distribute them to the
* documents/vmsacars/data/<profile>/config directory
* @public
*/
export const dev = localBuildTask
/**
* The build steps that run from the csproj
* Force the output path to go into our build directory
* @internal
*/
export const csbuild = series(
async () => {
paths.acars = '../Content/config/default'
},
build,
copyFilesToAcarsPathTask,
)
/**
* The default action
* @default
* @public
*/
export default build
/**
*
*
*
*/
/**
* Configure the ts transpilation
*
*/
const tsProject = ts.createProject('tsconfig.json')
/**
* Build the Typescript files
*/
function buildTsTask() {
// ensure the dist directory exists
if (!fs.existsSync(paths.out)) {
fs.mkdirSync(paths.out)
}
let pipeline = tsProject
.src()
.pipe(eslint())
.pipe(eslint.failAfterError())
.pipe(tsProject())
.js.pipe(prettier())
.pipe(dest(paths.out))
// Minify/mangle output
/*
pipeline = pipeline.pipe(minify({
mangle: false,
}))*/
return pipeline
}
/**
* This copies the package.json file to the output directory
*
*/
function copySoundsTask() {
return src([paths.src + '/sounds/**/*'], { encoding: false }).pipe(
dest(paths.out + '/sounds'),
)
}
/**
* This copies the package.json file to the output directory
*
*/
function copyPackageJsonTask() {
return src([paths.src + '/package.json']).pipe(dest(paths.out))
}
/**
* Copy the files from dist into ACARS_SCRIPTS_PATH
*/
function copyFilesToAcarsPathTask() {
console.log(`Copying files to ${paths.acars}`)
return src(['./**/*', '!node_modules/**/*'], { cwd: paths.out }).pipe(
dest(paths.acars),
)
}
/**
* Build the zip that should get uploaded
*/
function buildZipTask() {
console.log('Writing zip named ' + process.env.ACARS_DIST_ZIP)
if (!fs.existsSync(paths.export)) {
fs.mkdirSync(paths.export)
}
return (
src(paths.out + '/**/*', { base: paths.out })
/*.pipe(tap(function (file) {
console.log('file: ' + file.path)
}))*/
.pipe(zip(process.env.ACARS_DIST_ZIP, { buffer: true }))
.pipe(dest(paths.export))
)
}
/**
* Watch the files and then build and copy them to the documents directory
*/
function localBuildTask() {
return watch(
paths.src,
{ ignoreInitial: false },
series(build, copyFilesToAcarsPathTask),
)
}
/**
* Clean up the /dest directory
*/
async function cleanTask() {
return del([paths.out, paths.export + '/' + process.env.ACARS_DIST_ZIP])
}
/**
* Copy the PDK files to the PDK and config repos
* @internal
* @returns {Promise<void>}
*/
function updatePdk() {
if (!process.env.PDK_DEST || !process.env.CFG_DEST) {
console.error('PDK_DEST and CFG_DEST must be set')
return
}
}