| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Source file tree builder.
setup a lsp ( livescript + stylus + pug ) watcher:
require! <[@plotdb/srcbuild]>
srcbuild.lsp {base: 'web', i18n: ..., logger: ...}
where
sample logger with pino:
require! <[@plotdb/srcbuild pino]> srcbuild.lsp({logger: pino({level: 'debug'})})
These fields will be passed to all customized builders. Additionally, configurations in builder-specific fields will lso be passed to corresponding customized builders. For example, bundle field will be passed to bundle builder:
srcbuild.lsp {bundle: { ... /* this will be passed to bundle builder */ }, ...}
For lsp, there are 4 different builders:
See following sections for additional options in custom builders.
Extend base builder for a customized builder:
base = require("@plotdb/srcbuild").base
mybuild = (opt = {}) -> @init({srcdir: 'src', desdir: 'des'} <<< opt)
mybuild.prototype = Object.create(base.prototype) <<< {
is-supported: (file) -> return true
get-dependencies: (file) -> return []
build: (files) -> # build will be called if is supported.
}
with following user-defined functions:
and the common options for init are as following:
check src/ext/lsc.ls or src/ext/pug.ls for example.
Except common options, each builder may support different options:
intlbase: base dir to place i18n files. for example, intl part of /intl/zh-TW/index.html. default intl.
i18n: an optional i18n object having the same interface with i18next
i18n(text): translate text based on the i18n object provided.
language(): return current language. ( e.g., zh-TW )
intlbase(p, lng): return a path to given p, based on current i18n ( or specified lng arg ) setup.
additionally, a pug filter i18n is also available, which can be used like:
span:i18n translate this text
noView: default false. when true, js view files ( generated to viewdir ) won't be built.
buildIntl: default true. when true build locale-based files under static/intl/ and .view/intl
viewdir: default .view. a directory for storing prebuilt pug files ( in .js format )
bundler: default null. Auto packing will be possible only if this is provided.
locals: additional local variables for pug context when compiling.
These options are constructor options for corresponding builder, e.g., for pug builder:
new pugbuild({ i18n: ... })
When using shorthands like srcbuild.lsp(...), you can also specify corresponding option in scope, such as:
srcbuild.lsp({
base: '...', i18n: '...',
pug: {intlbase: '...'}
});
common options will be overwritten by scoped options.
Send adapters to watcher from getAdapter() of each custom builders:
require! <[@plotdb/srcbuild/dist/watch @plotdb/srcbuild/dist/ext/pug]>
pugbuilder = new pug(...)
watcher = new watch({adapters: [pugbuilder.getAdapter]})
By default, watcher watches the current working directory. Change watcher behavior with following constructor options:
use watch.demand(target-file) to force rebuild by request. e.g.,
require! <[srcbuild]>
watch = srcbuild.lsp!
# this triggers rebuilding of `web/src/pug/index.pug` file.
watch.demand('web/static/index.html').then -> console.log "built."
target to source file mapping is done by resolve function in custom builder, so to use on demand build, resolve must be implemented.
use srcbuild.i18n to quickly setup an i18next object:
require! <[srcbuild]>
srcbuild.i18n(options)
.then (i18n) -> srcbuild.lsp {i18n}
options is passed to i18next init function. Additional fields in options used by srcbuild.i18n:
When i18n object is provided, i18n data can be used in pug files via i18n function. e.g.,
div= i18n("my-key")
will show my-key content defined in locale corresponding default.yaml:
my-key: 這是我的鍵
To use a namespaced key, add : before key. For example:
div= i18n("new-ns:another-key")
will access to another-key in new-ns.yaml. Be sure to add your namespace name in ns field of i18n option:
"i18n": { ... "ns": ["default", "new-ns"] }
additionally, use intlbase to wrap path with a i18n based relative path:
a(href=intlbase('/faq'))
When building, we extend Pug via plugins and filters to support more features.
Use @ to include files in modules:
include @/ldview/dist/ldview.pug
Use @static to include files under static folder:
include @static/assets/sample.pug
Other paths starting with @ are reserved and will cause error when used.
use script and css builtin mixins to load external script and css files:
+script({name: "module-name", version: "main", path: "somefile.js"})
+css({name: "module-name", version: "main", path: "somefile.js"})
where the fields of the parameters:
By default the above script mixin generates a script tag pointing to files under /assets/lib/<name>/<version>/<path>. You can customize the /assets/lib/ by calling libLoader.root(desiredPath).
Additionally, you can also use a list of modules:
+script([
{name: "module-a", version: "0.0.1", path: "somefile.js"},
{name: "module-b", version: "0.2.1", path: "another.js"},
{name: "module-c", path: "with-default-version.js"},
{name: "module-d", version: "with.default.path" },
{name: "with-defer-async", defer: false, async: true}
{name: "omit-everything"},
])
Use the second option object to specify additional parameters, including:
Following formats and filters are supported:
lsc: transpile content from livescript to JavaScript.
stylus: transpile content from stylus to CSS.
md: transpile content from markdown to HTML.
bundle: bundle files including js, css or block. usage sample:
:bundle(options = {type: "block", files: [ { bid }, ... ]})
Following functions are added:
There are some additional i18n filters available if properly configured. See above for more information.
MIT
| Back | FazBrowse Home | New Git URL |