From f0b042ba691a92b359b5ebbda689795f76d9810a Mon Sep 17 00:00:00 2001 From: Caleb McHenry Date: Mon, 14 Oct 2019 20:45:10 -0400 Subject: [PATCH 1/8] Split index.js file into smaller files td.replace is the `testdouble` function for mocking a module. Added `eslint-disable-next-line` due to needing to require a module dynamically in the test since that is how the module mocking works --- .vscode/settings.json | 3 + index.js | 258 --------------------------------- package.json | 4 +- src/Task.js | 85 +++++++++++ src/index.js | 77 ++++++++++ src/logger.js | 16 ++ src/main.js | 30 ++++ src/utils/buildTasks.js | 34 +++++ src/utils/checkDependencies.js | 16 ++ src/utils/makeArray.js | 20 +++ src/utils/process.js | 28 ++++ test/Task.js | 2 +- test/buildTasks.js | 8 +- test/checkDependencies.js | 2 +- test/makeArray.js | 2 +- test/process.js | 19 ++- 16 files changed, 330 insertions(+), 274 deletions(-) create mode 100644 .vscode/settings.json delete mode 100755 index.js create mode 100644 src/Task.js create mode 100755 src/index.js create mode 100644 src/logger.js create mode 100644 src/main.js create mode 100644 src/utils/buildTasks.js create mode 100644 src/utils/checkDependencies.js create mode 100644 src/utils/makeArray.js create mode 100644 src/utils/process.js 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 100755 index 31d7a76..0000000 --- a/index.js +++ /dev/null @@ -1,258 +0,0 @@ -#!/usr/bin/env node - -// nabs - Not another build system. Easy management of package.json scripts. -// -// Copyright (C) 2016 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 . - -'use strict'; - -const fs = require('fs'); -const jsonfile = require('jsonfile'); -const path = require('path'); -const program = require('commander'); -const winston = require('winston'); -const yaml = require('js-yaml'); - -const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '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 || '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 = '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]; - -if (!module.parent) { - // we've been run directly - log.info('Starting nabs v%s', version); - - try { - nabs.main(program); - } catch (e) { - log.error(e.message); - log.debug(e); - process.exit(1); - } -} else { - // we've been imported - just expose the machinery - module.exports = nabs; -} diff --git a/package.json b/package.json index 856801b..a1bd4df 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": "src/index.js", "scripts": { "test": "npm run test:lint && npm run test:unit", "test:lint": "eslint .", @@ -45,7 +45,7 @@ "node": ">=6" }, "bin": { - "nabs": "./index.js" + "nabs": "./src/index.js" }, "preferGlobal": true } diff --git a/src/Task.js b/src/Task.js new file mode 100644 index 0000000..68922c0 --- /dev/null +++ b/src/Task.js @@ -0,0 +1,85 @@ +'use strict'; + +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..bef52a8 --- /dev/null +++ b/src/index.js @@ -0,0 +1,77 @@ +#!/usr/bin/env node + +// nabs - Not another build system. Easy management of package.json scripts. +// +// Copyright (C) 2016 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 . + +'use strict'; + +const fs = require('fs'); +const path = 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(path.join(__dirname, '../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]; + +if (!module.parent) { + // we've been run directly + log.info('Starting nabs v%s', version); + + try { + nabs.main(program); + } catch (e) { + log.error(e.message); + log.debug(e); + process.exit(1); + } +} else { + // we've been imported - just expose the machinery + module.exports = nabs; +} diff --git a/src/logger.js b/src/logger.js new file mode 100644 index 0000000..a66a540 --- /dev/null +++ b/src/logger.js @@ -0,0 +1,16 @@ +'use strict'; + +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..8fede0f --- /dev/null +++ b/src/main.js @@ -0,0 +1,30 @@ +'use strict'; + +const fs = require('fs'); +const jsonfile = require('jsonfile'); +const yaml = require('js-yaml'); +const log = require('./logger'); + +function main(options) { + const nabsFile = options.nabs || '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 = process(tasks); + + if (!options.disable) { + 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..788b797 --- /dev/null +++ b/src/utils/buildTasks.js @@ -0,0 +1,34 @@ +'use strict'; + +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..6e5d5f6 --- /dev/null +++ b/src/utils/checkDependencies.js @@ -0,0 +1,16 @@ +'use strict'; + +// 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..d4e18a9 --- /dev/null +++ b/src/utils/makeArray.js @@ -0,0 +1,20 @@ +'use strict'; + +// 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..61ce887 --- /dev/null +++ b/src/utils/process.js @@ -0,0 +1,28 @@ +'use strict'; + +const buildTasks = require('./buildTasks'); +const checkDependencies = require('./checkDependencies'); +const log = require('../logger'); + +// processes tasks, returns scripts +function process(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 = process; diff --git a/test/Task.js b/test/Task.js index 04b7a99..c53153c 100644 --- a/test/Task.js +++ b/test/Task.js @@ -22,7 +22,7 @@ const chai = require('chai'); const td = require('testdouble'); -const nabs = require('../'); +const nabs = require('../src'); chai.should(); diff --git a/test/buildTasks.js b/test/buildTasks.js index faf048f..0d88ebc 100644 --- a/test/buildTasks.js +++ b/test/buildTasks.js @@ -2,7 +2,7 @@ // // Copyright (C) 2016 James Kruth // -// This file is part of nabs. +// This file is part of // // nabs is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -15,16 +15,16 @@ // 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 . +// along with this If not, see . 'use strict'; const chai = require('chai'); -const nabs = require('../'); +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; diff --git a/test/checkDependencies.js b/test/checkDependencies.js index 51b88f6..d7c3b88 100644 --- a/test/checkDependencies.js +++ b/test/checkDependencies.js @@ -20,7 +20,7 @@ 'use strict'; const chai = require('chai'); -const nabs = require('../'); +const nabs = require('../src'); const should = chai.should(); diff --git a/test/makeArray.js b/test/makeArray.js index 88e02b7..e28edf6 100644 --- a/test/makeArray.js +++ b/test/makeArray.js @@ -20,7 +20,7 @@ 'use strict'; const chai = require('chai'); -const nabs = require('../'); +const nabs = require('../src'); chai.should(); diff --git a/test/process.js b/test/process.js index 1115140..6bfc647 100644 --- a/test/process.js +++ b/test/process.js @@ -22,14 +22,19 @@ const chai = require('chai'); const td = require('testdouble'); -const nabs = require('../'); +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(() => { @@ -39,17 +44,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'])); }); }); From daba35d14444cc3746793c24d6d19a4c543fbdae Mon Sep 17 00:00:00 2001 From: Kunle Oshiyoye Date: Mon, 14 Oct 2019 18:57:05 -0400 Subject: [PATCH 2/8] Checksum package-lock.json instead of package.json --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5e9326f..2d9a243 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ jobs: - save_cache: paths: - node_modules - key: v1-dependencies-{{ checksum "package.json" }} + key: v1-dependencies-{{ checksum "package-lock.json" }} # run tests! - run: npm run test From 6a00945604fe59f43add52a9e925abf1315f26f8 Mon Sep 17 00:00:00 2001 From: Kunle Oshiyoye Date: Mon, 14 Oct 2019 19:05:49 -0400 Subject: [PATCH 3/8] Update to update other reference of package.json --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2d9a243..1c48125 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: # Download and cache dependencies - restore_cache: keys: - - v1-dependencies-{{ checksum "package.json" }} + - v1-dependencies-{{ checksum "package-lock.json" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- From 54821170b1d154a6abe6db105036a84fe3e39d9c Mon Sep 17 00:00:00 2001 From: Kunle Oshiyoye Date: Mon, 14 Oct 2019 19:11:21 -0400 Subject: [PATCH 4/8] Update support to Node 10 instead of 6, because it is not longer supported --- .circleci/config.yml | 2 +- README.md | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1c48125..2364c06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ jobs: build: docker: # specify the version you desire here - - image: circleci/node:6 + - image: circleci/node:10 working_directory: ~/repo diff --git a/README.md b/README.md index f0d23df..d3ee9d0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ nabs is a compiler that turns a nicely structured YAML file into script entries in your `package.json`. npm is a great minimal task runner that's already installed along with node. However, a large number of multi-action tasks in your `package.json` can be hard to manage. That's where nabs comes in. You can write your tasks in much easier to manage format and then compile them into standard script entries. -Note: nabs is only designed to work in Bourne shell compatible environments. It should work with Node 6.x or greater. +Note: nabs is only designed to work in Bourne shell compatible environments. It should work with Node 10.x or greater. ``` Usage: nabs [options] diff --git a/package.json b/package.json index 856801b..959bee8 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "testdouble": "^3.12.2" }, "engines": { - "node": ">=6" + "node": ">=10" }, "bin": { "nabs": "./index.js" From 6efd6f278c1d1f2fffe1e6891bc4a480b3b8f953 Mon Sep 17 00:00:00 2001 From: Ron Green <11993626+georgettica@users.noreply.github.com> Date: Sat, 19 Oct 2019 15:35:56 +0300 Subject: [PATCH 5/8] upgrade eslint-config-airbnb-base to 14.0.0 solves #15 --- index.js | 4 ++-- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 31d7a76..c4a6b92 100755 --- a/index.js +++ b/index.js @@ -121,7 +121,7 @@ nabs.Task = class Task { let rawActions = []; function npmify(arr) { - return arr.map(key => `npm run ${key}`); + return arr.map((key) => `npm run ${key}`); } // generate dependencies @@ -165,7 +165,7 @@ nabs.buildTasks = function buildTasks(tasks, name) { } Object.keys(tasks) - .filter(item => !item.startsWith('$')) + .filter((item) => !item.startsWith('$')) .forEach((key) => { scripts = scripts.concat(nabs.buildTasks(tasks[key], name.concat(key))); task.addChild(key); diff --git a/package-lock.json b/package-lock.json index d376bfd..98be4a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -300,9 +300,9 @@ "dev": true }, "confusing-browser-globals": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.7.tgz", - "integrity": "sha512-cgHI1azax5ATrZ8rJ+ODDML9Fvu67PimB6aNxBrc/QwSaDaM9eTfIEUHx3bBLJJ82ioSb+/5zfsMCCEJax3ByQ==", + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.9.tgz", + "integrity": "sha512-KbS1Y0jMtyPgIxjO7ZzMAuUpAKMt1SzCL9fsrKsX6b0zJPTaT0SiSPmewwVZg9UAO83HVIlEhZF84LIjZ0lmAw==", "dev": true }, "contains-path": { @@ -505,12 +505,12 @@ } }, "eslint-config-airbnb-base": { - "version": "13.2.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-13.2.0.tgz", - "integrity": "sha512-1mg/7eoB4AUeB0X1c/ho4vb2gYkNH8Trr/EgCT/aGmKhhG+F6vF5s8+iRBlWAzFIAphxIdp3YfEKgEl0f9Xg+w==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-14.0.0.tgz", + "integrity": "sha512-2IDHobw97upExLmsebhtfoD3NAKhV4H0CJWP3Uprd/uk+cHuWYOczPVxQ8PxLFUAw7o3Th1RAU8u1DoUpr+cMA==", "dev": true, "requires": { - "confusing-browser-globals": "^1.0.5", + "confusing-browser-globals": "^1.0.7", "object.assign": "^4.1.0", "object.entries": "^1.1.0" } diff --git a/package.json b/package.json index 959bee8..a3cc121 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "devDependencies": { "chai": "^4.2.0", "eslint": "^5.3.0", - "eslint-config-airbnb-base": "^13.2.0", + "eslint-config-airbnb-base": "^14.0.0", "eslint-plugin-import": "^2.18.2", "mocha": "^6.2.0", "testdouble": "^3.12.2" From 8b5a054871fd1fecafe505fe4efd6e21821a1a50 Mon Sep 17 00:00:00 2001 From: calebmchenry Date: Sun, 20 Oct 2019 19:20:24 -0400 Subject: [PATCH 6/8] lint files --- src/Task.js | 2 +- src/utils/buildTasks.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Task.js b/src/Task.js index 68922c0..7f09c4e 100644 --- a/src/Task.js +++ b/src/Task.js @@ -57,7 +57,7 @@ class Task { let rawActions = []; function npmify(arr) { - return arr.map(key => `npm run ${key}`); + return arr.map((key) => `npm run ${key}`); } // generate dependencies diff --git a/src/utils/buildTasks.js b/src/utils/buildTasks.js index 788b797..7feb2b2 100644 --- a/src/utils/buildTasks.js +++ b/src/utils/buildTasks.js @@ -21,7 +21,7 @@ function buildTasks(tasks, name) { } Object.keys(tasks) - .filter(item => !item.startsWith('$')) + .filter((item) => !item.startsWith('$')) .forEach((key) => { scripts = scripts.concat(buildTasks(tasks[key], name.concat(key))); task.addChild(key); From bf9a332221944d8694c71b9b0a3ce2c045a74196 Mon Sep 17 00:00:00 2001 From: calebmchenry Date: Thu, 31 Oct 2019 19:33:31 -0400 Subject: [PATCH 7/8] fix tests after merge --- package-lock.json | 3 +-- package.json | 4 ++-- src/Task.js | 4 ++-- src/index.js | 18 ++++++++---------- src/logger.js | 2 +- src/main.js | 7 ++++--- src/utils/buildTasks.js | 2 +- src/utils/checkDependencies.js | 2 +- src/utils/makeArray.js | 2 +- src/utils/process.js | 10 +++++----- test/Task.js | 2 +- test/buildTasks.js | 4 ++-- test/checkDependencies.js | 2 +- test/makeArray.js | 2 +- test/process.js | 19 ++++++++++++------- webpack/webpack.common.js | 2 +- 16 files changed, 44 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7463e79..1cf04ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2597,8 +2597,7 @@ "esm": { "version": "3.2.25", "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", - "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", - "dev": true + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==" }, "espree": { "version": "6.1.2", diff --git a/package.json b/package.json index fa3e99a..1cc2f51 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": "src/index.js", + "main": "dist/index.js", "scripts": { "build": "cross-env NODE_ENV=production webpack --config webpack/webpack.production.js --production", "prepare": "npm run build", @@ -57,7 +57,7 @@ "node": ">=10" }, "bin": { - "nabs": "./src/index.js" + "nabs": "./dist/index.js" }, "preferGlobal": true } diff --git a/src/Task.js b/src/Task.js index 3894833..ac95ebb 100644 --- a/src/Task.js +++ b/src/Task.js @@ -1,5 +1,5 @@ -const makeArray = require('./utils/makeArray').default; +const makeArray = require('./utils/makeArray'); class Task { constructor(name) { @@ -81,4 +81,4 @@ class Task { } } -export default Task; +module.exports = Task; diff --git a/src/index.js b/src/index.js index 1151bec..d0ed7ee 100755 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,3 @@ -#!/usr/bin/env node - // nabs - Not another build system. Easy management of package.json scripts. // // Copyright (C) 2019 James Kruth @@ -23,13 +21,13 @@ const fs = require('fs'); const { resolve } = require('path'); const program = require('commander'); -const log = require('./logger').default; -const Task = require('./Task').default; -const buildTasks = require('./utils/buildTasks').default; -const checkDependencies = require('./utils/checkDependencies').default; -const makeArray = require('./utils/makeArray').default; -const processTasks = require('./utils/process').default; -const main = require('./main').default; +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')); @@ -68,4 +66,4 @@ try { process.exit(1); } -export default nabs; +module.exports = nabs; diff --git a/src/logger.js b/src/logger.js index ca51537..2616590 100644 --- a/src/logger.js +++ b/src/logger.js @@ -12,4 +12,4 @@ const log = winston.createLogger({ }); -export default log; +module.exports = log; diff --git a/src/main.js b/src/main.js index 18176e4..060a5eb 100644 --- a/src/main.js +++ b/src/main.js @@ -3,7 +3,8 @@ const fs = require('fs'); const { resolve } = require('path'); const jsonfile = require('jsonfile'); const yaml = require('js-yaml'); -const log = require('./logger').default; +const log = require('./logger'); +const processTasks = require('./utils/process'); function main(options) { const nabsFile = options.nabs || resolve('nabs.yml'); @@ -14,7 +15,7 @@ function main(options) { log.info('Opening %s...', pkgFile); const pkg = jsonfile.readFileSync(pkgFile, 'utf8'); - pkg.scripts = process(tasks); + pkg.scripts = processTasks(tasks); if (!options.disable && !pkg.scripts.nabs) { pkg.scripts.nabs = 'nabs'; @@ -27,4 +28,4 @@ function main(options) { }); } -export default main; +module.exports = main; diff --git a/src/utils/buildTasks.js b/src/utils/buildTasks.js index 386d04f..59860e7 100644 --- a/src/utils/buildTasks.js +++ b/src/utils/buildTasks.js @@ -29,4 +29,4 @@ function buildTasks(tasks, name) { return scripts; } -export default buildTasks; +module.exports = buildTasks; diff --git a/src/utils/checkDependencies.js b/src/utils/checkDependencies.js index 5ab1eb2..1795763 100644 --- a/src/utils/checkDependencies.js +++ b/src/utils/checkDependencies.js @@ -11,4 +11,4 @@ function checkDependencies(tasks, names) { }); } -export default checkDependencies; +module.exports = checkDependencies; diff --git a/src/utils/makeArray.js b/src/utils/makeArray.js index b95a048..d3d49b6 100644 --- a/src/utils/makeArray.js +++ b/src/utils/makeArray.js @@ -16,4 +16,4 @@ function makeArray(item) { throw new Error(`Item must be string, array or null: ${item}`); } -export default makeArray; +module.exports = makeArray; diff --git a/src/utils/process.js b/src/utils/process.js index 0ec5784..ea4316f 100644 --- a/src/utils/process.js +++ b/src/utils/process.js @@ -1,10 +1,10 @@ -const buildTasks = require('./buildTasks').default; -const checkDependencies = require('./checkDependencies').default; -const log = require('../logger').default; +const buildTasks = require('./buildTasks'); +const checkDependencies = require('./checkDependencies'); +const log = require('../logger'); // processes tasks, returns scripts -function process(tasks) { +function processTasks(tasks) { const scripts = {}; let taskList = []; @@ -24,4 +24,4 @@ function process(tasks) { return scripts; } -export default process; +module.exports = processTasks; diff --git a/test/Task.js b/test/Task.js index ca78bdf..89cfc7c 100644 --- a/test/Task.js +++ b/test/Task.js @@ -19,7 +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 8af6f59..d932172 100644 --- a/test/buildTasks.js +++ b/test/buildTasks.js @@ -18,7 +18,7 @@ // along with this If not, see . const chai = require('chai'); -const nabs = require('../dist').default; +const nabs = require('../src'); chai.should(); @@ -111,5 +111,5 @@ describe('nabs.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..53b8494 100644 --- a/test/checkDependencies.js +++ b/test/checkDependencies.js @@ -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..6adde33 100644 --- a/test/makeArray.js +++ b/test/makeArray.js @@ -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..8366369 100644 --- a/test/process.js +++ b/test/process.js @@ -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 4a2efa9..03f5345 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -9,7 +9,7 @@ const banner = readFileSync(resolve('webpack/file-header.txt')).toString().conca module.exports = { target: 'node', entry: { - index: resolve('index.js'), + index: resolve('src/index.js'), }, output: { filename: '[name].js', From ea5878f2d4db0fdc3a54c86f1483601cd11b7e51 Mon Sep 17 00:00:00 2001 From: calebmchenry Date: Thu, 31 Oct 2019 19:46:27 -0400 Subject: [PATCH 8/8] doc: update copyright 2019 --- src/Task.js | 18 ++++++++++++++++++ src/logger.js | 18 ++++++++++++++++++ src/main.js | 18 ++++++++++++++++++ src/utils/buildTasks.js | 19 +++++++++++++++++++ src/utils/checkDependencies.js | 19 +++++++++++++++++++ src/utils/makeArray.js | 18 ++++++++++++++++++ src/utils/process.js | 18 ++++++++++++++++++ test/Task.js | 2 +- test/buildTasks.js | 6 +++--- test/checkDependencies.js | 2 +- test/makeArray.js | 2 +- test/process.js | 2 +- 12 files changed, 135 insertions(+), 7 deletions(-) diff --git a/src/Task.js b/src/Task.js index ac95ebb..1daa795 100644 --- a/src/Task.js +++ b/src/Task.js @@ -1,3 +1,21 @@ +// 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'); diff --git a/src/logger.js b/src/logger.js index 2616590..3fbda56 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,3 +1,21 @@ +// 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'); diff --git a/src/main.js b/src/main.js index 060a5eb..b649b24 100644 --- a/src/main.js +++ b/src/main.js @@ -1,3 +1,21 @@ +// 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'); diff --git a/src/utils/buildTasks.js b/src/utils/buildTasks.js index 59860e7..493f002 100644 --- a/src/utils/buildTasks.js +++ b/src/utils/buildTasks.js @@ -1,3 +1,22 @@ +// 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 diff --git a/src/utils/checkDependencies.js b/src/utils/checkDependencies.js index 1795763..720f8c6 100644 --- a/src/utils/checkDependencies.js +++ b/src/utils/checkDependencies.js @@ -1,3 +1,22 @@ +// 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); diff --git a/src/utils/makeArray.js b/src/utils/makeArray.js index d3d49b6..26348e7 100644 --- a/src/utils/makeArray.js +++ b/src/utils/makeArray.js @@ -1,3 +1,21 @@ +// 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) { diff --git a/src/utils/process.js b/src/utils/process.js index ea4316f..56905fb 100644 --- a/src/utils/process.js +++ b/src/utils/process.js @@ -1,3 +1,21 @@ +// 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'); diff --git a/test/Task.js b/test/Task.js index 89cfc7c..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. // diff --git a/test/buildTasks.js b/test/buildTasks.js index d932172..f29dea8 100644 --- a/test/buildTasks.js +++ b/test/buildTasks.js @@ -1,8 +1,8 @@ // 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 +// 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 @@ -15,7 +15,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this If not, see . +// along with this nabs. If not, see . const chai = require('chai'); const nabs = require('../src'); diff --git a/test/checkDependencies.js b/test/checkDependencies.js index 53b8494..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. // diff --git a/test/makeArray.js b/test/makeArray.js index 6adde33..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. // diff --git a/test/process.js b/test/process.js index 8366369..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. //