3
3
const yargs_parser = require ( "yargs-parser" ) ;
4
4
const path = require ( "path" ) ;
5
5
const chalk = require ( "chalk" ) ;
6
+ const prompts = require ( "prompts" ) ;
7
+ const semver = require ( "semver" ) ;
6
8
const ora = require ( "ora" ) ;
7
9
const { extract } = require ( "pacote" ) ;
8
10
const glob = require ( "fast-glob" ) ;
@@ -11,6 +13,7 @@ const os = require("os");
11
13
const packageName = "html5-boilerplate" ;
12
14
const tempDir = os . tmpdir ( ) + `/${ packageName } -staging` ;
13
15
const elapsed = require ( "elapsed-time-logger" ) ;
16
+ let spinner ;
14
17
15
18
module . exports = async ( ) => {
16
19
const argv = yargs_parser ( process . argv . slice ( 2 ) , {
@@ -19,7 +22,7 @@ module.exports = async () => {
19
22
const timer = elapsed . start ( ) ;
20
23
const version = argv [ "release" ] || "latest" ;
21
24
const targetDir = path . resolve ( argv [ "_" ] [ 0 ] || "./" ) ;
22
- const spinner = ora (
25
+ spinner = ora (
23
26
`Downloading ${ packageName } version '${ version } ' to ${ targetDir } `
24
27
) . start ( ) ;
25
28
await fs . ensureDir ( tempDir ) ;
@@ -29,9 +32,13 @@ module.exports = async () => {
29
32
tempDir ,
30
33
{ }
31
34
) ;
32
- spinner . text = `${ nameWithVersion } copied to ${ targetDir } in ${ timer . get ( ) } . Have fun!` ;
35
+ await fs . copy ( tempDir + "/dist" , targetDir ) ;
36
+ await onLoad ( targetDir , version ) ;
37
+ spinner . succeed (
38
+ `${ nameWithVersion } copied to ${ targetDir } in ${ timer . get ( ) } . Have fun!`
39
+ ) ;
40
+ return ;
33
41
} catch ( err ) {
34
- await fs . remove ( tempDir ) ;
35
42
if ( err . code === "ETARGET" ) {
36
43
const msg = chalk . red (
37
44
`version '${ err . wanted } ' not found in npm registry\navailable versions:\n`
@@ -41,16 +48,49 @@ module.exports = async () => {
41
48
}
42
49
spinner . fail ( "Unexpected error" ) ;
43
50
throw new Error ( err ) ;
51
+ } finally {
52
+ await fs . remove ( tempDir ) ;
44
53
}
45
- await fs . copy ( tempDir + "/dist" , targetDir ) ;
46
- await fs . remove ( tempDir ) ;
54
+ } ;
55
+
56
+ const onLoad = async ( targetDir , version ) => {
47
57
// see https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
48
58
const npmIgnoreFiles = await glob (
49
59
`${ targetDir . replace ( / \\ / g, "/" ) } /**/.npmignore`
50
60
) ;
51
61
for ( const npmIgnore of npmIgnoreFiles ) {
52
62
await fs . rename ( npmIgnore , npmIgnore . replace ( / \. n p m i g n o r e $ / , ".gitignore" ) ) ;
53
63
}
54
- spinner . succeed ( ) ;
55
- return ;
64
+
65
+ spinner . stop ( ) ;
66
+
67
+ const questions = [
68
+ {
69
+ type : "confirm" ,
70
+ name : "jquery" ,
71
+ message : "Remove jQuery?" ,
72
+ initial : true ,
73
+ } ,
74
+ // {
75
+ // type: 'confirm',
76
+ // name: 'docs',
77
+ // message: 'Include docs?',
78
+ // }
79
+ ] ;
80
+
81
+ const { jquery } = await prompts ( questions ) ;
82
+
83
+ if ( jquery ) {
84
+ try {
85
+ const indexFile = targetDir + "/index.html" ;
86
+ const sourceHTML = await fs . readFile ( indexFile , "utf-8" ) ;
87
+ const resultHTML = sourceHTML . replace (
88
+ / ( < s c r i p t > w i n d o w \. j Q u e r y .* < \/ s c r i p t > | < s c r i p t s r c = " .* j q u e r y .* < \/ s c r i p t > ) / gi,
89
+ ""
90
+ ) ;
91
+ await fs . writeFile ( indexFile , resultHTML ) ;
92
+ } catch ( err ) {
93
+ throw new Error ( err ) ;
94
+ }
95
+ }
56
96
} ;
0 commit comments