diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ff30c44 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.tabSize": 2 +} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index c6bea4e..0000000 --- a/index.js +++ /dev/null @@ -1,249 +0,0 @@ -// nabs - Not another build system. Easy management of package.json scripts. -// -// Copyright (C) 2019 James Kruth -// -// This file is part of nabs. -// -// nabs is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// nabs is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this nabs. If not, see . - -const fs = require('fs'); -const jsonfile = require('jsonfile'); -const { resolve } = require('path'); -const program = require('commander'); -const winston = require('winston'); -const yaml = require('js-yaml'); - -const { version } = JSON.parse(fs.readFileSync(resolve('package.json'), 'utf8')); - -const log = winston.createLogger({ - format: winston.format.combine(winston.format.splat(), winston.format.cli()), - transports: [ - new (winston.transports.Console)({ - handleExceptions: true, - humanReadableUnhandledException: true, - }), - ], -}); - -const logLevels = [ - 'error', - 'warn', - 'info', - 'debug', -]; - -const nabs = {}; - -// utility function - string -> [string], [] -> copy of [], null -> [] -nabs.makeArray = function makeArray(item) { - if (typeof item === 'string') { - return [item]; - } - - if (Array.isArray(item)) { - return item.slice(); - } - - if (item === null) { - return []; - } - - throw new Error(`Item must be string, array or null: ${item}`); -}; - -nabs.Task = class Task { - constructor(name) { - // name is an array of the full parts of the name - // e.g. ['super', 'task', 'sub'] - this.name = name; - - // an array of action strings (shell commands) - this.actions = []; - // an array of task names: ['task:sub1', 'task:sub2', 'task:sub3'] - this.dependencies = []; - - // children are needed to calculate the default dependencies - // an array of task names: ['task:sub1', 'task:sub2', 'task:sub3'] - this.children = []; - // default to using the children as dependencies - this.useChildrenAsDependencies = true; - } - - // expects a single action (string), or a list of actions (array) - addAction(action) { - this.actions = this.actions.concat(nabs.makeArray(action)); - } - - // expects a child task name (string) and fully qualifies it - addChild(child) { - this.children.push(`${this.scriptName}:${child}`); - } - - // expects a single dependency (string), or a list of dependencies (array) - // the empty array and null are also allowed - addDependency(task) { - const name = this.scriptName; - const deps = nabs.makeArray(task); - - // dependencies have been overridden - this.useChildrenAsDependencies = false; - - // change shorthand deps (:subtask) to full (task:subtask) - deps.forEach((item, index) => { - if (item.startsWith(':')) { - deps[index] = name + item; - } - }); - - this.dependencies = this.dependencies.concat(deps); - } - - get scriptName() { - return this.name.join(':'); - } - - get scriptValue() { - let rawActions = []; - - function npmify(arr) { - return arr.map((key) => `npm run ${key}`); - } - - // generate dependencies - if (this.useChildrenAsDependencies) { - rawActions = npmify(this.children.sort()); - } else { - rawActions = npmify(this.dependencies); - } - - // concat actions - rawActions = rawActions.concat(this.actions); - - if (rawActions.length === 0) { - throw new Error(`Tasks with no actions or dependencies are invalid: ${this}`); - } - - return rawActions.join(' && '); - } - - toString() { - return this.scriptName; - } -}; - -// given a tasks object (from the YAML file), returns a list of Task objects -nabs.buildTasks = function buildTasks(tasks, name) { - const task = new nabs.Task(name); - let scripts = [task]; - - if (typeof tasks === 'string' || Array.isArray(tasks)) { - // simple task - task.addAction(tasks); - } else { - // object task - if (typeof tasks.$depend !== 'undefined') { - task.addDependency(tasks.$depend); - } - - if (typeof tasks.$action !== 'undefined') { - task.addAction(tasks.$action); - } - - Object.keys(tasks) - .filter((item) => !item.startsWith('$')) - .forEach((key) => { - scripts = scripts.concat(nabs.buildTasks(tasks[key], name.concat(key))); - task.addChild(key); - }); - } - - return scripts; -}; - -// look for missing dependencies -nabs.checkDependencies = function checkDependencies(tasks, names) { - const taskNames = new Set(names); - - tasks.forEach((task) => { - task.dependencies.forEach((dependency) => { - if (!taskNames.has(dependency)) { - throw new Error(`Task ${task} has non-existent dependency: ${dependency}`); - } - }); - }); -}; - -// processes tasks, returns scripts -nabs.process = function process(tasks) { - const scripts = {}; - let taskList = []; - - log.info('Processing tasks...'); - Object.keys(tasks).forEach((task) => { - taskList = taskList.concat(nabs.buildTasks(tasks[task], [task])); - }); - - log.info('Building scripts...'); - taskList.sort().forEach((item) => { - scripts[item.scriptName] = item.scriptValue; - }); - - log.info('Checking dependencies...'); - nabs.checkDependencies(taskList, Object.keys(scripts)); - - return scripts; -}; - -nabs.main = function main(options) { - const nabsFile = options.nabs || resolve('nabs.yml'); - log.info('Opening %s...', nabsFile); - const tasks = yaml.safeLoad(fs.readFileSync(nabsFile, 'utf8')); - - const pkgFile = options.package || 'package.json'; - log.info('Opening %s...', pkgFile); - const pkg = jsonfile.readFileSync(pkgFile, 'utf8'); - - pkg.scripts = nabs.process(tasks); - - if (!options.disable && !pkg.scripts.nabs) { - pkg.scripts.nabs = 'nabs'; - } - - log.info('Writing %s...', pkgFile); - jsonfile.writeFileSync('package.json', pkg, { - encoding: 'utf8', - spaces: 2, - }); -}; - -program - .version(version) - .option('-d, --disable', 'disable the default nabs regenerate task') - .option('-n, --nabs ', 'nabs.yml file (defaults to nabs.yml in current dir)') - .option('-p, --package ', 'package.json file (defaults to package.json in current dir)') - .option('-v, --verbose', 'pass up to 3 times to increase verbosity', (v, total) => total + 1, 0) - .parse(process.argv); - -log.level = logLevels[program.verbose || 0]; -log.info('Starting nabs v%s', version); - -try { - nabs.main(program); -} catch (e) { - log.error(e.message); - log.debug(e); - process.exit(1); -} - -export default nabs; diff --git a/package-lock.json b/package-lock.json index b4aab9f..fedb92a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1691,6 +1691,11 @@ "integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", "dev": true }, + "esm": { + "version": "3.2.25", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==" + }, "espree": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/espree/-/espree-6.1.2.tgz", diff --git a/package.json b/package.json index 93f7637..59185da 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "nabs", "version": "0.4.0", "description": "Not Another Build System - compiles YAML to scripts in package.json", - "main": "index.js", + "main": "dist/index.js", "scripts": { "build": "npm run build:prod", "build:dev": "webpack --config webpack/webpack.development.js --watch", @@ -44,8 +44,8 @@ "eslint-plugin-import": "^2.18.2", "mocha": "^6.2.0", "testdouble": "^3.12.2", - "webpack-cli": "^3.3.9", "webpack": "^4.41.2", + "webpack-cli": "^3.3.9", "webpack-merge": "^4.2.2", "webpack-node-externals": "^1.7.2" }, diff --git a/src/Task.js b/src/Task.js new file mode 100644 index 0000000..1daa795 --- /dev/null +++ b/src/Task.js @@ -0,0 +1,102 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +const makeArray = require('./utils/makeArray'); + +class Task { + constructor(name) { + // name is an array of the full parts of the name + // e.g. ['super', 'task', 'sub'] + this.name = name; + + // an array of action strings (shell commands) + this.actions = []; + // an array of task names: ['task:sub1', 'task:sub2', 'task:sub3'] + this.dependencies = []; + + // children are needed to calculate the default dependencies + // an array of task names: ['task:sub1', 'task:sub2', 'task:sub3'] + this.children = []; + // default to using the children as dependencies + this.useChildrenAsDependencies = true; + } + + // expects a single action (string), or a list of actions (array) + addAction(action) { + this.actions = this.actions.concat(makeArray(action)); + } + + // expects a child task name (string) and fully qualifies it + addChild(child) { + this.children.push(`${this.scriptName}:${child}`); + } + + // expects a single dependency (string), or a list of dependencies (array) + // the empty array and null are also allowed + addDependency(task) { + const name = this.scriptName; + const deps = makeArray(task); + + // dependencies have been overridden + this.useChildrenAsDependencies = false; + + // change shorthand deps (:subtask) to full (task:subtask) + deps.forEach((item, index) => { + if (item.startsWith(':')) { + deps[index] = name + item; + } + }); + + this.dependencies = this.dependencies.concat(deps); + } + + get scriptName() { + return this.name.join(':'); + } + + get scriptValue() { + let rawActions = []; + + function npmify(arr) { + return arr.map((key) => `npm run ${key}`); + } + + // generate dependencies + if (this.useChildrenAsDependencies) { + rawActions = npmify(this.children.sort()); + } else { + rawActions = npmify(this.dependencies); + } + + // concat actions + rawActions = rawActions.concat(this.actions); + + if (rawActions.length === 0) { + throw new Error(`Tasks with no actions or dependencies are invalid: ${this}`); + } + + return rawActions.join(' && '); + } + + toString() { + return this.scriptName; + } +} + +module.exports = Task; diff --git a/src/index.js b/src/index.js new file mode 100755 index 0000000..d0ed7ee --- /dev/null +++ b/src/index.js @@ -0,0 +1,69 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + + +const fs = require('fs'); +const { resolve } = require('path'); +const program = require('commander'); +const log = require('./logger'); +const Task = require('./Task'); +const buildTasks = require('./utils/buildTasks'); +const checkDependencies = require('./utils/checkDependencies'); +const makeArray = require('./utils/makeArray'); +const processTasks = require('./utils/process'); +const main = require('./main'); + +const { version } = JSON.parse(fs.readFileSync(resolve('package.json'), 'utf8')); + +const nabs = {}; + +const logLevels = [ + 'error', + 'warn', + 'info', + 'debug', +]; + +nabs.Task = Task; +nabs.makeArray = makeArray; +nabs.buildTasks = buildTasks; +nabs.checkDependencies = checkDependencies; +nabs.process = processTasks; +nabs.main = main; + +program + .version(version) + .option('-d, --disable', 'disable the default nabs regenerate task') + .option('-n, --nabs ', 'nabs.yml file (defaults to nabs.yml in current dir)') + .option('-p, --package ', 'package.json file (defaults to package.json in current dir)') + .option('-v, --verbose', 'pass up to 3 times to increase verbosity', (v, total) => total + 1, 0) + .parse(process.argv); + +log.level = logLevels[program.verbose || 0]; +log.info('Starting nabs v%s', version); + +try { + nabs.main(program); +} catch (e) { + log.error(e.message); + log.debug(e); + process.exit(1); +} + +module.exports = nabs; diff --git a/src/logger.js b/src/logger.js new file mode 100644 index 0000000..3fbda56 --- /dev/null +++ b/src/logger.js @@ -0,0 +1,33 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +const winston = require('winston'); + +const log = winston.createLogger({ + format: winston.format.combine(winston.format.splat(), winston.format.cli()), + transports: [ + new (winston.transports.Console)({ + handleExceptions: true, + humanReadableUnhandledException: true, + }), + ], +}); + + +module.exports = log; diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..b649b24 --- /dev/null +++ b/src/main.js @@ -0,0 +1,49 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +const fs = require('fs'); +const { resolve } = require('path'); +const jsonfile = require('jsonfile'); +const yaml = require('js-yaml'); +const log = require('./logger'); +const processTasks = require('./utils/process'); + +function main(options) { + const nabsFile = options.nabs || resolve('nabs.yml'); + log.info('Opening %s...', nabsFile); + const tasks = yaml.safeLoad(fs.readFileSync(nabsFile, 'utf8')); + + const pkgFile = options.package || 'package.json'; + log.info('Opening %s...', pkgFile); + const pkg = jsonfile.readFileSync(pkgFile, 'utf8'); + + pkg.scripts = processTasks(tasks); + + if (!options.disable && !pkg.scripts.nabs) { + pkg.scripts.nabs = 'nabs'; + } + + log.info('Writing %s...', pkgFile); + jsonfile.writeFileSync('package.json', pkg, { + encoding: 'utf8', + spaces: 2, + }); +} + +module.exports = main; diff --git a/src/utils/buildTasks.js b/src/utils/buildTasks.js new file mode 100644 index 0000000..493f002 --- /dev/null +++ b/src/utils/buildTasks.js @@ -0,0 +1,51 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +const Task = require('../Task'); + +// given a tasks object (from the YAML file), returns a list of Task objects +function buildTasks(tasks, name) { + const task = new Task(name); + let scripts = [task]; + + if (typeof tasks === 'string' || Array.isArray(tasks)) { + // simple task + task.addAction(tasks); + } else { + // object task + if (typeof tasks.$depend !== 'undefined') { + task.addDependency(tasks.$depend); + } + + if (typeof tasks.$action !== 'undefined') { + task.addAction(tasks.$action); + } + + Object.keys(tasks) + .filter((item) => !item.startsWith('$')) + .forEach((key) => { + scripts = scripts.concat(buildTasks(tasks[key], name.concat(key))); + task.addChild(key); + }); + } + + return scripts; +} + +module.exports = buildTasks; diff --git a/src/utils/checkDependencies.js b/src/utils/checkDependencies.js new file mode 100644 index 0000000..720f8c6 --- /dev/null +++ b/src/utils/checkDependencies.js @@ -0,0 +1,33 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +// look for missing dependencies +function checkDependencies(tasks, names) { + const taskNames = new Set(names); + + tasks.forEach((task) => { + task.dependencies.forEach((dependency) => { + if (!taskNames.has(dependency)) { + throw new Error(`Task ${task} has non-existent dependency: ${dependency}`); + } + }); + }); +} + +module.exports = checkDependencies; diff --git a/src/utils/makeArray.js b/src/utils/makeArray.js new file mode 100644 index 0000000..26348e7 --- /dev/null +++ b/src/utils/makeArray.js @@ -0,0 +1,37 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +// utility function - string -> [string], [] -> copy of [], null -> [] +function makeArray(item) { + if (typeof item === 'string') { + return [item]; + } + + if (Array.isArray(item)) { + return item.slice(); + } + + if (item === null) { + return []; + } + + throw new Error(`Item must be string, array or null: ${item}`); +} + +module.exports = makeArray; diff --git a/src/utils/process.js b/src/utils/process.js new file mode 100644 index 0000000..56905fb --- /dev/null +++ b/src/utils/process.js @@ -0,0 +1,45 @@ +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2019 James Kruth +// +// This file is part of nabs. +// +// nabs is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// nabs is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this nabs. If not, see . + +const buildTasks = require('./buildTasks'); +const checkDependencies = require('./checkDependencies'); +const log = require('../logger'); + +// processes tasks, returns scripts +function processTasks(tasks) { + const scripts = {}; + let taskList = []; + + log.info('Processing tasks...'); + Object.keys(tasks).forEach((task) => { + taskList = taskList.concat(buildTasks(tasks[task], [task])); + }); + + log.info('Building scripts...'); + taskList.sort().forEach((item) => { + scripts[item.scriptName] = item.scriptValue; + }); + + log.info('Checking dependencies...'); + checkDependencies(taskList, Object.keys(scripts)); + + return scripts; +} + +module.exports = processTasks; diff --git a/test/Task.js b/test/Task.js index a46b86c..031107f 100644 --- a/test/Task.js +++ b/test/Task.js @@ -1,6 +1,6 @@ // nabs - Not another build system. Easy management of package.json scripts. // -// Copyright (C) 2016 James Kruth +// Copyright (C) 2019 James Kruth // // This file is part of nabs. // @@ -19,8 +19,7 @@ const chai = require('chai'); const td = require('testdouble'); - -const nabs = require('../dist').default; +const nabs = require('../src'); chai.should(); diff --git a/test/buildTasks.js b/test/buildTasks.js index e66774a..f29dea8 100644 --- a/test/buildTasks.js +++ b/test/buildTasks.js @@ -1,6 +1,6 @@ // nabs - Not another build system. Easy management of package.json scripts. // -// Copyright (C) 2016 James Kruth +// Copyright (C) 2019 James Kruth // // This file is part of nabs. // @@ -18,11 +18,11 @@ // along with this nabs. If not, see . const chai = require('chai'); -const nabs = require('../dist').default; +const nabs = require('../src'); chai.should(); -describe('buildTasks', () => { +describe('nabs.buildTasks', () => { it('should return a single task if tasks is string/array', () => { const name = []; let scripts; @@ -111,5 +111,5 @@ describe('buildTasks', () => { scripts[0].children[1].should.equal('test:sub2'); }); - it('should call itself recursively for each key'); + it('should call itself recursively for each key', () => {}); }); diff --git a/test/checkDependencies.js b/test/checkDependencies.js index 68593a0..dae0121 100644 --- a/test/checkDependencies.js +++ b/test/checkDependencies.js @@ -1,6 +1,6 @@ // nabs - Not another build system. Easy management of package.json scripts. // -// Copyright (C) 2016 James Kruth +// Copyright (C) 2019 James Kruth // // This file is part of nabs. // @@ -18,7 +18,7 @@ // along with this nabs. If not, see . const chai = require('chai'); -const nabs = require('../dist').default; +const nabs = require('../src'); const should = chai.should(); diff --git a/test/makeArray.js b/test/makeArray.js index c133b46..8d488de 100644 --- a/test/makeArray.js +++ b/test/makeArray.js @@ -1,6 +1,6 @@ // nabs - Not another build system. Easy management of package.json scripts. // -// Copyright (C) 2016 James Kruth +// Copyright (C) 2019 James Kruth // // This file is part of nabs. // @@ -18,7 +18,7 @@ // along with this nabs. If not, see . const chai = require('chai'); -const nabs = require('../dist').default; +const nabs = require('../src'); chai.should(); diff --git a/test/process.js b/test/process.js index 73c187f..cd5c1f4 100644 --- a/test/process.js +++ b/test/process.js @@ -1,6 +1,6 @@ // nabs - Not another build system. Easy management of package.json scripts. // -// Copyright (C) 2016 James Kruth +// Copyright (C) 2019 James Kruth // // This file is part of nabs. // @@ -20,14 +20,19 @@ const chai = require('chai'); const td = require('testdouble'); -const nabs = require('../dist').default; +const Task = require('../src/Task'); chai.should(); +let checkDependencies; +let buildTasks; +let process; describe('process', () => { beforeEach(() => { - nabs.buildTasks = td.function('buildTasks'); - nabs.checkDependencies = td.function('checkDependdencies'); + buildTasks = td.replace('../src/utils/buildTasks'); + checkDependencies = td.replace('../src/utils/checkDependencies'); + // eslint-disable-next-line global-require + process = require('../src/utils/process'); }); afterEach(() => { @@ -37,17 +42,17 @@ describe('process', () => { it('should process the tasks properly', () => { const name = 'test'; const action = 'my action'; - const task = new nabs.Task([name]); + const task = new Task([name]); task.addAction(action); - td.when(nabs.buildTasks(td.matchers.anything(), td.matchers.isA(Array))) + td.when(buildTasks(td.matchers.anything(), td.matchers.isA(Array))) .thenReturn([task]); - const scripts = nabs.process({ [name]: action }); + const scripts = process({ [name]: action }); scripts.should.have.property(name); scripts[name].should.equal(action); - td.verify(nabs.checkDependencies([task], ['test'])); + td.verify(checkDependencies([task], ['test'])); }); }); diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 5034e3d..e6ca2c5 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -9,7 +9,7 @@ const banner = readFileSync(resolve('webpack/file-header.txt')).toString(); module.exports = { target: 'node', entry: { - index: resolve('index.js'), + index: resolve('src/index.js'), }, output: { filename: '[name].js',