Skip to content

Commit ddbfd92

Browse files
committed
Sync with the pdk
1 parent e0d24bb commit ddbfd92

File tree

4 files changed

+340
-177
lines changed

4 files changed

+340
-177
lines changed

gulpfile.mjs

+114-101
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,106 @@
11
import dotconfig from '@dotenvx/dotenvx'
2-
import { deleteAsync } from 'del'
2+
import { deleteSync as del } from 'del'
33
import { dest, series, src, watch } from 'gulp'
44
import eslint from 'gulp-eslint-new'
55
import ts from 'gulp-typescript'
66
import prettier from 'gulp-prettier'
7+
import zip from 'gulp-zip'
8+
import tap from 'gulp-tap'
79
import minify from 'gulp-minify'
10+
import fs from 'fs'
811

912
dotconfig.config()
1013

11-
// console.log(process.env)
12-
1314
/**
1415
* Different paths we use...
16+
* Don't modify this directly, use the environment variables
1517
*/
1618
const paths = {
17-
src: './src',
18-
dist: './dist',
19-
2019
/**
2120
* ACARS scripts/config directory. This, by default, points to the home directory
2221
* But you can change this to point to a local directory
2322
*/
2423
acars: process.env.ACARS_SCRIPTS_PATH,
24+
25+
src: './src',
26+
out: './dist',
27+
export: './dist',
2528
}
2629

30+
/**
31+
* Build the project, copy the appropriate files over
32+
* @public
33+
*/
34+
export const build = series(
35+
buildTsTask,
36+
copyPackageJsonTask,
37+
)
38+
39+
/**
40+
* Clean the build directories
41+
* @public
42+
*/
43+
export const clean = cleanTask
44+
45+
/**
46+
* Build a distribution zip file, which can be easily uploaded
47+
* @public
48+
*/
49+
export const dist = series(
50+
clean,
51+
build,
52+
buildZipTask,
53+
)
54+
55+
/**
56+
* Watch the files and distribute them to the
57+
* documents/vmsacars/data/<profile>/config directory
58+
* @public
59+
*/
60+
export const local = localBuildTask
61+
62+
/**
63+
* The build steps that run from the csproj
64+
* Force the output path to go into our build directory
65+
* @internal
66+
*/
67+
export const csbuild = series(
68+
async () => {
69+
paths.acars = '../Content/config/default'
70+
},
71+
build,
72+
copyFilesToAcarsPathTask,
73+
)
74+
75+
76+
/**
77+
* The default action
78+
* @default
79+
* @public
80+
*/
81+
export default build
82+
83+
/**
84+
*
85+
*
86+
*
87+
*/
88+
2789
/**
2890
* Configure the ts transpilation
91+
*
2992
*/
3093
const tsProject = ts.createProject('tsconfig.json')
3194

32-
function build_ts() {
95+
/**
96+
* Build the Typescript files
97+
*/
98+
function buildTsTask() {
99+
// ensure the dist directory exists
100+
if (!fs.existsSync(paths.out)) {
101+
fs.mkdirSync(paths.out)
102+
}
103+
33104
let pipeline = tsProject.src()
34105
.pipe(eslint())
35106
.pipe(eslint.failAfterError())
@@ -43,129 +114,71 @@ function build_ts() {
43114
mangle: false,
44115
}))*/
45116

46-
pipeline = pipeline.pipe(dest(paths.dist))
117+
pipeline = pipeline.pipe(dest(paths.out))
47118

48119
return pipeline
49120
}
50121

51122
/**
123+
* This copies the package.json file to the output directory
52124
*
53-
* @returns {*}
54125
*/
55-
function copy_package() {
126+
function copyPackageJsonTask() {
56127
return src([paths.src + '/package.json'])
57-
.pipe(dest(paths.dist))
128+
.pipe(dest(paths.out))
58129
}
59130

60-
/**
61-
* Build the project, copy the appropriate files over
62-
*/
63-
export const build = series(build_ts, copy_package)
64-
65131
/**
66132
* Copy the files from dist into ACARS_SCRIPTS_PATH
67-
*
68133
*/
69-
export function copy() {
134+
function copyFilesToAcarsPathTask() {
70135
console.log(`Copying files to ${paths.acars}`)
71136

72-
return src(['./**/*', '!node_modules/**/*'], { 'cwd': paths.dist })
137+
return src(
138+
[
139+
'./**/*',
140+
'!node_modules/**/*',
141+
],
142+
{ 'cwd': paths.out },
143+
)
73144
.pipe(dest(paths.acars))
74145
}
75146

76-
/**
77-
* The build steps that run from the csproj
78-
* Force the output path to go into our build directory
79-
*/
80-
export const csbuild = series(
81-
async () => {
82-
paths.acars = '../Content/config/default'
83-
},
84-
build,
85-
copy,
86-
)
87-
88-
/**
89-
* TODO: Build the distribution zip file
90-
*/
91-
function build_dist() {
92-
93-
}
94147

95148
/**
96-
* Build a distribution zip file, which can be easily uploaded
149+
* Build the zip that should get uploaded
97150
*/
98-
export const dist = series(
99-
build,
100-
build_dist,
101-
)
151+
function buildZipTask() {
152+
console.log('Writing zip named ' + process.env.ACARS_DIST_ZIP)
153+
if (!fs.existsSync(paths.export)) {
154+
fs.mkdirSync(paths.export)
155+
}
102156

103-
/**
104-
* Watch the src folder for updates, compile them and then copy them
105-
* to the config directory. ACARS should auto-reload
106-
*/
107-
export async function testing() {
108-
watch('src/', {
109-
ignoreInitial: false,
110-
delay: 500,
111-
}, series(build, copy))
157+
return src(paths.out + '/**/*', { base: paths.out })
158+
/*.pipe(tap(function (file) {
159+
console.log('file: ' + file.path)
160+
}))*/
161+
.pipe(zip(process.env.ACARS_DIST_ZIP, { buffer: true}))
162+
.pipe(dest(paths.export))
112163
}
113164

114165
/**
115-
* Watch the files and distribute them out
166+
* Watch the files and then build and copy them to the documents directory
116167
*/
117-
export function watchFiles() {
118-
watch('src/', build)
168+
function localBuildTask() {
169+
return watch(
170+
paths.src,
171+
{ ignoreInitial: false },
172+
series(build, copyFilesToAcarsPathTask)
173+
)
119174
}
120175

121-
export { watchFiles as watch }
122-
123176
/**
124177
* Clean up the /dest directory
125178
*/
126-
export async function clean() {
127-
try {
128-
await deleteAsync([paths.dist])
129-
await Promise.resolve()
130-
} catch (e) {
131-
console.log(e)
132-
}
179+
async function cleanTask() {
180+
return del([
181+
paths.out,
182+
paths.export + '/' + process.env.ACARS_DIST_ZIP
183+
])
133184
}
134-
135-
/**
136-
* The default action
137-
*/
138-
export default build
139-
140-
/**
141-
* Get the default profile name
142-
*
143-
* @returns {*}
144-
*/
145-
/*async function getDefaultProfilePath() {
146-
if (profileName === null || profileName === '') {
147-
const f = await fs.promises.readFile(`${paths.acars}/settings.json`)
148-
const settings = JSON.parse(f)
149-
profileName = settings.Profile
150-
console.log('No profile name set, looked in settings and used ' + profileName)
151-
}
152-
153-
// Read all of the profiles
154-
let dirent
155-
const dir = await fs.promises.opendir(`${paths.acars}/profiles`)
156-
for await (const dirent of dir) {
157-
const pf = await fs.promises.readFile(`${dirent.parentPath}/${dirent.name}`)
158-
if (pf === null) {
159-
continue
160-
}
161-
162-
const profile = JSON.parse(pf)
163-
console.log(profile)
164-
165-
if (profile.Name === profileName) {
166-
return `${paths.acars}/data/${profile.Domain}/config/`
167-
}
168-
}
169-
170-
return null
171-
}*/

0 commit comments

Comments
 (0)