0.8.9 • Published 6 years ago

script-helper v0.8.9

Weekly downloads
12
License
MIT
Repository
github
Last release
6 years ago

script-helper

Helper for creating and maintaining boilerplates, configurations and script modules for npm projects.

Commitizen friendly

Description

Provides utility class and related methods to create script modules which manipulate npm projects such as create/copy/remove files, directories and data files. Also provides reset() method which reverses all modifications made by this module.

Script modules help to develop npm modules without config. A very good article explaining this concept is written by Kent C. Dodds which can be found here.

With script-helper, it is very easy to cerate custom script modules.

Inspired

Inspired by kcd-scripts utility functions, thanks to Kent C. Dodds and all contributors.

Synopsis

Module Hierarchy

┏ 'project' module: npm project.
┣━━ 'my-scripts' module: Your custom scripts module to manipulate npm projects. Uses `script-helper` (this module).
┣━━━━ 'script-helper' module: This module.

Configuration

Configuration is based on cosmiconfig. See below for details.

'my-scripts' module

In examples below, it is assumed that your scripts module is named and uploaded to npm as my-scripts. You can use name you choose.

my-scripts/package.json

{
  "bin": { "my-scripts": "lib/index.js" },
  "scripts": {
    "postinstall": "my-scripts init",
    "preuninstall": "my-scripts reset",
    "test": "my-scripts test"
  }
}

my-scripts/lib/index.js

#!/usr/bin/env node

const { Project, execute } = require("script-helper");
const project = new Project();
module.exports = project; // If you don't want to use execute() helper, you can access exported project via require.

// If called from directly from CLI
if (require.main === module) {
  try {
    const result = project.executeFromCLISync(); // Optional helper which executes scripts in 'scripts' directory, which is in same directory with this file.
  } catch (e) {
    console.error(e);
    process.exit(1);
  }
}

project.executeFromCLISync() takes script name to execute and arguments from process.argv and requires your script and executes it's exported script() function, and passes 3 parameters.

  1. project: {@link Project} instance, to help tasks related to project module.
  2. args: args passed from CLI.
  3. s: {@link ScriptKit} instance, to help tasks related to script file which will be executed.

my-scripts/lib/scripts/init.js

function script(project, args, s) {
  // Reset previous modifications
  project.reset();

  // Add some scripts to package.json. (Does not overwrite if target keys are already defined or changed by user.)
  // You can change other keys by hand.
  project.package.set("scripts.test", "my-scripts test").set("scripts.compile", "my-scripts compile");

  // Create a .env file with default content. (Does not overwirte if it is already created or changed by user.)
  project.writeFile(".env", "PASSWORD=my-super-secret-password");

  // Create a symlink in project which points to a file in your custom module.
  // project/tsconfig.json -> project/node_modules/my-scripts/lib/config/tsconfig.json
  project.createSymLink("lib/config/tsconfig.json", "tsconfig.json");

  // Copy a file from your custom module to project.
  // Copy: project/node_modules/my-scripts/lib/config/changelog.md -> project/CHANGELOG.md
  project.copyFile("lib/config/changelog.md", "CHANGELOG.md");
}

// Function to be called must be exported under 'script' key if you use 'execute' helper.
module.exports = { script };

my-scripts/lib/scripts/reset.js

function script(project, args, s) {
  // Reset all created files, symlinks, changed JSON and YAML entries if they are not changed by user.
  // All modifications are tracked in a JSON file called 'my-scripts-registry.json'
  // 'my-scripts' is the name of your module and file name is shaped according the name of your module.
  project.reset();
}

module.exports = { script };

my-scripts/lib/scripts/build/index.js

function script(project, args, s) {
  // s is ScriptKit instance, see API doc.
  const subScript = project.isTypeScript ? "tsc" : "babel";

  // Executes my-scripts/lib/scripts/build/tsc.js or my-scripts/lib/scripts/build/babel.js
  return s.executeSubScriptSync(subScript, args);
}

module.exports = { script };

my-scripts/lib/scripts/build/tsc.js

function script(project, args, s) {
  // Execute some commands serially and concurrently. Commands in object is executed concurrently.
  // In example below, `serial-command-1` is executed first, then `serial-command-2` is executed, then based on condition `serial-command-3` is executed or not,
  // `build-doc-command`, `some-other-command` and `tsc` is executed using `concurrently` module (Keys are names used in log).
  // Lastly `other-serial-command` is executed. If some command in serial tasks fails, no further command is executed and function would return.
  return project.executeSync(
    ["serial-command-1", ["arg"]],
    "serial-command-2",
    someCondition ? "serial-command-3" : null,
    {
      my-parallel-job: ["build-doc-command", ["arg"],
      my-parallel-task: "some-other-command"
      builder: ["tsc", ["arg"],
    },
    ["other-serial-command", ["arg"]],
  );
}

module.exports = { script };

my-scripts/lib/scripts/test.js

process.env.BABEL_ENV = "test";
process.env.NODE_ENV = "test";

function script(project, args, s) {
  const config = []; // Some default config
  require("jest").run(config);
  return { status: 0, exit: false };
}

module.exports = { script };

and so on...

npm project module

package.json

Instead of adding scripts below manually, you can create an init script and add it to postinstall (see init example above)

{
  "scripts": {
    "test": "my-scripts test"
  }
}
> npm test

or

> node_modules/.bin/my-scripts test

Configuration

Your scripts module (i.e. my-scripts) has builtin cosmiconfig support. If user puts a cosmiconfig compatibale configuration in npm project, you can access configration via project.config() method in your script functions.

If script module contains user names such as @microsoft/typescript, cosmiconfig name is converted to dashed version: microsoft-typescript.

By default you can design your own configuration schema. script-helper provides some defaults and related methods, as described below:

KeyTypeMethodDescription
optInArray.<string>project.isOptedIn()Lists opted in options.
optOutArray.<string>project.isOptedOut()Lists opted out options.

Highlights

  • Tries best for non-destructive modifications.
  • Tracks all modifications in a registry json file.
  • Provides project.reset() method to reset all changes made by this module.
  • Changes in JSON and YAML files are tracked by key level using resettable.
    • User created keys and values would not be deleted/modified if { force: true } ıs not used.
    • User can further modify data files. They do not interfere with this module's targets.
    • CAVEAT: resettable cannot handle all cases, please see it's documentation and always use version control.
  • Changes in non data files are tracked using SHA-1 hash.
  • JSON, YAML and JavaScript files are normalized in memory before comparison to eliminate white-space noise.
  • Provides execute() helper function to execute your scripts and handle errors and saving project data files and registry.
  • Provides project.save() method for saving registry json file and changes made to data files.

Notes

  • For tracking data files by key level, use project.readDataFile() method, which returns DataObject
    • Methods of DataObject such as set(), remove() provides automatic log messages.
    • You can directly access data using .data property.
    • Tracking still works if you manipulate data from .data directly, because modifications are calculated during file save.
  • All data files read with project.readDataFile() are saved during project save (project.save()).
    • Do not use project.writeFile() for those files.
  • If user modifies file or data created by this library, they are not modified further if not forced with { force: true } option.
  • DO NOT forget project.save() after you finish your modifications.
    • Or use execute() helper function, which saves project even after error in your scripts, and handle process.exit() as necessary.
  • reset() method does not recreate deleted files and directories.

Disable Tracking

To completely disable tracking, set track to falsein constructor:

const project = new Project({ track: false });

Tracking may be enabled/disabled per operation:

project.writeFile("some.txt", "content", { track: false });

Please note that disabling tracking does not permit automatically modifying user created files / content. force option is still needed to overwrite. However non-tracked modifications are treated like user created content.

For example:

// Assume user.txt is created manually by user beforehand.
project.deleteFile("user.txt"); // NOT deleted, because it is created by user.
project.writeFile("auto.txt", "x"); // Created and tracked. It is known this file is created by this library.
project.deleteFile("auto.txt"); // Deleted, because it is known that file was created by this library.
project.writeFile("non-tracked.txt", "x", { track: false }); // Created and tracked. It is known this file is created by this library.
project.deleteFile("non-tracked.txt"); // NOT deleted, because it is not tracked, and it is unknown created by whom.
project.deleteFile("non-tracked.txt", { force: true }); // Deleted, because `force` is in effect.

API

Classes

Functions

Typedefs

Project

Kind: global class

new Project(options)

ParamTypeDefaultDescription
optionsObjectOptions
options.trackbooleanSets default tracking option for methods.
options.sortPackageKeysArray.<string>"scripts"Default keys to be sorted in package.json file.
options.logLevelLogLevel"info"Sets log level. ("error", "warn", "info", "debug", "verbose", "silly")
options.filesDirbooleanrequire.main.filenameDirectory of config and script directories. Default value assumes file called from CLI resides same dir with scripts and config.
options.cwdstring"project root"For Testing Working directory of project root.
options.moduleRootstring"module root"For Testing Root of the module using this library.
options.debugbooleanfalseTurns on debug mode.
options.loggerLoggerA looger instance such as winston. Must implement info, warn, error, verbose, silly.

project.name : string

Kind: instance property of Project
Read only: true

project.safeName : string

Kind: instance property of Project
Read only: true
Example

const name = project.name(); // @microsoft/typescript
const safeName = project.safeName(); // microsoft-typescript

project.moduleName : string

Kind: instance property of Project
Read only: true

project.safeModuleName : string

Kind: instance property of Project
Read only: true
Example

const name = project.moduleName(); // @user/my-scripts
const safeName = project.safeModuleName(); // user-my-scripts

project.moduleRoot : string

Kind: instance property of Project
Read only: true

project.config : Object

Kind: instance property of Project
Read only: true

project.package : DataObject

Kind: instance property of Project
Read only: true

project.modulePackage : Object

Kind: instance property of Project
Read only: true

project.isCompiled : boolean

Kind: instance property of Project
Read only: true

project.isTypeScript : boolean

Kind: instance property of Project
Read only: true

project.moduleBin : string

Kind: instance property of Project
Read only: true
Example

const bin = project.moduleBin; // "my-scripts"

project.availableScripts : Array.<string>

Kind: instance property of Project
Read only: true

project.scriptsDir : string

Kind: instance property of Project
Read only: true

project.configDir : string

Kind: instance property of Project
Read only: true

project.root : string

Kind: instance property of Project
Read only: true

project.sourceRoot : string

Kind: instance property of Project
Read only: true

project.track : boolean

Kind: instance property of Project
Read only: true

project.logger : BasicLogger

Kind: instance property of Project
Read only: true

project.logLevel : string

Kind: instance property of Project

project.resolveModule(name) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
namestringName of the module to get root path of.

Example

project.resolveModule("fs-extra"); // /path/to/project-module/node_modules/fs-extra

project.bin(executable) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
executablestringName of the executable

project.resolveScriptsBin(options, executable, cwd) ⇒ string | undefined

Kind: instance method of Project
Returns: string | undefined -

ParamTypeDefaultDescription
optionsObjectOptions.
executablestringExecutable name.
cwdstring"process.cwd()"Current working directory

Example

project.resolveScriptsBin(); // my-scripts (executable of this libraray)

project.resolveBin(modName, options, executable, cwd) ⇒ string

Kind: instance method of Project
Returns: string -

  • VError
ParamTypeDefaultDescription
modNamestringModule name to find executable from.
optionsObjectOptions.
executablestring"param.modName"Executable name. (Defaults to module name)
cwdstring"process.cwd()"Current working directory

Example

project.resolveBin("typescript", { executable: "tsc" }); // Searches typescript module, looks `bin.tsc` in package.json and returns it's path.
project.resolveBin("tsc"); // If `tsc` is defined in PATH, returns `tsc`s path, otherwise searches "tsc" module, which returns no result and throws error.
project.resolveBin("some-cmd"); // Searches "some-cmd" module and

project.fromModuleRoot(...part) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
...partstringPath parts to get path relative to module root.

project.fromConfigDir(...part) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
...partstringPath relative to config dir.

project.fromScriptsDir(...part) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
...partstringPath relative to scripts dir.

project.hasAnyDep(deps, t, f) ⇒ *

Kind: instance method of Project
Returns: * -

ParamTypeDefaultDescription
depsstring | Array.<string>Dependency or dependencies to check.
t*trueValue to return if any of dependencies exists.
f*falseValue to return if none of dependencies exists.

project.envIsSet(name) ⇒ boolean

Kind: instance method of Project
Returns: boolean -

ParamTypeDescription
namestringName of the environment variable to look for.

project.parseEnv(name, defaultValue) ⇒ *

Kind: instance method of Project
Returns: * -

ParamTypeDescription
namestringName of the environment variable
defaultValue*Default value to return if no environment variable is set or is empty.

project.executeFromCLISync(exit) ⇒ ScriptResult | void

Kind: instance method of Project
Returns: ScriptResult | void -

  • VError
ParamTypeDescription
exitbooleanWhether to exit from process.

Example

// in my-scripts/lib/index.js
project.executeFromCLI();

// in package.json
{ "scripts": { "test": "my-scripts test" } }

// on CLI
> npm run test
> node_modules/.bin/my-scripts test

project.executeScriptFileSync(scriptFile, args) ⇒ ScriptResult | Array.<ScriptResult>

Kind: instance method of Project
Returns: ScriptResult | Array.<ScriptResult> -

  • VError
ParamTypeDefaultDescription
scriptFilestringScript file to execute in scripts directory.
argsArray.<string>[]Arguments to pass script function.

Example

const result = executeScriptFileSync("build"); // Executes my-scripts/lib/scripts/build

project.hasScriptSync(scriptFile) ⇒ string | undefined

Kind: instance method of Project
Returns: string | undefined -

ParamTypeDescription
scriptFilestringModule file to check existence.

project.executeSync(...executables) ⇒ ScriptResult

Kind: instance method of Project
Returns: ScriptResult -

ParamTypeDescription
...executablesExecutableExecutable or executables.

Example

// Execute some commands serially and concurrently. Commands in object is executed concurrently.
// In example below, `serial-command-1` is executed first, then `serial-command-2` is executed, then based on condition `serial-command-3` is executed or not,
// `build-doc-command`, `some-other-command` and `tsc` is executed using `concurrently` module (Keys are names used in log).
// Lastly `other-serial-command` is executed. If some command in serial tasks fails, no further command is executed and function would return.
const result = project.executeSync(
  ["serial-command-1", ["arg"]],
  "serial-command-2",
  someCondition ? "serial-command-3" : null,
  {
    my-parallel-job: ["build-doc-command", ["arg"],
    my-parallel-task: "some-other-command"
    builder: ["tsc", ["arg"],
  },
  ["other-serial-command", ["arg"]],
);

project.executeWithoutExitSync(...executables) ⇒ ScriptResult

Kind: instance method of Project
Returns: ScriptResult -

ParamTypeDescription
...executablesExecutableExecutable or executables.

project.getConcurrentlyArgs(scripts, options, killOthers) ⇒ Array.<string>

Kind: instance method of Project
Returns: Array.<string> -

ParamTypeDefaultDescription
scriptsObject.<string, string>Object with script names as keys, commands as values.
optionsObjectOptions
killOthersbooleantrueWhether -kill-others-on-fail should added.

project.isOptedOut(key, t, f) ⇒ *

Kind: instance method of Project
Returns: * -

ParamTypeDefaultDescription
keystringParemeter to look for.
t*trueValue to return if it is opted out.
f*falseValue to return if it is not opted out.

project.isOptedIn(key, t, f) ⇒ *

Kind: instance method of Project
Returns: * -

ParamTypeDefaultDescription
keystringParemeter to look for.
t*trueValue to return if it is opted in.
f*falseValue to return if it is not opted in.

project.fromRoot(...part) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
...partstringPath or path parts to get full path in root.

Example

const resettable = new ResettableFile({ registryFile: "dir/registry.json" });
resettable.fromRoot("path/to/file.txt"); // dir/path/to/file.txt

project.fromSourceRoot(...part) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
...partstringPath or path parts to get full path in root.

Example

const resettable = new ResettableFile({ sourceRoot: "sourcedir" });
resettable.fromSourceRoot("path/to/file.txt"); // sourcedir/path/to/file.txt

project.isDataFile(projectFile) ⇒ boolean

Kind: instance method of Project
Returns: boolean -

ParamTypeDescription
projectFilestringFile to check

project.hasFileSync(projectFiles, t, f) ⇒ *

Kind: instance method of Project
Returns: * -

ParamTypeDefaultDescription
projectFilesstring | Array.<string>File or list of files to look in root.
t*trueValue to return if any of the files exists in root.
f*falseValue to return if none of the files exists in root.

project.isBrokenLink(projectFile) ⇒ boolena

Kind: instance method of Project
Returns: boolena -

ParamTypeDescription
projectFilestringProject file to check.

project.saveSync() ⇒ void

Kind: instance method of Project
Throws:

  • VError

project.resetSync() ⇒ void

Kind: instance method of Project
Throws:

  • VError

project.resetFileSync(projectFile) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDescription
projectFilestringFile to reset

project.getFileDetailsSync(projectFile, options) ⇒ FileDetail

Kind: instance method of Project
Returns: FileDetail -

  • VError
ParamTypeDescription
projectFilestringFile to get detail for.
optionsObjectOptions
options.forcebooleanAssume safe to operate on file even it is not auto created.
options.trackbooleanWhether to track file if it is created by module.

project.getFileHashSync(projectFile) ⇒ string

Kind: instance method of Project
Returns: string -

ParamTypeDescription
projectFilestringFile path of the file relative to root to calculate hash for.

project.getDataObjectSync(projectFile, options) ⇒ DataObject

Kind: instance method of Project
Returns: DataObject -

  • VError
ParamTypeDefaultDescription
projectFilestringFile path to read relative to root.
optionsObjectOptions
options.createbooleanfalseWhether to create file if it does not exist.
options.defaultContentObjectDefault content to write if file is created.
options.throwNotExistsbooleantrueThrow error if file does not exist.
options.formatbooleanfile extensionFormat to serialize data in given format. (json or yaml) Default is json.
options.createFormatboolean"json"Format to serialize data in given format. (json or yaml) Default is json.
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.
options.forcebooleanfalseWhether to force write file even it exist.
options.sortKeysArray.<string>List of keys which their values shoud be sorted. Key names be paths like "scripts.test"

project.createSymLinkSync(targetFile, projectFile, options) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDefaultDescription
targetFilestringTarget file which link points to. Should be given relative to module root.
projectFilestringLink file. Should be given relative to project root.
optionsObjectOptions
options.forcebooleanfalseWrites file even it exists and not auto created.
options.trackbooleanthis.trackWhether to track symlink if it is created by module.

Example

// Creates tsconfig.json symbolic link file in project root, pointing to a file from toolkit.
createSymLink(here("../../config.json"), "tsconfig.json");

project.readFileSync(projectFile, options) ⇒ *

Kind: instance method of Project
Returns: * -

  • VError
ParamTypeDefaultDescription
projectFilestringFile to read relative to root.
optionsObjectOptions
options.createbooleanfalseWhether to create file if it does not exist.
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.
options.forcebooleanfalseWhether to force create even it is deleted by user.
options.defaultContent*Default content to write if file does not exist.
options.throwNotExistsbooleantrueThrow error if file does not exist.
options.parsebooleanfalseWhether to parse file content to create a js object.
options.formatFormatfile extensionFormat to use parsing data.
options.createFormatFormatjsonFormat to be used while creating nonexisting file if no format is provided.
options.serializeFormatparseWhether to serialize content if file is created. (Default is status of parse option)

project.readFileDetailedSync(projectFile, options) ⇒ Object

Kind: instance method of Project
Returns: Object -

  • VError
ParamTypeDefaultDescription
projectFilestringFile to read relative to project root.
optionsObjectOptions
options.createbooleanfalseWhether to create file if it does not exist.
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.
options.forcebooleanfalseWhether to force create even it is deleted by user.
options.defaultContent*Default content to write if file does not exist.
options.throwNotExistsbooleantrueThrow error if file does not exist.
options.parsebooleanfalseWhether to parse file content to create a js object.
options.formatFormatfile extensionFormat to use parsing data.
options.createFormatFormatjsonFormat to be used while creating nonexisting file if no format is provided.
options.serializeFormatparseWhether to serialize content if file is created. (Default is status of parse option)

project.writeFileSync(projectFile, data, options) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDefaultDescription
projectFilestringFile path to relative to project root.
datastringData to write
optionsObjectOptions
options.forcebooleanfalseWrites file even it exists and not auto created.
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.
options.serializebooleanfalseWhether to serialize object before written to file.
options.formatFormatfile extensionFormat to use serializing data.
options.sortKeysArrayKeys to be sorted. Keys may be given as chained paths. (i.e. a.b.c -> Keys of c would be sorted)

Example

project.writeFile("./some-config.json", '{"name": "my-project"}'); // Writes given data to some-config.json in project root.

project.deleteFileSync(projectFile, options) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDefaultDescription
projectFilestringFile path relative to paroject root.
optionsObjectOptions
options.forcebooleanfalseDeletes file even it exists and not auto created.
options.trackbooleanthis.trackWhether to operate in tracked mode. In non-tracked mode existing files are not deleted if force is not active.
options.logbooleantrueWhether to log operation.
options.brokenLinkbooleanfalseWhether project file is a broken link. Broken links are treated as if they do not exist.

Example

project.copy("./some-config.json", "./some-config.json"); // Copies some-config.json file from module's root to project's root.

project.copyFileSync(sourceFile, projectFile, options) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDefaultDescription
sourceFilestringSource file path.
projectFilestringDestinantion file path relative to paroject root.
optionsObjectOptions
options.forcebooleanfalseOverwrites file even it exists and not auto created.
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.

Example

project.copy("./some-config.json", "./some-config.json"); // Copies some-config.json file from module's root to project's root.

project.createDirSync(projectDir, options) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDefaultDescription
projectDirstringDirectory path to relative to project root.
optionsObjectOptions
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.
options.logDirsbooleantrueWhether to log delete operation of sub directories.

Example

project.createDir("path/to/dir"); // Created "path", "to" and "dir" as necessary.

project.deleteDirSync(projectDir, options) ⇒ void

Kind: instance method of Project
Throws:

  • VError
ParamTypeDefaultDescription
projectDirstringDestinantion directory to delete.
optionsObjectOptions
options.forcebooleanfalseDeletes directory and it's contents even it is not empty.
options.trackbooleanthis.trackWhether to track file in registry if it is created by module.
options.logFilesbooleantrueWhether to log delete operation of files.
options.logDirsbooleantrueWhether to log delete operation of sub directories.

DataObject

Kind: global class

new DataObject(data, options)

ParamTypeDefaultDescription
dataObject{}Data to be modified.
optionsObjectOptions
options.trackbooleanWhether to track changes.
options.sortKeysArray.<string>List of keys which their values shoud be sorted. Key names be paths like "scripts.test"
options.namestringPath of the name to be used in logs.
options.formatFormatData format used for parsing and serializing data.
options.operationsArray.<Operation>Operations to reset data to its original state.
options.loggerLoggerA looger instance such as winston. Must implement silky, verbose, info, warn, error.

dataObject.isChanged : boolean

Kind: instance property of DataObject
Read only: true

dataObject.data : Data

Kind: instance property of DataObject
Read only: true

dataObject.original : Data

Kind: instance property of DataObject
Read only: true

dataObject.snapshot : Data

Kind: instance property of DataObject
Read only: true

dataObject.has(props, t, f) ⇒ *

Kind: instance method of DataObject
Returns: * -

ParamTypeDefaultDescription
propsstring | Array.<Path>Property or properties to look in data
t*trueValue to return if some of the properties exists in project.
f*falseValue to return if none of the properties exists in project.

Example

const result = project.hasProp(["scripts.build", "scripts.build:doc"], "yes", "no");

dataObject.hasSubProp(prop, subProps, t, f) ⇒ *

Kind: instance method of DataObject
Returns: * -

ParamTypeDefaultDescription
propPathProperty or properties to look in data
subPropsstring | Array.<Path>Property or properties to look in data
t*trueValue to return if some of the properties exists.
f*falseValue to return if none of the properties exists.

Example

const result = project.hasSubProp("scripts", ["build", "build:doc"]);
const result2 = project.hasSubProp("address.home", ["street.name", "street.no"]);

dataObject.get(path) ⇒ *

Kind: instance method of DataObject
Returns: * -

ParamTypeDescription
pathPathPath to get data from

dataObject.set(path, value, options) ⇒ this

Kind: instance method of DataObject
Returns: this -

ParamTypeDefaultDescription
pathPathPath to store data at.
value*Value to store at given key.
optionsObjectOptions
options.forcebooleanfalseWhether to force change even value is altered by user manually.

dataObject.setObject(data, options) ⇒ this

Kind: instance method of DataObject
Returns: this -

ParamTypeDefaultDescription
dataObjectData to store at object.
optionsObjectOptions
options.forcebooleanfalseWhether to force change even value is altered by user manually.

Example

data.setObject({ "a.b": 1, c: 2, d: 3 });

dataObject.remove(path, options) ⇒ this

Kind: instance method of DataObject
Returns: this -

ParamTypeDefaultDescription
pathstring | Array.<Path>Path or list of paths to remove
optionsObjectOptions
options.forcebooleanfalseWhether to force change even value is altered by user manually.

dataObject.reset() ⇒ Array.<Operation>

Kind: instance method of DataObject
Returns: Array.<Operation> -

replaceArgumentName(args, names, newName) ⇒ Array

Kind: global function
Returns: Array -

ParamTypeDescription
argsArrayArguments array.
namesstring | Array.<string>Parameter names to look for in arguments.
newNamestringParameter names to look for in arguments.

Example

const arguments = ["--a", "--b"];
replaceArgumentName(arguments, ["--a"], "--c"); // -> ["--c", "--b"]

Options : Object

Kind: global typedef
Properties

NameTypeDescription
stdioArraystdio parameter to feed spawn
encodingstringencoding to provide to feed spawn

Executable : string | Array.<(string|Array.<string>|SpawnOptions)>

Kind: global typedef
Example

const bin = "tsc";
const binWithArgs = ["tsc", ["--strict", "--target", "ESNext"]];
const binWithOptions = ["tsc", ["--strict", "--target", "ESNext"], { encoding: "utf-8" }];

ScriptResult : Object

Kind: global typedef
Properties

NameTypeDescription
statusnumberExit status code of cli command (0: success, other value: error)
errorErrorError object if execution of cli command fails.
previousResultsArray.<ScriptResult>If more than one command is executed serially, results of prevoulsy executed commands.
exitbooleanWhether script should exit after finishes its job. (Default behaviour is exit/true)

Script : function

Kind: global typedef

ParamTypeDescription
projectProjectProject instance.
argsArray.<string>Argument.
scriptKitScriptKitScriptKit instance, which have utility methods fro currently executed script file.
0.8.9

6 years ago

0.8.8

6 years ago

0.8.7

6 years ago

0.8.6

6 years ago

0.8.5

6 years ago

0.8.4

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago