Skip to content

Commit 09ac86d

Browse files
committed
Zip generation
1 parent f225b1d commit 09ac86d

File tree

3 files changed

+280
-116
lines changed

3 files changed

+280
-116
lines changed

gulpfile.mjs

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
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

@@ -13,27 +16,38 @@ dotconfig.config()
1316
* Don't modify this directly, use the environment variables
1417
*/
1518
const paths = {
16-
src: './src',
17-
dist: './dist',
18-
1919
/**
2020
* ACARS scripts/config directory. This, by default, points to the home directory
2121
* But you can change this to point to a local directory
2222
*/
2323
acars: process.env.ACARS_SCRIPTS_PATH,
24+
25+
src: './src',
26+
out: './dist',
27+
export: './dist',
2428
}
2529

2630
/**
2731
* Build the project, copy the appropriate files over
2832
* @public
2933
*/
30-
export const build = series(buildTsTask, copyPackageTask)
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
3144

3245
/**
3346
* Build a distribution zip file, which can be easily uploaded
3447
* @public
3548
*/
3649
export const dist = series(
50+
clean,
3751
build,
3852
buildZipTask,
3953
)
@@ -43,16 +57,7 @@ export const dist = series(
4357
* documents/vmsacars/data/<profile>/config directory
4458
* @public
4559
*/
46-
export const local = localTask
47-
48-
49-
/**
50-
* The default action
51-
* @default
52-
* @public
53-
*/
54-
export default build
55-
60+
export const local = localBuildTask
5661

5762
/**
5863
* The build steps that run from the csproj
@@ -64,9 +69,17 @@ export const csbuild = series(
6469
paths.acars = '../Content/config/default'
6570
},
6671
build,
67-
copyFilesToScriptsPathTask,
72+
copyFilesToAcarsPathTask,
6873
)
6974

75+
76+
/**
77+
* The default action
78+
* @default
79+
* @public
80+
*/
81+
export default build
82+
7083
/**
7184
*
7285
*
@@ -75,14 +88,19 @@ export const csbuild = series(
7588

7689
/**
7790
* Configure the ts transpilation
91+
*
7892
*/
7993
const tsProject = ts.createProject('tsconfig.json')
8094

8195
/**
8296
* Build the Typescript files
83-
* @returns {module:stream.Stream.Transform | *}
8497
*/
85-
async function buildTsTask() {
98+
function buildTsTask() {
99+
// ensure the dist directory exists
100+
if (!fs.existsSync(paths.out)) {
101+
fs.mkdirSync(paths.out)
102+
}
103+
86104
let pipeline = tsProject.src()
87105
.pipe(eslint())
88106
.pipe(eslint.failAfterError())
@@ -96,75 +114,71 @@ async function buildTsTask() {
96114
mangle: false,
97115
}))*/
98116

99-
pipeline = pipeline
100-
.pipe(dest(paths.dist))
117+
pipeline = pipeline.pipe(dest(paths.out))
101118

102119
return pipeline
103120
}
104121

105122
/**
123+
* This copies the package.json file to the output directory
106124
*
107-
* @returns {*}
108125
*/
109-
async function copyPackageTask() {
126+
function copyPackageJsonTask() {
110127
return src([paths.src + '/package.json'])
111-
.pipe(dest(paths.dist))
128+
.pipe(dest(paths.out))
112129
}
113130

114131
/**
115132
* Copy the files from dist into ACARS_SCRIPTS_PATH
116-
*
117133
*/
118-
export async function copyFilesToScriptsPathTask() {
134+
function copyFilesToAcarsPathTask() {
119135
console.log(`Copying files to ${paths.acars}`)
120136

121137
return src(
122138
[
123139
'./**/*',
124140
'!node_modules/**/*',
125141
],
126-
{ 'cwd': paths.dist },
142+
{ 'cwd': paths.out },
127143
)
128144
.pipe(dest(paths.acars))
129145
}
130146

131147

132148
/**
133-
* TODO: Build the distribution zip file
149+
* Build the zip that should get uploaded
134150
*/
135151
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+
}
136156

137-
}
138-
139-
140-
/**
141-
* Watch the src folder for updates, compile them and then copy them
142-
* to the config directory. ACARS should auto-reload
143-
*/
144-
export async function testingTask() {
145-
watch('src/', {
146-
ignoreInitial: false,
147-
delay: 500,
148-
}, series(build, copyFilesToScriptsPathTask))
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))
149163
}
150164

151165
/**
152166
* Watch the files and then build and copy them to the documents directory
153167
*/
154-
export async function localTask() {
155-
return watch('src/', { ignoreInitial: false }, series(build, copyFilesToScriptsPathTask), function() {
156-
cb()
157-
})
168+
function localBuildTask() {
169+
return watch(
170+
paths.src,
171+
{ ignoreInitial: false },
172+
series(build, copyFilesToAcarsPathTask)
173+
)
158174
}
159175

160176
/**
161177
* Clean up the /dest directory
162178
*/
163-
export async function cleanTask() {
164-
try {
165-
await deleteAsync([paths.dist])
166-
await Promise.resolve()
167-
} catch (e) {
168-
console.log(e)
169-
}
179+
async function cleanTask() {
180+
return del([
181+
paths.out,
182+
paths.export + '/' + process.env.ACARS_DIST_ZIP
183+
])
170184
}

0 commit comments

Comments
 (0)