Skip to content

Commit

Permalink
More flexible cli configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
somebee committed May 31, 2024
1 parent 1d4df79 commit be25194
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 8 additions & 6 deletions packages/imba/bin/imba.imba
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ for item,i in argv
cfg = cfg[path[0]] ||= {}
path.shift!

let aliased = overrideAliases[path[0]]
if aliased
Object.assign(cfg,aliased)
let k = path[0]

if k..match(/^[mMsS]+$/)
for chr of k
Object.assign(cfg,overrideAliases[chr])
else
if val.indexOf(' ') >= 0
val = val.split(/\,\s*|\s+/g)

val = valueMap[val] or val

cfg[path[0]] = val
cfg[k] = val
argv[i] = null
argv[i+1] = null

Expand Down Expand Up @@ -434,12 +436,12 @@ def common cmd
.option("-w, --watch", "Continously build and watch project")
.option("--loglevel <level>", "Log level: debug|info|success|warning|error|silent")
.option("-v, --verbose", "verbosity (repeat to increase)",fmt.v,0)
.option("-s, --sourcemap", "verbosity (repeat to increase)",fmt.v,0)
.option("-s, --sourcemap", "Enable sourcemaps")
.option("-S, --no-sourcemap", "Omit sourcemaps")
.option("-m, --minify", "Minify generated files")
.option("-M, --no-minify", "Disable minifying")
.option("-f, --force", "Disregard previously cached outputs")
.option("-k, --keep", "Keep existing files in output directory")
.option("-S, --no-sourcemap", "Omit sourcemaps")
.option("-d, --development","Use defaults for development")
.option("-p, --production","Use defaults for production")
.option("--br", "Compress assets with brotli")
Expand Down
7 changes: 5 additions & 2 deletions packages/imba/src/bundler/bundle.imba
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export default class Bundle < Component
!!program.web or root.html?

get minify?
o.minify ?? program.minify
o.minify ?? program.minify ?? no

get sourcemap?
o.sourcemap ?? program.sourcemap ?? no

get dev?
program.mode == 'development'
Expand Down Expand Up @@ -251,7 +254,7 @@ export default class Bundle < Component
banner: {js: "//__HEAD__" + (o.banner ? '\n' + o.banner : '')}
footer: {js: o.footer or "//__FOOT__"}
splitting: o.splitting
sourcemap: (program.sourcemap === false ? no : (web? ? yes : yes))
sourcemap: sourcemap?
minifySyntax: true
minifyWhitespace: minify? and o.format != 'html'
minifyIdentifiers: minify? and o.format != 'html'
Expand Down
7 changes: 4 additions & 3 deletions packages/imba/src/bundler/config.imba
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export const defaultConfig = {
extends: 'base'
platform: 'node'
format: 'cjs'
sourcemap: true
target: ['node14.13.0']
external: ['dependencies','!imba']
}
Expand All @@ -126,7 +125,6 @@ export const defaultConfig = {
web: {
extends: 'base'
platform: 'browser'
sourcemap: true
format: 'esm'
splitting: true
}
Expand Down Expand Up @@ -196,7 +194,7 @@ export const defaultConfig = {
}

def clone object
return object if object == undefined or object == null
return object if object == undefined or object == null or object == true or object == false
JSON.parse(JSON.stringify(object))

export def merge config, patch, ...up
Expand All @@ -215,6 +213,9 @@ export def merge config, patch, ...up
if otyp == 'string' and vtyp == 'string'
return patch

if vtyp == 'boolean' and (config == null or otyp == 'boolean')
return patch

if otyp == 'array'
if vtyp == 'string'
patch = patch.split(/\,\s*|\s+/g)
Expand Down

0 comments on commit be25194

Please sign in to comment.