@@ -8,10 +8,9 @@ import minify from 'gulp-minify'
88
99dotconfig . config ( )
1010
11- // console.log(process.env)
12-
1311/**
1412 * Different paths we use...
13+ * Don't modify this directly, use the environment variables
1514 */
1615const paths = {
1716 src : './src' ,
@@ -24,12 +23,66 @@ const paths = {
2423 acars : process . env . ACARS_SCRIPTS_PATH ,
2524}
2625
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+
2776/**
2877 * Configure the ts transpilation
2978 */
3079const tsProject = ts . createProject ( 'tsconfig.json' )
3180
32- function build_ts ( ) {
81+ /**
82+ * Build the Typescript files
83+ * @returns {module:stream.Stream.Transform | * }
84+ */
85+ async function buildTsTask ( ) {
3386 let pipeline = tsProject . src ( )
3487 . pipe ( eslint ( ) )
3588 . pipe ( eslint . failAfterError ( ) )
@@ -43,7 +96,8 @@ function build_ts() {
4396 mangle: false,
4497 }))*/
4598
46- pipeline = pipeline . pipe ( dest ( paths . dist ) )
99+ pipeline = pipeline
100+ . pipe ( dest ( paths . dist ) )
47101
48102 return pipeline
49103}
@@ -52,120 +106,65 @@ function build_ts() {
52106 *
53107 * @returns {* }
54108 */
55- function copy_package ( ) {
109+ async function copyPackageTask ( ) {
56110 return src ( [ paths . src + '/package.json' ] )
57111 . pipe ( dest ( paths . dist ) )
58112}
59113
60- /**
61- * Build the project, copy the appropriate files over
62- */
63- export const build = series ( build_ts , copy_package )
64-
65114/**
66115 * Copy the files from dist into ACARS_SCRIPTS_PATH
67116 *
68117 */
69- export function copy ( ) {
118+ export async function copyFilesToScriptsPathTask ( ) {
70119 console . log ( `Copying files to ${ paths . acars } ` )
71120
72- return src ( [ './**/*' , '!node_modules/**/*' ] , { 'cwd' : paths . dist } )
121+ return src (
122+ [
123+ './**/*' ,
124+ '!node_modules/**/*' ,
125+ ] ,
126+ { 'cwd' : paths . dist } ,
127+ )
73128 . pipe ( dest ( paths . acars ) )
74129}
75130
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- )
87131
88132/**
89133 * TODO: Build the distribution zip file
90134 */
91- function build_dist ( ) {
135+ function buildZipTask ( ) {
92136
93137}
94138
95- /**
96- * Build a distribution zip file, which can be easily uploaded
97- */
98- export const dist = series (
99- build ,
100- build_dist ,
101- )
102139
103140/**
104141 * Watch the src folder for updates, compile them and then copy them
105142 * to the config directory. ACARS should auto-reload
106143 */
107- export async function testing ( ) {
144+ export async function testingTask ( ) {
108145 watch ( 'src/' , {
109146 ignoreInitial : false ,
110147 delay : 500 ,
111- } , series ( build , copy ) )
148+ } , series ( build , copyFilesToScriptsPathTask ) )
112149}
113150
114151/**
115- * Watch the files and distribute them out
152+ * Watch the files and then build and copy them to the documents directory
116153 */
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+ } )
119158}
120159
121- export { watchFiles as watch }
122-
123160/**
124161 * Clean up the /dest directory
125162 */
126- export async function clean ( ) {
163+ export async function cleanTask ( ) {
127164 try {
128165 await deleteAsync ( [ paths . dist ] )
129166 await Promise . resolve ( )
130167 } catch ( e ) {
131168 console . log ( e )
132169 }
133170}
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