Skip to content

Commit

Permalink
Release v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Oct 21, 2022
1 parent 985b460 commit e6508dc
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/run-scripts.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! run-scripts-util v0.0.0 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License
//! run-scripts-util v0.0.1 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License

export declare type Settings = {
quiet: boolean;
Expand Down
2 changes: 1 addition & 1 deletion dist/run-scripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! run-scripts-util v0.0.0 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License
//! run-scripts-util v0.0.1 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License

import { spawnSync } from 'node:child_process';
import fs from 'fs';
Expand Down
2 changes: 1 addition & 1 deletion dist/run-scripts.umd.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! run-scripts-util v0.0.0 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License
//! run-scripts-util v0.0.1 ~~ https://github.com/center-key/run-scripts-util ~~ MIT License

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "run-scripts-util",
"version": "0.0.0",
"version": "0.0.1",
"description": "Organize npm scripts into named groups of easy to manage commands (CLI tool designed for use in npm scripts)",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -63,13 +63,15 @@
"runScriptsConfig": {
"spec-a": [
"copy-folder bin spec/fixtures/target/a",
"copy-file spec/fixtures/target/a/cli.js spec/fixtures/target/a/cli2.js",
"copy-folder .github/workflows spec/fixtures/target/a"
],
"spec-b1": "copy-file LICENSE.txt spec/fixtures/target/b/license1.txt",
"spec-b1": "copy-file LICENSE.txt spec/fixtures/target/b1/license1.txt",
"spec-b2": [
"copy-file --cd=spec/fixtures/target/b license1.txt license2.txt",
"copy-file --cd=spec/fixtures/target/b license2.txt last.txt",
"rimraf spec/fixtures/target/b/license*.txt"
"copy-folder --cd=spec/fixtures/target b1 b2",
"copy-file --cd=spec/fixtures/target/b2 license1.txt license2.txt",
"copy-file --cd=spec/fixtures/target/b2 license2.txt last.txt",
"rimraf spec/fixtures/target/b1 spec/fixtures/target/b2/license*.txt"
]
},
"scripts": {
Expand All @@ -83,15 +85,14 @@
"pretest": "npm-run-all step:*",
"test": "mocha spec/*.spec.js"
},
"dependencies": {
},
"devDependencies": {
"@types/node": "~18.11",
"@typescript-eslint/eslint-plugin": "~5.40",
"@typescript-eslint/parser": "~5.40",
"add-dist-header": "~0.3",
"assert-deep-strict-equal": "~1.0",
"copy-file-util": "~0.1",
"copy-folder-util": "~0.2",
"eslint": "~8.25",
"jshint": "~2.13",
"mocha": "~10.1",
Expand Down
53 changes: 53 additions & 0 deletions spec/fixtures/target/a/cli2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node
//////////////////////
// run-scripts-util //
// MIT License //
//////////////////////

// Usage in package.json:
// "runScriptsConfig": {
// "clean": [
// "rimraf build dist"
// ],
// "compile": [
// "tsc",
// "lessc src/web-app/style.less build/web-app/style.css",
// "copy-folder src/graphics build/my-app/graphics",
// "replacer src/web-app --ext=.html --pkg build/my-app"
// ]
// },
// "scripts": {
// "pretest": "run-scripts clean compile",
// "test": "mocha spec",
// },
//
// Usage from command line:
// $ npm install --global run-scripts-util
// $ run-scripts compile --quiet

// Imports
import { runScripts } from '../dist/run-scripts.js';

// Parameters
const validFlags = ['quiet'];
const args = process.argv.slice(2);
const flags = args.filter(arg => /^--/.test(arg));
const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('=')));
const flagOn = Object.fromEntries(validFlags.map(flag => [flag, flag in flagMap]));
const invalidFlag = Object.keys(flagMap).find(key => !validFlags.includes(key));
const params = args.filter(arg => !/^--/.test(arg));

// Data
const groups = params; //list of script set names

// Run scripts
const error =
invalidFlag ? 'Invalid flag: ' + invalidFlag :
!params.length ? 'Must provide at lease one script group to run.' :
null;
if (error)
throw Error('[run-scripts-util] ' + error);
const options = {
quiet: flagOn.quiet,
};
groups.forEach(group => runScripts.exec(group, options));
File renamed without changes.
3 changes: 2 additions & 1 deletion spec/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Calling runScripts.exec()', () => {
const actual = fs.readdirSync('spec/fixtures/target/a').sort();
const expected = [
'cli.js',
'cli2.js',
'release-on-vtag.yaml',
'run-spec-on-push.yaml',
];
Expand All @@ -76,7 +77,7 @@ describe('Executing the CLI', () => {
it('with two command groups correctly runs them in serial', () => {
const cmd = 'node bin/cli.js spec-b1 spec-b2';
execSync(cmd);
const actual = fs.readdirSync('spec/fixtures/target/b').sort();
const actual = fs.readdirSync('spec/fixtures/target/b2').sort();
const expected = ['last.txt'];
assertDeepStrictEqual(actual, expected);
});
Expand Down

0 comments on commit e6508dc

Please sign in to comment.