Build NodeDK assets, run migrations, and generate sitemaps.
npm i -g @nodedk/cli
Run commands from the application root:
ndk build
ndk migrate
ndk sitemap
ndk help
ndk build recreates dist, runs an optional deploy/build.js function,
then copies app/assets into dist. It concatenates the files listed in
app/config/bundle.js in order and minifies JavaScript and CSS with esbuild.
JavaScript includes a linked source map.
// app/config/bundle.js
module.exports = {
css: ['/css/base.css', '/css/theme.css'],
js: ['/js/browser.js', '/js/base.js']
}
Bundle paths are relative to app/assets. Use browser scripts here; the build
does not resolve require() or import dependencies. The bundle configuration
may also export an async function returning this object.
Copy packaged browser assets into the application before building:
mkdir -p app/assets/js
cp node_modules/@nodedk/browser/dist/browser.js app/assets/js/browser.js
ndk build
Use state.script(['/bundle.js']) and state.style(['/bundle.css']) in a
NodeDK server layout. Development mode loads the individual configured files;
production references the built bundles. Serve dist through your production
web server or use static: 'dist' in the NodeDK server configuration.
ndk migrate loads files from migrations in filename order and awaits each
exported function. It runs them again on every invocation, so migrations
should handle existing data.
// migrations/001-cache-index.js
var { client } = require('@nodedk/mongodb')
module.exports = async function () {
var connection = client(process.env.MONGODB_URL)
try {
await connection.connect()
await connection.db('app').collection('cache').createIndex({ expires: 1 })
} finally {
await connection.close()
}
}
ndk sitemap reads deploy/sitemap.js and writes dist/sitemap.xml.
outpath changes the output directory, relative to the application root.
The file may export an object or an async function returning one.
// deploy/sitemap.js
module.exports = {
hostname: 'https://example.com',
outpath: 'dist',
urls: ['/', '/about', { url: '/contact', priority: 0.5 }]
}
See sitemap for URL options.
Install locally to call commands from application code:
npm i @nodedk/cli
var cli = require('@nodedk/cli')
async function main() {
var options = { cwd: '/path/to/app' }
await cli.build(options)
await cli.migrate(options)
await cli.sitemap(options)
console.log(cli.help())
}
main().catch(console.error)
build(options = {}), migrate(options = {}), and sitemap(options = {})
return Promises with no result value. Their only option is cwd, which
defaults to process.cwd(). help() returns the command help string.
Created by Vidar Eldøy