generated from phpvms/acars-pdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.mjs
155 lines (131 loc) · 3.25 KB
/
gulpfile.mjs
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
import dotconfig from '@dotenvx/dotenvx'
import { deleteAsync } from 'del'
import fs from 'fs'
import { dest, series, src, watch } from 'gulp'
import eslint from 'gulp-eslint-new'
import ts from 'gulp-typescript'
dotconfig.config()
// console.log(process.env)
/**
* Different paths we use...
*/
const paths = {
src: './src',
dist: './dist',
/**
* 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,
}
/**
* Configure the ts transpilation
*/
const tsProject = ts.createProject('tsconfig.json')
function build_ts() {
return tsProject.src()
.pipe(eslint())
.pipe(eslint.failAfterError())
.pipe(tsProject())
.js.pipe(dest(paths.dist))
}
function copy_package() {
return src([paths.src + '/package.json'])
.pipe(dest(paths.dist))
}
/**
* Build the project, copy the appropriate files over
*/
export const build = series(build_ts, copy_package)
/**
* Copy the files from dist into ACARS_SCRIPTS_PATH
*
*/
export function copy() {
console.log(`Copying files to ${paths.acars}`)
return src(['./**/*', '!node_modules/**/*'], { 'cwd': paths.dist })
.pipe(dest(paths.acars))
}
/**
* The build steps that run from the csproj
* Force the output path to go into our build directory
*/
export const csbuild = series(
async () => {
paths.acars = '../Content/config/default'
},
build,
copy,
)
/**
* TODO: Build the distribution zip file
*/
function build_dist() {
}
/**
* Build a distribution zip file, which can be easily uploaded
*/
export const dist = series(
build,
build_dist,
)
/**
* Watch the src folder for updates, compile them and then copy them
* to the config directory. ACARS should auto-reload
*/
export async function testing() {
watch('src/', {
ignoreInitial: false,
delay: 500,
}, series(build, copy))
}
/**
* Watch the files and distribute them out
*/
export function watchFiles() {
watch('src/', build)
}
export { watchFiles as watch }
/**
* Clean up the /dest directory
*/
export async function clean() {
try {
await deleteAsync([paths.dist])
await Promise.resolve()
} catch (e) {
console.log(e)
}
}
/**
* The default action
*/
export default build
/**
* Get the default profile name
*
* @returns {*}
*/
/*async function getDefaultProfilePath() {
if (profileName === null || profileName === '') {
const f = await fs.promises.readFile(`${paths.acars}/settings.json`)
const settings = JSON.parse(f)
profileName = settings.Profile
console.log('No profile name set, looked in settings and used ' + profileName)
}
// Read all of the profiles
let dirent
const dir = await fs.promises.opendir(`${paths.acars}/profiles`)
for await (const dirent of dir) {
const pf = await fs.promises.readFile(`${dirent.parentPath}/${dirent.name}`)
if (pf === null) {
continue
}
const profile = JSON.parse(pf)
console.log(profile)
if (profile.Name === profileName) {
return `${paths.acars}/data/${profile.Domain}/config/`
}
}
return null
}*/