-
Notifications
You must be signed in to change notification settings - Fork 0
/
luolita.coffee
executable file
·78 lines (61 loc) · 2.31 KB
/
luolita.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env coffee
###
目前coffeescript解释器还不支持ESM模式,本仓库采用CJS+ESM混合开发,战未来!((((
但是捏,cfs又支持ES2015的import modules语法,真是搞不懂捏
Currently, the coffeescript interpreter does not support ESM mode.
This repository adopts CJS+ESM hybrid development to fight for the future!
BUT, coffeescript support ES2015 modules' syntactic sugar : /
###
# This is Node.js CommonJS support.
console.log "[luolita] use CommonJS loader."
console.log "[luolita] start converting..."
args = require("minimist") process.argv.slice 2
cfs = require "coffeescript"
pug = require "pug"
sty = require "stylus"
PATH = "temp/test.luoli"
NAME = "[luolita]"
ENCODING = "utf-8"
COFFEE_OPTIONS =
bare: true,
header: false,
sourceMap: true,
inlineMap: true,
console.log "#{ NAME } use ES Modules loader."
console.log "#{ NAME } CoffeeScript ver: #{ cfs.VERSION }"
{ readFileSync, createReadStream, writeFileSync } = require "fs"
JSON = require 'json5'
readline = require "readline"
DEBUG = true
{ config: CONFIG } = JSON.parse readFileSync "package.json5", "utf-8"
file = readline.createInterface
input: createReadStream PATH, encoding: ENCODING
if DEBUG then console.log "#{ NAME } Reading file: #{ PATH }"
# 0: coffeescript, 1: pug, 2: stylus
file_segments = {}
file_segment_status = ""
output_segments = {}
sfc_var_bridge = ->
output2file = (json) ->
writeFileSync "temp/test.css", json.style
writeFileSync "temp/test.js", json.coffee.js
writeFileSync "temp/test.html", json.template
file.on "line", (line) ->
if DEBUG then console.log "#{ NAME } #{ PATH }> #{ line }"
switch line.trimEnd()
when "coffee:" then file_segment_status = "coffee"
when "template:" then file_segment_status = "template"
when "style:" then file_segment_status = "style"
else
file_segments[file_segment_status] ?= ""
file_segments[file_segment_status] += line + '\n'
file.on "close", ->
if DEBUG then console.log "#{ NAME } Close file: #{ PATH }"
sfc_var_bridge()
output_segments.coffee = cfs.compile file_segments.coffee, COFFEE_OPTIONS
output_segments.template = pug.render file_segments.template
output_segments.style = await sty file_segments.style
.render()
if DEBUG then console.log output_segments
output2file output_segments
console.log(__dirname, args)