@@ -8,10 +8,9 @@ import minify from 'gulp-minify'
8
8
9
9
dotconfig . config ( )
10
10
11
- // console.log(process.env)
12
-
13
11
/**
14
12
* Different paths we use...
13
+ * Don't modify this directly, use the environment variables
15
14
*/
16
15
const paths = {
17
16
src : './src' ,
@@ -24,12 +23,66 @@ const paths = {
24
23
acars : process . env . ACARS_SCRIPTS_PATH ,
25
24
}
26
25
26
+ /**
27
+ * Build the project, copy the appropriate files over
28
+ * @public
29
+ */
30
+ export const build = series ( buildTsTask , copyPackageTask )
31
+
32
+ /**
33
+ * Build a distribution zip file, which can be easily uploaded
34
+ * @public
35
+ */
36
+ export const dist = series (
37
+ build ,
38
+ buildZipTask ,
39
+ )
40
+
41
+ /**
42
+ * Watch the files and distribute them to the
43
+ * documents/vmsacars/data/<profile>/config directory
44
+ * @public
45
+ */
46
+ export const local = localTask
47
+
48
+
49
+ /**
50
+ * The default action
51
+ * @default
52
+ * @public
53
+ */
54
+ export default build
55
+
56
+
57
+ /**
58
+ * The build steps that run from the csproj
59
+ * Force the output path to go into our build directory
60
+ * @internal
61
+ */
62
+ export const csbuild = series (
63
+ async ( ) => {
64
+ paths . acars = '../Content/config/default'
65
+ } ,
66
+ build ,
67
+ copyFilesToScriptsPathTask ,
68
+ )
69
+
70
+ /**
71
+ *
72
+ *
73
+ *
74
+ */
75
+
27
76
/**
28
77
* Configure the ts transpilation
29
78
*/
30
79
const tsProject = ts . createProject ( 'tsconfig.json' )
31
80
32
- function build_ts ( ) {
81
+ /**
82
+ * Build the Typescript files
83
+ * @returns {module:stream.Stream.Transform | * }
84
+ */
85
+ async function buildTsTask ( ) {
33
86
let pipeline = tsProject . src ( )
34
87
. pipe ( eslint ( ) )
35
88
. pipe ( eslint . failAfterError ( ) )
@@ -43,7 +96,8 @@ function build_ts() {
43
96
mangle: false,
44
97
}))*/
45
98
46
- pipeline = pipeline . pipe ( dest ( paths . dist ) )
99
+ pipeline = pipeline
100
+ . pipe ( dest ( paths . dist ) )
47
101
48
102
return pipeline
49
103
}
@@ -52,120 +106,65 @@ function build_ts() {
52
106
*
53
107
* @returns {* }
54
108
*/
55
- function copy_package ( ) {
109
+ async function copyPackageTask ( ) {
56
110
return src ( [ paths . src + '/package.json' ] )
57
111
. pipe ( dest ( paths . dist ) )
58
112
}
59
113
60
- /**
61
- * Build the project, copy the appropriate files over
62
- */
63
- export const build = series ( build_ts , copy_package )
64
-
65
114
/**
66
115
* Copy the files from dist into ACARS_SCRIPTS_PATH
67
116
*
68
117
*/
69
- export function copy ( ) {
118
+ export async function copyFilesToScriptsPathTask ( ) {
70
119
console . log ( `Copying files to ${ paths . acars } ` )
71
120
72
- return src ( [ './**/*' , '!node_modules/**/*' ] , { 'cwd' : paths . dist } )
121
+ return src (
122
+ [
123
+ './**/*' ,
124
+ '!node_modules/**/*' ,
125
+ ] ,
126
+ { 'cwd' : paths . dist } ,
127
+ )
73
128
. pipe ( dest ( paths . acars ) )
74
129
}
75
130
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
131
88
132
/**
89
133
* TODO: Build the distribution zip file
90
134
*/
91
- function build_dist ( ) {
135
+ function buildZipTask ( ) {
92
136
93
137
}
94
138
95
- /**
96
- * Build a distribution zip file, which can be easily uploaded
97
- */
98
- export const dist = series (
99
- build ,
100
- build_dist ,
101
- )
102
139
103
140
/**
104
141
* Watch the src folder for updates, compile them and then copy them
105
142
* to the config directory. ACARS should auto-reload
106
143
*/
107
- export async function testing ( ) {
144
+ export async function testingTask ( ) {
108
145
watch ( 'src/' , {
109
146
ignoreInitial : false ,
110
147
delay : 500 ,
111
- } , series ( build , copy ) )
148
+ } , series ( build , copyFilesToScriptsPathTask ) )
112
149
}
113
150
114
151
/**
115
- * Watch the files and distribute them out
152
+ * Watch the files and then build and copy them to the documents directory
116
153
*/
117
- export function watchFiles ( ) {
118
- watch ( 'src/' , build )
154
+ export async function localTask ( ) {
155
+ return watch ( 'src/' , { ignoreInitial : false } , series ( build , copyFilesToScriptsPathTask ) , function ( ) {
156
+ cb ( )
157
+ } )
119
158
}
120
159
121
- export { watchFiles as watch }
122
-
123
160
/**
124
161
* Clean up the /dest directory
125
162
*/
126
- export async function clean ( ) {
163
+ export async function cleanTask ( ) {
127
164
try {
128
165
await deleteAsync ( [ paths . dist ] )
129
166
await Promise . resolve ( )
130
167
} catch ( e ) {
131
168
console . log ( e )
132
169
}
133
170
}
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