UNPKG

backed-cli

Version:

The official command line interface for Backed

1,580 lines 89.6 kB
[ { "__docId__": 0, "kind": "file", "name": "src/backed.js", "content": "'use strict';\nprocess.title = 'backed';\nconst commander = require('commander');\nconst {version} = require('./../package.json');\nconst webup = require('webup');\nconst logger = require('backed-logger');\n\nimport Config from './config.js';\nimport tasks from './tasks.js';\n\ncommander\n .version(version)\n .option('-w, --watch', 'watch for file changes & rebuild on change')\n .option('-u, --uglify', 'minimize code ouput')\n .option('-b, --build', 'build your app/component')\n .option('-s, --serve', 'serve your app/component')\n .option('-c, --copy', 'copy files from your app/component src folder to it distribution folder')\n .option('-d, --debug', 'show all warnings')\n .option('-v, --version', 'current version')\n .parse(process.argv);\n\nconst commands = {\n build: Boolean(commander.build),\n uglify: Boolean(commander.uglify),\n serve: Boolean(commander.serve) || Boolean(commander.watch),\n watch: Boolean(commander.watch),\n copy: Boolean(commander.build) || Boolean(commander.copy)\n};\n\nglobal.debug = commander.debug;\n\n/**\n * @param {object} config {@link Config}\n */\nnew Config().then(config => {\n async function run(config) {\n if (config.uglify) {\n commands.uglify = true;\n }\n for (const task of Object.entries(commands)) {\n const name = task[0];\n const enabled = task[1];\n if (enabled) {\n try {\n if (name === 'serve' && commands.watch) {\n tasks[name](config);\n } else {\n const done = await tasks[name](config);\n }\n } catch (e) {\n logger.warn(`task::function ${name} ${e}`);\n }\n }\n }\n process.exit(0);\n }\n run(config);\n});\n", "static": true, "longname": "src/backed.js", "access": null, "description": null, "lineNumber": 1 }, { "__docId__": 1, "kind": "variable", "name": "commander", "memberof": "src/backed.js", "static": true, "longname": "src/backed.js~commander", "access": null, "export": false, "importPath": "backed-cli/src/backed.js", "importStyle": null, "description": null, "lineNumber": 3, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 2, "kind": "variable", "name": "version", "memberof": "src/backed.js", "static": true, "longname": "src/backed.js~version", "access": null, "export": false, "importPath": "backed-cli/src/backed.js", "importStyle": null, "description": null, "lineNumber": 4, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 3, "kind": "variable", "name": "webup", "memberof": "src/backed.js", "static": true, "longname": "src/backed.js~webup", "access": null, "export": false, "importPath": "backed-cli/src/backed.js", "importStyle": null, "description": null, "lineNumber": 5, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 4, "kind": "variable", "name": "logger", "memberof": "src/backed.js", "static": true, "longname": "src/backed.js~logger", "access": null, "export": false, "importPath": "backed-cli/src/backed.js", "importStyle": null, "description": null, "lineNumber": 6, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 5, "kind": "variable", "name": "commands", "memberof": "src/backed.js", "static": true, "longname": "src/backed.js~commands", "access": null, "export": false, "importPath": "backed-cli/src/backed.js", "importStyle": null, "description": null, "lineNumber": 22, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "{\"build\": *, \"uglify\": *, \"serve\": *, \"watch\": *, \"copy\": *}" ] } }, { "__docId__": 6, "kind": "file", "name": "src/config.js", "content": "'use strict';\nconst {readFileSync} = require('fs');\nconst path = require('path');\nconst {merge} = require('lodash');\nconst logger = require('backed-logger');\n\n/**\n * @param {string} config.name name off your project\n * @param {string} config.server.entry path to where your build is located\n * @param {string} config.server.entry path to where your build is located\n * @param {string} config.server.docs path to where your docs are located\n * @param {string} config.server.bowerPath path to bower_components\n * @param {string} config.server.nodeModulesPath path to node_modules\n * @param {string} config.server.demo path to the demo\n * @param {string} config.server.index path to your index.html file we serve a helper/docs index by default (not support for now)\n * @param {array} config.server.use static files to include [{path: some/path, static: some//path}] when static is undefined path will be used.\n */\nexport default class Config {\n constructor() {\n return new Promise((resolve, reject) => {\n this.importConfig().then(config => {\n this.name = config.name;\n this.cleanup = config.cleanup || true;\n this.babel = config.babel || true;\n if (config.bundles) {\n for (let bundle of config.bundles) {\n bundle.plugins = this.defaultPlugins(bundle.plugins);\n }\n }\n return resolve(this.updateConfig(config));\n });\n });\n }\n\n /**\n * @param {array} plugins\n */\n defaultPlugins(plugins = {}) {\n const defaults = ['babel', 'cleanup'];\n for (let key of defaults) {\n if (this[key] && !plugins[key]) {\n plugins[key] = {};\n }\n }\n return plugins;\n }\n\n /**\n * Default bundles config\n *\n * @return {array} [{src: `src/${name}.js`, dest: `dist/${name}.js`, format: 'es'}\n */\n get bundles() {\n return [\n {\n src: `src/${this.name}.js`,\n dest: `dist/${this.name}.js`,\n format: 'es'\n }\n ];\n }\n\n /**\n * Default server config\n *\n * @return {object} {\n * port: 3000,\n * entry: '/',\n * demo: 'demo',\n * docs: 'docs',\n * bowerPath: 'bower_components',\n * nodeModulesPath: 'node_modules',\n * index: null\n * }\n */\n get server() {\n return {\n port: 9000,\n entry: '/',\n demo: 'demo',\n docs: 'docs',\n bowerPath: 'bower_components',\n nodeModulesPath: 'node_modules',\n index: null};\n }\n\n /**\n * Default watcher config\n *\n * @return {array} [{task: 'build', src: ['./src'], options: {}}\n */\n get watch() {\n return [{\n task: 'build',\n src: ['./src'],\n options: {}\n }];\n }\n\n /**\n * wrapper around cjs require\n * try's to read file from current working directory\n * @param {string} path path to file/module\n * @return {object|array|function|class} module or file\n */\n require(path) {\n return new Promise((resolve, reject) => {\n let root = process.cwd();\n root += `/${path}`;\n try {\n let required = require(root);\n resolve(required);\n } catch (error) {\n reject(error);\n }\n });\n }\n\n /**\n * @return {object} value of 'backed.json'\n */\n importConfig() {\n return new Promise((resolve, reject) => {\n async function generator(fn) {\n const pkg = await fn('package.json').catch(error => {\n if (global.debug) {\n logger.error(error);\n }\n });\n const config = await fn('backed.json').catch(error => {\n if (global.debug) {\n logger.warn('backed.json::not found, ignore this when using backed in package.json');\n }\n });\n if (!config && !pkg) {\n logger.warn('No backed.json or backed section in package.json, using default options.');\n return resolve({name: process.cwd()});\n }\n if (config) {\n let name = config.name;\n if (!name && pkg && pkg.name && !pkg.backed) {\n return resolve(merge(config, {name: pkg.name}));\n } else if (!name && !pkg) {\n return resolve(merge(config, {name: process.cwd()}));\n }\n }\n if (pkg && pkg.backed) {\n return resolve(merge(pkg.backed, {name: pkg.name}));\n }\n }\n generator(this.require);\n });\n }\n\n /**\n * @return {string} name from 'package.json'\n */\n importPackageName() {\n try {\n return JSON.parse(readFileSync(`${process.cwd()}/package.json`)).name;\n } catch (e) {\n if (global.debug) {\n logger.warn('no package.json found');\n }\n }\n return undefined;\n }\n\n /**\n * @return {string} name from 'bower.json'\n */\n importBowerName() {\n try {\n return JSON.parse(readFileSync(`${process.cwd()}/bower.json`)).name;\n } catch (e) {\n if (global.debug) {\n logger.warn('no bower.json found');\n }\n }\n return undefined;\n }\n\n /**\n * @param {object} config - the config to be updated\n * @param {string} name - the name of the element, component, etc\n *\n * @example\n * config.updateConfig({\n * bundles: [{\n * src: 'src',\n * dest: 'dist'\n * }]\n * });\n *\n * @todo create method for building atom app with atom-builder\n * @todo implement element, app & atom-app config\n * @todo handle sourceMap at bundle level\n */\n updateConfig(config, name) {\n config.sourceMap = config.sourceMap || true;\n if (config.entry && config.sources) {\n delete config.bundles;\n } else {\n config.bundles = merge(this.bundles, config.bundles);\n }\n config.server = merge(this.server, config.server);\n config.watch = merge(this.watch, config.watch);\n global.config = config;\n return config;\n }\n}\n", "static": true, "longname": "src/config.js", "access": null, "description": null, "lineNumber": 1 }, { "__docId__": 7, "kind": "variable", "name": "readFileSync", "memberof": "src/config.js", "static": true, "longname": "src/config.js~readFileSync", "access": null, "export": false, "importPath": "backed-cli/src/config.js", "importStyle": null, "description": null, "lineNumber": 2, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 8, "kind": "variable", "name": "path", "memberof": "src/config.js", "static": true, "longname": "src/config.js~path", "access": null, "export": false, "importPath": "backed-cli/src/config.js", "importStyle": null, "description": null, "lineNumber": 3, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 9, "kind": "variable", "name": "merge", "memberof": "src/config.js", "static": true, "longname": "src/config.js~merge", "access": null, "export": false, "importPath": "backed-cli/src/config.js", "importStyle": null, "description": null, "lineNumber": 4, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 10, "kind": "variable", "name": "logger", "memberof": "src/config.js", "static": true, "longname": "src/config.js~logger", "access": null, "export": false, "importPath": "backed-cli/src/config.js", "importStyle": null, "description": null, "lineNumber": 5, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 11, "kind": "class", "name": "Config", "memberof": "src/config.js", "static": true, "longname": "src/config.js~Config", "access": null, "export": true, "importPath": "backed-cli/src/config.js", "importStyle": "Config", "description": "", "lineNumber": 18, "params": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.name", "description": "name off your project" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.entry", "description": "path to where your build is located" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.entry", "description": "path to where your build is located" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.docs", "description": "path to where your docs are located" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.bowerPath", "description": "path to bower_components" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.nodeModulesPath", "description": "path to node_modules" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.demo", "description": "path to the demo" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.server.index", "description": "path to your index.html file we serve a helper/docs index by default (not support for now)" }, { "nullable": null, "types": [ "array" ], "spread": false, "optional": false, "name": "config.server.use", "description": "static files to include [{path: some/path, static: some//path}] when static is undefined path will be used." } ], "interface": false }, { "__docId__": 12, "kind": "constructor", "name": "constructor", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#constructor", "access": null, "description": null, "lineNumber": 19, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [] }, { "__docId__": 13, "kind": "member", "name": "name", "memberof": "src/config.js~Config", "static": false, "longname": "src/config.js~Config#name", "access": null, "description": null, "lineNumber": 22, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 14, "kind": "member", "name": "cleanup", "memberof": "src/config.js~Config", "static": false, "longname": "src/config.js~Config#cleanup", "access": null, "description": null, "lineNumber": 23, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 15, "kind": "member", "name": "babel", "memberof": "src/config.js~Config", "static": false, "longname": "src/config.js~Config#babel", "access": null, "description": null, "lineNumber": 24, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 16, "kind": "method", "name": "defaultPlugins", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#defaultPlugins", "access": null, "description": "", "lineNumber": 38, "params": [ { "nullable": null, "types": [ "array" ], "spread": false, "optional": false, "name": "plugins", "description": "" } ], "return": { "types": [ "*" ] } }, { "__docId__": 17, "kind": "get", "name": "bundles", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#bundles", "access": null, "description": " Default bundles config", "lineNumber": 53, "return": { "nullable": null, "types": [ "array" ], "spread": false, "description": "[{src: `src/${name}.js`, dest: `dist/${name}.js`, format: 'es'}" }, "type": { "types": [ "undefined[]" ] } }, { "__docId__": 18, "kind": "get", "name": "server", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#server", "access": null, "description": " Default server config", "lineNumber": 76, "return": { "nullable": null, "types": [ "object" ], "spread": false, "description": "{\n port: 3000,\n entry: '/',\n demo: 'demo',\n docs: 'docs',\n bowerPath: 'bower_components',\n nodeModulesPath: 'node_modules',\n index: null\n }" }, "type": { "types": [ "{\"port\": number, \"entry\": string, \"demo\": string, \"docs\": string, \"bowerPath\": string, \"nodeModulesPath\": string, \"index\": *}" ] } }, { "__docId__": 19, "kind": "get", "name": "watch", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#watch", "access": null, "description": " Default watcher config", "lineNumber": 92, "return": { "nullable": null, "types": [ "array" ], "spread": false, "description": "[{task: 'build', src: ['./src'], options: {}}" }, "type": { "types": [ "undefined[]" ] } }, { "__docId__": 20, "kind": "method", "name": "require", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#require", "access": null, "description": "wrapper around cjs require\ntry's to read file from current working directory", "lineNumber": 106, "params": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "path", "description": "path to file/module" } ], "return": { "nullable": null, "types": [ "object", "array", "function", "class" ], "spread": false, "description": "module or file" } }, { "__docId__": 21, "kind": "method", "name": "importConfig", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#importConfig", "access": null, "description": "", "lineNumber": 122, "params": [], "return": { "nullable": null, "types": [ "object" ], "spread": false, "description": "value of 'backed.json'" } }, { "__docId__": 22, "kind": "method", "name": "importPackageName", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#importPackageName", "access": null, "description": "", "lineNumber": 158, "params": [], "return": { "nullable": null, "types": [ "string" ], "spread": false, "description": "name from 'package.json'" } }, { "__docId__": 23, "kind": "method", "name": "importBowerName", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#importBowerName", "access": null, "description": "", "lineNumber": 172, "params": [], "return": { "nullable": null, "types": [ "string" ], "spread": false, "description": "name from 'bower.json'" } }, { "__docId__": 24, "kind": "method", "name": "updateConfig", "memberof": "src/config.js~Config", "generator": false, "async": false, "static": false, "longname": "src/config.js~Config#updateConfig", "access": null, "description": "", "examples": [ "config.updateConfig({\n bundles: [{\n src: 'src',\n dest: 'dist'\n }]\n});" ], "lineNumber": 199, "todo": [ "create method for building atom app with atom-builder", "implement element, app & atom-app config", "handle sourceMap at bundle level" ], "params": [ { "nullable": null, "types": [ "object" ], "spread": false, "optional": false, "name": "config", "description": "the config to be updated" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "name", "description": "the name of the element, component, etc" } ], "return": { "types": [ "*" ] } }, { "__docId__": 25, "kind": "file", "name": "src/server.js", "content": "'use strict';\nconst express = require('express');\nconst http = require('http');\nconst glob = require('glob');\nconst opn = require('opn');\n\nconst app = express();\nconst server = http.createServer(app);\n// TODO: find better way to reload\n// const reload = require('reload');\n// const reloadServer = reload(server, app);\nconst logger = require('backed-logger');\n\n/**\n * glob file path\n * @param {string} string\n */\nconst src = string => {\n return new Promise((resolve, reject) => {\n glob(string, (error, files) => {\n if (error) {\n reject(error);\n }\n if (files.length > 0) {\n resolve(files);\n }\n });\n });\n};\n\nclass Server {\n\n/**\n * @param {object} config - configuration\n * @param {string} config.entry path to where your build is located\n * @param {string} config.docs path to where your docs are located\n * @param {string} config.bowerPath path to bower_components\n * @param {string} config.nodeModulesPath path to node_modules\n * @param {string} config.demo path to the demo\n * @param {string} config.index path to your index.html file we serve a helper/docs index by default (not support for now)\n * @param {array} config.use static files to include [{path: some/path, static: some//path}] when static is undefined path will be used.\n */\n serve(config = {\n entry: '/',\n demo: 'demo',\n docs: 'docs',\n port: 9000,\n use: [{path: null, static: null}],\n bowerPath: 'bower_components',\n nodeModulesPath: 'node_modules',\n index: null}) {\n return new Promise((resolve, reject) => {\n if (config) {\n this.handleOldOptions(config);\n if (config.use) {\n for (let use of config.use) {\n app.use(use.path, express.static(this.appLocation(use.static || use.path)));\n }\n }\n\n app.use('/', express.static(\n this.appLocation(config.entry)));\n\n app.use('/bower_components', express.static(\n this.appLocation(config.bowerPath, 'bower_components')));\n\n app.use('/node_modules', express.static(\n this.appLocation(config.nodeModulesPath, 'node_modules')));\n\n app.use('/demo/node_modules', express.static(\n this.appLocation(config.nodeModulesPath, 'node_modules')));\n\n app.use('/demo', express.static(\n this.appLocation(config.demo, 'demo')));\n\n app.use('/docs', express.static(\n this.appLocation(config.docs, 'docs')));\n\n app.use('/package.json', express.static(\n this.appLocation('package.json')\n ));\n\n // serve backed-cli documentation\n app.use('/backed-cli/docs', express.static(\n __dirname.replace('bin', 'docs')));\n\n // serve backed documentation\n app.use('/backed/docs', express.static(\n this.appLocation('node_modules/backed/docs')));\n\n // TODO: Add option to override index\n app.use('/', express.static(__dirname.replace('bin', 'node_modules\\\\backed-client\\\\dist')));\n\n // TODO: implement copyrighted by package author & package name if no file is found\n src(process.cwd() + '/license.*').then(files => {\n app.use('/license', express.static(files[0]));\n });\n\n this._listen(config);\n } else {\n reject(logger.warn(`${global.config.name}::server config not found [example](https://raw.githubusercontent.com/VandeurenGlenn/backed-cli/master/config/backed.json)`));\n }\n });\n }\n\n _listen({port, entry}) {\n try {\n server.listen(port, error => {\n logger.log(`${global.config.name}::serving from http://localhost:${port}/${entry.replace('/', '')}`);\n opn(`http://localhost:${port}/${entry.replace('/', '')}`);\n });\n } catch (e) {\n console.log(error);\n logger.warn(error);\n logger.log('trying another port');\n return this._listen(port++);\n }\n }\n\n /**\n * @param {string} path - location of the file\n * @param {string} alternate - returns when path is undefined\n * @param {string} disableAlternate - current working directory is ignored when true, defaults to false\n */\n appLocation(path, alternate, disableAlternate = false) {\n let root = process.cwd();\n if (!path && !disableAlternate) {\n path = alternate;\n } else if (!path && disableAlternate) {\n // when we disable alternate we return the value of alternate\n return alternate;\n }\n root += `\\\\${path}`;\n return root;\n }\n\n handleOldOptions(options) {\n if (options.path || options.elementLocation) {\n logger.warn(`${options.path ? 'server.path' : 'server.elementLocation'} is no longer supported, [visit](https://github.com/vandeurenglenn/backed-cli#serve) to learn more'`);\n } else if (options.bowerPath) {\n logger.warn('server.bowerPath::deprecated: removal planned @1.0.0+');\n }\n }\n\n // reload() {\n // reloadServer.reload();\n // }\n}\nexport default new Server();\n", "static": true, "longname": "src/server.js", "access": null, "description": null, "lineNumber": 1 }, { "__docId__": 26, "kind": "variable", "name": "express", "memberof": "src/server.js", "static": true, "longname": "src/server.js~express", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 2, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 27, "kind": "variable", "name": "http", "memberof": "src/server.js", "static": true, "longname": "src/server.js~http", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 3, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 28, "kind": "variable", "name": "glob", "memberof": "src/server.js", "static": true, "longname": "src/server.js~glob", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 4, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 29, "kind": "variable", "name": "opn", "memberof": "src/server.js", "static": true, "longname": "src/server.js~opn", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 5, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 30, "kind": "variable", "name": "app", "memberof": "src/server.js", "static": true, "longname": "src/server.js~app", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 7, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 31, "kind": "variable", "name": "server", "memberof": "src/server.js", "static": true, "longname": "src/server.js~server", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 8, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 32, "kind": "variable", "name": "logger", "memberof": "src/server.js", "static": true, "longname": "src/server.js~logger", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 12, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 33, "kind": "function", "name": "src", "memberof": "src/server.js", "generator": false, "async": false, "static": true, "longname": "src/server.js~src", "access": null, "export": false, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": "glob file path", "lineNumber": 18, "params": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "string", "description": "" } ], "return": { "types": [ "*" ] } }, { "__docId__": 34, "kind": "class", "name": "Server", "memberof": "src/server.js", "static": true, "longname": "src/server.js~Server", "access": null, "export": true, "importPath": "backed-cli/src/server.js", "importStyle": null, "description": null, "lineNumber": 31, "pseudoExport": true, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "interface": false }, { "__docId__": 35, "kind": "method", "name": "serve", "memberof": "src/server.js~Server", "generator": false, "async": false, "static": false, "longname": "src/server.js~Server#serve", "access": null, "description": "", "lineNumber": 43, "params": [ { "nullable": null, "types": [ "object" ], "spread": false, "optional": false, "name": "config", "description": "configuration" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.entry", "description": "path to where your build is located" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.docs", "description": "path to where your docs are located" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.bowerPath", "description": "path to bower_components" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.nodeModulesPath", "description": "path to node_modules" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.demo", "description": "path to the demo" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "config.index", "description": "path to your index.html file we serve a helper/docs index by default (not support for now)" }, { "nullable": null, "types": [ "array" ], "spread": false, "optional": false, "name": "config.use", "description": "static files to include [{path: some/path, static: some//path}] when static is undefined path will be used." } ], "return": { "types": [ "*" ] } }, { "__docId__": 36, "kind": "method", "name": "_listen", "memberof": "src/server.js~Server", "generator": false, "async": false, "static": false, "longname": "src/server.js~Server#_listen", "access": null, "description": null, "lineNumber": 106, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "objectPattern", "types": [ "{\"port\": *, \"entry\": *}" ], "defaultRaw": { "port": null, "entry": null }, "defaultValue": "{\"port\":null,\"entry\":null}" } ], "return": { "types": [ "*" ] } }, { "__docId__": 37, "kind": "method", "name": "appLocation", "memberof": "src/server.js~Server", "generator": false, "async": false, "static": false, "longname": "src/server.js~Server#appLocation", "access": null, "description": "", "lineNumber": 125, "params": [ { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "path", "description": "location of the file" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "alternate", "description": "returns when path is undefined" }, { "nullable": null, "types": [ "string" ], "spread": false, "optional": false, "name": "disableAlternate", "description": "current working directory is ignored when true, defaults to false" } ], "return": { "types": [ "*" ] } }, { "__docId__": 38, "kind": "method", "name": "handleOldOptions", "memberof": "src/server.js~Server", "generator": false, "async": false, "static": false, "longname": "src/server.js~Server#handleOldOptions", "access": null, "description": null, "lineNumber": 137, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "options", "types": [ "*" ] } ] }, { "__docId__": 39, "kind": "variable", "name": "server", "memberof": "src/server.js", "static": true, "longname": "src/server.js~server", "access": null, "export": true, "importPath": "backed-cli/src/server.js", "importStyle": "server", "description": null, "lineNumber": 149, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "src/server.js~Server" ] } }, { "__docId__": 40, "kind": "file", "name": "src/tasks.js", "content": "'use strict';\r\nconst fs = require('backed-fs');\r\nconst {readFile} = require('fs');\r\nconst webup = require('webup');\r\nconst uglifyEs = require('uglify-es');\r\nimport builder from './../node_modules/backed-builder/src/builder.js';\r\nimport server from './server.js';\r\nimport watcher from './watcher.js';\r\n\r\nconst build = config => {\r\n return new Promise((resolve, reject) => {\r\n if (config.entry && config.sources) {\r\n return webup(config).then(() => {\r\n return resolve();\r\n });\r\n }\r\n builder.build(config).then(() => resolve());\r\n });\r\n};\r\n\r\nconst read = src => {\r\n return new Promise((resolve, reject) => {\r\n readFile(src, 'utf-8', (error, code) => {\r\n if (error) {\r\n reject(error);\r\n }\r\n resolve(code);\r\n });\r\n });\r\n};\r\n\r\nconst uglify = config => {\r\n return new Promise((resolve, reject) => {\r\n async function generator() {\r\n for (const bundle of config.bundles) {\r\n const file = await read(bundle.dest);\r\n const result = uglifyEs.minify(file, {compress: true});\r\n const done = await fs.write({contents: result.code}, bundle.dest.replace('.js', '.min.js'));\r\n }\r\n resolve();\r\n }\r\n generator();\r\n });\r\n};\r\n\r\nconst copy = config => {\r\n return new Promise((resolve, reject) => {\r\n return fs.copySources(config.copy).then(() => {\r\n return resolve();\r\n });\r\n });\r\n};\r\n\r\nconst serve = config => {\r\n return server.serve(config.server);\r\n};\r\n\r\nconst watch = config => {\r\n watcher.on('reload', () => {\r\n server.reload();\r\n });\r\n return watcher.watch(config);\r\n};\r\n\r\nexport default {\r\n build,\r\n uglify,\r\n copy,\r\n serve,\r\n watch\r\n};\r\n", "static": true, "longname": "src/tasks.js", "access": null, "description": null, "lineNumber": 1 }, { "__docId__": 41, "kind": "variable", "name": "fs", "memberof": "src/tasks.js", "static": true, "longname": "src/tasks.js~fs", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 2, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 42, "kind": "variable", "name": "readFile", "memberof": "src/tasks.js", "static": true, "longname": "src/tasks.js~readFile", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 3, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 43, "kind": "variable", "name": "webup", "memberof": "src/tasks.js", "static": true, "longname": "src/tasks.js~webup", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 4, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 44, "kind": "variable", "name": "uglifyEs", "memberof": "src/tasks.js", "static": true, "longname": "src/tasks.js~uglifyEs", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 5, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 45, "kind": "function", "name": "build", "memberof": "src/tasks.js", "generator": false, "async": false, "static": true, "longname": "src/tasks.js~build", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 10, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "config", "types": [ "*" ] } ], "return": { "types": [ "*" ] } }, { "__docId__": 46, "kind": "function", "name": "read", "memberof": "src/tasks.js", "generator": false, "async": false, "static": true, "longname": "src/tasks.js~read", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 21, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "src", "types": [ "*" ] } ], "return": { "types": [ "*" ] } }, { "__docId__": 47, "kind": "function", "name": "uglify", "memberof": "src/tasks.js", "generator": false, "async": false, "static": true, "longname": "src/tasks.js~uglify", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 32, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "config", "types": [ "*" ] } ], "return": { "types": [ "*" ] } }, { "__docId__": 48, "kind": "function", "name": "copy", "memberof": "src/tasks.js", "generator": false, "async": false, "static": true, "longname": "src/tasks.js~copy", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 46, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "config", "types": [ "*" ] } ], "return": { "types": [ "*" ] } }, { "__docId__": 49, "kind": "function", "name": "serve", "memberof": "src/tasks.js", "generator": false, "async": false, "static": true, "longname": "src/tasks.js~serve", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 54, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "config", "types": [ "*" ] } ], "return": { "types": [ "*" ] } }, { "__docId__": 50, "kind": "function", "name": "watch", "memberof": "src/tasks.js", "generator": false, "async": false, "static": true, "longname": "src/tasks.js~watch", "access": null, "export": false, "importPath": "backed-cli/src/tasks.js", "importStyle": null, "description": null, "lineNumber": 58, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "params": [ { "name": "config", "types": [ "*" ] } ], "return": { "types": [ "*" ] } }, { "__docId__": 51, "kind": "file", "name": "src/watcher.js", "content": "'use strict';\nconst {fork} = require('child_process');\nconst chokidar = require('chokidar');\nconst path = require('path');\nconst EventEmitter = require('events');\nconst {readFileSync, writeFileSync} = require('fs');\n// const {merge} = require('lodash');\nconst logger = require('backed-logger');\nconst time = () => {\n return new Date().toLocaleTimeString();\n};\nlet worker;\n\n/**\n * @extends EventEmitter\n */\nclass Watcher extends EventEmitter {\n\n /**\n * @param {object} config {@link Config}\n */\n watch(config) {\n return new Promise((resolve, reject) => {\n if (!config.watch) {\n logger.warn('nothing to watch');\n reject('nothing to watch');\n return process.kill(process.pid, 'SIGINT');\n }\n this.server = config.server;\n this.configureDemo(this.server);\n\n logger.log(`[${time()}] ${logger._chalk('Starting initial build', 'cyan')}`);\n this.runWorker(config);\n\n logger.log(`[${time()}] ${logger._chalk('Watching files for changes', 'cyan')}`);\n\n let watchers = {};\n for (let watch of config.watch) {\n watchers[watch.task] = chokidar.watch(watch.src, watch.options);\n watchers[watch.task].on('change', () => {\n this.runWorker(watch.task, config);\n });\n }\n // resolve();\n });\n }\n\n configureDemo(server) {\n logger.log(`[${time()}] ${logger._chalk('Configuring demo', 'cyan')}`);\n\n if (server) {\n let demoPath = path.join(process.cwd(), server.demo);\n\n if (!demoPath.includes('index.html')) {\n demoPath = path.join(demoPath, 'index.html');\n }\n let demo = readFileSync(demoPath, 'utf-8');\n if (!demo.includes('/reload/reload.js')) {\n demo = demo.replace('</body>', '\\t<script src=\"/reload/reload.js\"></script>\\n</body>');\n writeFileSync(demoPath, demo);\n }\n }\n }\n\n runWorker(task, config) {\n if (this.busy) {\n worker.kill();\n this.busy = false;\n }\n this.busy = true;\n worker = fork(path.join(__dirname, 'workers/watcher-worker.js'));\n worker.on('message', message => {\n if (message === 'done') {\n this.configureDemo(this.server);\n message = 'reload';\n }\n logger.log(`[${time()}] ${logger._chalk('Reloading browser', 'cyan')}`);\n this.emit(message);\n worker.kill();\n this.busy = false;\n });\n worker.send({task: task, config: config});\n }\n\n // on(event, fn) {\n // this.on(event, fn);\n // }\n\n // this.watcher = chokidar.watch(config.watchers, config.options);\n // this.watcher.on('change', path => logger.log(`File ${path} has been changed`));\n}\nexport default new Watcher();\n", "static": true, "longname": "src/watcher.js", "access": null, "description": null, "lineNumber": 1 }, { "__docId__": 52, "kind": "variable", "name": "fork", "memberof": "src/watcher.js", "static": true, "longname": "src/watcher.js~fork", "access": null, "export": false, "importPath": "backed-cli/src/watcher.js", "importStyle": null, "description": null, "lineNumber": 2, "undocument": true, "unknown": [ { "tagName": "@_undocument", "tagValue": "" } ], "type": { "types": [ "*" ] } }, { "__docId__": 53, "kind": "variable", "name": "chokidar", "memberof": "src/watcher.js", "static": true, "longname": "src/watcher.js~chokidar", "access": null, "export":