1
1
import * as esbuild from 'esbuild'
2
2
//import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
3
3
import * as fs from 'fs' ;
4
+ import { simpleGit , CleanOptions } from 'simple-git' ;
5
+ import JSZip from 'jszip' ;
4
6
5
7
//const path = require('path')
6
8
@@ -16,12 +18,36 @@ var defaultconfig = {
16
18
//watch: process.argv.includes("--watch"),
17
19
} ;
18
20
21
+ function buildRelease ( ) {
22
+ simpleGit ( ) . tags ( ) . then ( res => {
23
+ const regversion = / v ( \d + \. \d + \. \d + ) / i;
24
+ let matches = null ;
25
+ if ( ! res || ! ( matches = res . latest . match ( regversion ) ) || matches . length < 2 ) throw new Error ( 'No valid version found' ) ;
26
+ console . log ( `Releasing '${ matches [ 1 ] } '...` ) ;
27
+ let zipname = `igc2kmz-${ matches [ 1 ] } .zip` ;
28
+ let zip = new JSZip ( ) ;
29
+ [ 'igc2kmz.cmd.js' , 'igc2kmz.min.js' , 'igc2kmz.js' ] . forEach ( f => zip . file ( 'dist/' + f , fs . readFileSync ( 'dist/' + f , { encoding : 'utf8' , flag : 'r' } ) ) ) ;
30
+ zip . file ( 'igc2kmz_spa.html' , fs . readFileSync ( 'dist/igc2kmz_spa.html' , { encoding : 'utf8' , flag : 'r' } ) ) ;
31
+ [ 'igc2kmz.html' , 'README.md' , 'LICENSE' ] . forEach ( f => zip . file ( f , fs . readFileSync ( f , { encoding : 'utf8' , flag : 'r' } ) ) ) ;
32
+ zip
33
+ . generateNodeStream ( { type : 'nodebuffer' , streamFiles : true } )
34
+ . pipe ( fs . createWriteStream ( zipname ) )
35
+ . on ( 'finish' , function ( ) {
36
+ console . log ( zipname + " written." ) ;
37
+ } ) ;
38
+ } ) ;
39
+ }
40
+
19
41
async function buildAction ( buildmode ) {
20
- console . log ( `Building '${ buildmode } '...` ) ;
21
- let build = true , bundle = false ;
42
+ let build = true , bundle = false , release = false ;
22
43
let config = { } ;
23
44
24
45
switch ( buildmode ) {
46
+ case 'release' :
47
+ release = true ;
48
+ build = false ;
49
+ bundle = false ;
50
+ break ;
25
51
case 'bundle' :
26
52
build = false ;
27
53
bundle = true ;
@@ -55,6 +81,7 @@ async function buildAction(buildmode) {
55
81
}
56
82
57
83
if ( build ) {
84
+ console . log ( `Building '${ buildmode } '...` ) ;
58
85
await esbuild . build ( config ) . catch ( ( ) => process . exit ( 1 ) ) ;
59
86
// contournement d'un bug dans collections.js utilisée par igc-xc-score ;
60
87
// dans le fichier generic-collections.js est référencé directement l'objet global
@@ -69,6 +96,7 @@ async function buildAction(buildmode) {
69
96
}
70
97
}
71
98
if ( bundle ) {
99
+ console . log ( `Bundling igc2html_spa.html...` ) ;
72
100
// BUNDLE
73
101
const reginsert = / < s c r i p t [ \s \r \n ] + s r c \s * = \s * (?: " | ' ) ( [ ^ " ' ] + ) (?: " | ' ) [ \s \r \n ] * > / i;
74
102
const regminifyjs = / < s c r i p t > ( (?: .| [ \r \n ] ) * ) < \/ s c r i p t > / i;
@@ -109,8 +137,16 @@ async function buildAction(buildmode) {
109
137
}
110
138
fs . writeFileSync ( './dist/igc2kmz_spa.html' , htmli2k ) ;
111
139
}
140
+ if ( release ) {
141
+ buildRelease ( ) ;
142
+ }
112
143
}
113
144
114
- let argv = process . argv . slice ( 2 ) ;
115
- if ( argv . length <= 0 ) argv . push ( 'cmd' , 'web' , 'minify' , 'bundle' ) ;
145
+ let allargs = [ 'cmd' , 'web' , 'minify' , 'bundle' ] ;
146
+ let argv = process . argv . slice ( 2 ) . map ( v => v . trim ( ) . toLowerCase ( ) ) ;
147
+ if ( argv . length <= 0 ) {
148
+ argv = allargs ;
149
+ } else if ( argv . indexOf ( 'release' ) > - 1 ) {
150
+ argv = [ ...allargs , 'release' ] ;
151
+ }
116
152
argv . forEach ( await buildAction ) ;
0 commit comments