@@ -9,12 +9,14 @@ fs = require('fs')
9
9
# async = require('async')
10
10
path = require(' path' )
11
11
12
+ defaultstack = [' default' , ' pug' , ' stylus' ]
13
+
12
14
plugin = (script , name ) ->
13
15
if !! script .config
14
16
if !! script .config .stack
15
17
return name in script .config .stack
16
18
else
17
- if name in [ ' pug ' , ' stylus ' ] # defaults
19
+ if name in defaultstack
18
20
return true
19
21
return false
20
22
@@ -38,6 +40,7 @@ client_libs = [
38
40
]
39
41
40
42
plugin_libs = {
43
+ ' default' : [' dentist' ],
41
44
' pug' : [' pug' ],
42
45
' stylus' : [' stylus' , ' nib' ],
43
46
' electron' : [' electron' ],
@@ -48,20 +51,22 @@ plugin_libs = {
48
51
]
49
52
}
50
53
51
- if process .env .SINGLEFILE # launching wrapper
54
+ if process .env .SINGLEFILE_EXT # launching wrapper
52
55
# include interpreter since we're generating singlefile.js and we need script require()s
53
56
54
57
interpreter = void
55
- if process.env.SINGLEFILE == ' coffee'
58
+ if process.env.SINGLEFILE_EXT == ' coffee'
56
59
require(' coffeescript' ).register()
57
- else if process.env.SINGLEFILE == ' ts'
60
+ else if process.env.SINGLEFILE_EXT == ' ts'
58
61
require(' typescript-require' )
59
- else if process .env .SINGLEFILE != ' js'
60
- interpreter = require(interpreters [process .env .SINGLEFILE ])
62
+ else if process .env .SINGLEFILE_EXT != ' js'
63
+ interpreter = require(interpreters [process .env .SINGLEFILE_EXT ])
61
64
62
65
fn = path .resolve(process .env .SINGLEFILE_SCRIPT )
63
66
scriptdir = path .dirname(fn )
64
67
script = require(fn )
68
+ if ! script .config
69
+ script.config = {}
65
70
cfg = script .config
66
71
if cfg .stack or cfg.stack == ' '
67
72
cfg.stack = cfg .stack .split(' ' )
@@ -144,6 +149,9 @@ if process.env.SINGLEFILE # launching wrapper
144
149
return cb err
145
150
else
146
151
app = {}
152
+ if not script .server
153
+ script.server = ->
154
+ <- app .run()
147
155
if script.server.constructor.name == ' AsyncFunction'
148
156
app.run = promisify(app .run )
149
157
script .server(app )
@@ -435,13 +443,14 @@ if not script.pub
435
443
script.pub = {}
436
444
437
445
if script.config.base == ' svelte'
438
- if not (' index.pug' in script .views )
439
- # default index
440
- script .views [' index.pug' ] = '''
441
- head
442
- script(defer src='bundle.js')
443
- body
444
- '''
446
+ if not (' index.html' in script .pub )
447
+ if not (' index.pug' in script .views )
448
+ # default index
449
+ script .views [' index.pug' ] = '''
450
+ head
451
+ script(defer src='bundle.js')
452
+ body
453
+ '''
445
454
if not (' App.svelte' in script .pub )
446
455
script .pub [' App.svelte' ] = '''
447
456
<script src="client.js"></script>
@@ -462,18 +471,24 @@ if script.config.base == 'svelte'
462
471
463
472
try
464
473
fs .mkdirSync path .join(scriptdir ,' views' )
465
- for template , content of script .views
466
- fs .writeFileSync path .join(scriptdir ,' views' ,template ), dedent(content ), {' flag' : ' w' }
474
+ for fn , content of script .views
475
+ if fn .toLowerCase().endsWith ' .html'
476
+ if Array .isArray content
477
+ content = _ .map(content , (x )-> x .outerHTML || x ).join(' ' )
478
+ fs .writeFileSync path .join(scriptdir ,' views' ,fn ), dedent(content ), {' flag' : ' w' }
467
479
468
480
# generate static/public dir
469
481
try
470
482
fs .mkdirSync path .join(scriptdir ,' public' )
471
- for staticfile , content of script .pub
472
- fs .writeFileSync path .join(scriptdir ,' public' , staticfile ), dedent(content ), {' flag' : ' w' }
483
+ for fn , content of script .pub
484
+ if fn .toLowerCase().endsWith ' .html'
485
+ if Array .isArray content
486
+ content = _ .map(content , (x )-> x .outerHTML || x ).join(' ' )
487
+ fs .writeFileSync path .join(scriptdir ,' public' , fn ), dedent(content ), {' flag' : ' w' }
473
488
474
489
env =
475
490
# NODE_PATH: path.join(scriptdir,'node_modules')
476
- SINGLEFILE : ext
491
+ SINGLEFILE_EXT : ext
477
492
SINGLEFILE_SCRIPT : argv [argv .length-1 ]
478
493
479
494
if script.config.base == ' svelte'
0 commit comments