1
1
import dotconfig from '@dotenvx/dotenvx'
2
- import { deleteAsync } from 'del'
2
+ import { deleteSync as del } from 'del'
3
3
import { dest , series , src , watch } from 'gulp'
4
4
import eslint from 'gulp-eslint-new'
5
5
import ts from 'gulp-typescript'
6
6
import prettier from 'gulp-prettier'
7
+ import zip from 'gulp-zip'
8
+ import tap from 'gulp-tap'
7
9
import minify from 'gulp-minify'
10
+ import fs from 'fs'
8
11
9
12
dotconfig . config ( )
10
13
11
- // console.log(process.env)
12
-
13
14
/**
14
15
* Different paths we use...
16
+ * Don't modify this directly, use the environment variables
15
17
*/
16
18
const paths = {
17
- src : './src' ,
18
- dist : './dist' ,
19
-
20
19
/**
21
20
* ACARS scripts/config directory. This, by default, points to the home directory
22
21
* But you can change this to point to a local directory
23
22
*/
24
23
acars : process . env . ACARS_SCRIPTS_PATH ,
24
+
25
+ src : './src' ,
26
+ out : './dist' ,
27
+ export : './dist' ,
25
28
}
26
29
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
+
27
89
/**
28
90
* Configure the ts transpilation
91
+ *
29
92
*/
30
93
const tsProject = ts . createProject ( 'tsconfig.json' )
31
94
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
+
33
104
let pipeline = tsProject . src ( )
34
105
. pipe ( eslint ( ) )
35
106
. pipe ( eslint . failAfterError ( ) )
@@ -43,129 +114,71 @@ function build_ts() {
43
114
mangle: false,
44
115
}))*/
45
116
46
- pipeline = pipeline . pipe ( dest ( paths . dist ) )
117
+ pipeline = pipeline . pipe ( dest ( paths . out ) )
47
118
48
119
return pipeline
49
120
}
50
121
51
122
/**
123
+ * This copies the package.json file to the output directory
52
124
*
53
- * @returns {* }
54
125
*/
55
- function copy_package ( ) {
126
+ function copyPackageJsonTask ( ) {
56
127
return src ( [ paths . src + '/package.json' ] )
57
- . pipe ( dest ( paths . dist ) )
128
+ . pipe ( dest ( paths . out ) )
58
129
}
59
130
60
- /**
61
- * Build the project, copy the appropriate files over
62
- */
63
- export const build = series ( build_ts , copy_package )
64
-
65
131
/**
66
132
* Copy the files from dist into ACARS_SCRIPTS_PATH
67
- *
68
133
*/
69
- export function copy ( ) {
134
+ function copyFilesToAcarsPathTask ( ) {
70
135
console . log ( `Copying files to ${ paths . acars } ` )
71
136
72
- return src ( [ './**/*' , '!node_modules/**/*' ] , { 'cwd' : paths . dist } )
137
+ return src (
138
+ [
139
+ './**/*' ,
140
+ '!node_modules/**/*' ,
141
+ ] ,
142
+ { 'cwd' : paths . out } ,
143
+ )
73
144
. pipe ( dest ( paths . acars ) )
74
145
}
75
146
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
- }
94
147
95
148
/**
96
- * Build a distribution zip file, which can be easily uploaded
149
+ * Build the zip that should get uploaded
97
150
*/
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
+ }
102
156
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 ) )
112
163
}
113
164
114
165
/**
115
- * Watch the files and distribute them out
166
+ * Watch the files and then build and copy them to the documents directory
116
167
*/
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
+ )
119
174
}
120
175
121
- export { watchFiles as watch }
122
-
123
176
/**
124
177
* Clean up the /dest directory
125
178
*/
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
+ ] )
133
184
}
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