100 lines
2.7 KiB
Plaintext
100 lines
2.7 KiB
Plaintext
// cell build - Compile all modules in modules/ to build/
|
|
|
|
var io = use('io')
|
|
var shop = use('shop')
|
|
var js = use('js')
|
|
|
|
if (!io.exists('.cell/shop.toml')) {
|
|
log.error("No shop.toml found. Run 'cell init' first.")
|
|
$_.stop()
|
|
return
|
|
}
|
|
|
|
var config = shop.load_config()
|
|
if (!config || !config.dependencies) {
|
|
log.console("No dependencies to build")
|
|
$_.stop()
|
|
return
|
|
}
|
|
|
|
log.console("Building modules...")
|
|
|
|
// Process each dependency
|
|
for (var alias in config.dependencies) {
|
|
var version = config.dependencies[alias]
|
|
var parsed = shop.parse_locator(version)
|
|
var module_name = alias
|
|
if (parsed && parsed.version) {
|
|
module_name = alias + '@' + parsed.version
|
|
}
|
|
|
|
var source_dir = '.cell/modules/' + module_name
|
|
|
|
// Check if replaced with local path
|
|
if (config.replace && config.replace[version]) {
|
|
source_dir = config.replace[version]
|
|
log.console("Using local override for " + alias + ": " + source_dir)
|
|
}
|
|
|
|
if (!io.exists(source_dir)) {
|
|
log.console("Skipping " + alias + " - source not found at " + source_dir)
|
|
continue
|
|
}
|
|
|
|
var build_dir = '.cell/build/' + module_name
|
|
if (!io.exists(build_dir)) {
|
|
io.mkdir(build_dir)
|
|
}
|
|
|
|
// Apply patches if any
|
|
if (config.patches && config.patches[alias]) {
|
|
var patch_file = config.patches[alias]
|
|
if (io.exists(patch_file)) {
|
|
log.console("TODO: Apply patch " + patch_file + " to " + alias)
|
|
}
|
|
}
|
|
|
|
// Find and compile all .js files
|
|
var files = io.enumerate(source_dir, true) // recursive
|
|
var compiled_count = 0
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i]
|
|
if (file.endsWith('.js')) {
|
|
// Read source
|
|
var src_path = file
|
|
var src_content = io.slurp(src_path)
|
|
|
|
// Calculate relative path for output
|
|
var rel_path = file.substring(source_dir.length)
|
|
if (rel_path.startsWith('/')) rel_path = rel_path.substring(1)
|
|
|
|
var out_path = build_dir + '/' + rel_path + '.o'
|
|
|
|
// Ensure output directory exists
|
|
var out_dir = out_path.substring(0, out_path.lastIndexOf('/'))
|
|
if (!io.exists(out_dir)) {
|
|
io.mkdir(out_dir)
|
|
}
|
|
|
|
// Compile
|
|
var mod_name = rel_path.replace(/\.js$/, '').replace(/\//g, '_')
|
|
var wrapped = '(function ' + mod_name + '_module(arg){' + src_content + ';})'
|
|
|
|
try {
|
|
var compiled = js.compile(src_path, wrapped)
|
|
var blob = js.compile_blob(compiled)
|
|
io.slurpwrite(out_path, blob)
|
|
compiled_count++
|
|
} catch (e) {
|
|
log.error("Failed to compile " + src_path + ": " + e)
|
|
}
|
|
}
|
|
}
|
|
|
|
log.console("Built " + alias + ": " + compiled_count + " files compiled")
|
|
}
|
|
|
|
log.console("Build complete!")
|
|
|
|
$_.stop() |