Files
cell/scripts/build.ce
2025-06-02 08:18:08 -05:00

48 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// cell build Compile all .cm and .ce files to bytecode
var io = use('io')
var js = use('js')
var build_root = '.cell/build'
log.console("Building scripts...")
// Find and compile all .cm and .ce files from root
var files = io.enumerate('', true) // recursive from root
var compiled_count = 0
var error_count = 0
files = files.filter(f => {
return (f.endsWith('.ce' || f.endsWith('.cm')) && !f.startsWith('.cell'))
})
for (var file of files) {
var src = io.slurp(file)
var fullpath = io.realdir(file) + "/" + file
var outpath = build_root + fullpath
io.mkdir(outpath.substring(0, outpath.lastIndexOf('/')))
var mod_name = file
.replace(/\.(cm|ce)$/, '')
.replace(/[\/\-.]/g, '_')
var src_content = io.slurp(file)
var wrapped = '(function ' + mod_name + '(arg){' + src_content + '})'
try {
var compiled = js.compile(file, wrapped)
var blob = js.compile_blob(compiled)
io.slurpwrite(outpath, blob)
compiled_count++
} catch(e) {
log.error(e)
error_count++
}
}
log.console("Build complete: " + compiled_count + " files compiled")
if (error_count > 0) {
log.console(" " + error_count + " errors")
}
$_.stop()