npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

toolkit-utils

v0.0.1-alpha.33

Published

A set of utilities for creating toolkits

Downloads

28

Readme


⚠️ This is very much work in progress. The API will be facing breaking changes until it is no longer alpha.

Inspired by "Tools without config", "The Melting Pot of JavaScript", and kcd-scripts.

This library provides utility classes and methods for creating toolkits, used to abstract much of the overhead involved in regular JS and TS tasks, such as testing, linting, formatting, building, etc.

API

Classes

Functions

Project

Kind: global class

new Project([options])

| Param | Description | | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [options] | Options | | [options.debug] | Enables debug logs. | | [options.silent] | Silences the logger. | | [options.logger] | The instance of Signale to be used as a logger. | | [options.filesDir] | The directory of the scripts and config directories. May be the src or lib directory where the toolkit is called from. | | [options.toolkitRoot] | The root of the toolkit using this library. |

project.srcDir

Kind: instance property of Project

project.scriptsDir

Kind: instance property of Project

project.configDir

Kind: instance property of Project

project.toolkitName

Kind: instance property of Project

project.toolkitRootDir

Kind: instance property of Project

project.name

Kind: instance property of Project

project.package

Kind: instance property of Project

project.isCompiled

Kind: instance property of Project

project.isTypeScript

Kind: instance property of Project

project.toolkitBin

Kind: instance property of Project

project.availableScripts

Kind: instance property of Project

project.fromRoot(...part) ⇒

Kind: instance method of Project
Returns: Path in root directory.

| Param | Description | | ------- | ------------------------------------- | | ...part | Path relative to the root dir. |

project.fromToolkitRoot(...part) ⇒

Kind: instance method of Project
Returns: Path in toolkit root directory.

| Param | Description | | ------- | ---------------------------------------------------- | | ...part | Path relative to the root dir of the toolkit. |

project.fromConfigDir(...part) ⇒

Kind: instance method of Project
Returns: Path in config directory.

| Param | Description | | ------- | --------------------------------------- | | ...part | Path relative to the config dir. |

project.fromScriptsDir(...part) ⇒

Kind: instance method of Project
Returns: Path in scripts dir.

| Param | Description | | ------- | ---------------------------------------- | | ...part | Path relative to the scripts dir. |

project.hasAnyDep(deps) ⇒

Kind: instance method of Project
Returns: Boolean value based on the existence of dependency in package.json.

| Param | Description | | ----- | ------------------------------------------- | | deps | Dependency or dependencies to check. |

project.envIsSet(name) ⇒

Kind: instance method of Project
Returns: Whether the given environment variable is set.

| Param | Description | | ----- | ---------------------------------------------------- | | name | Name of the environment variable to look for. |

project.parseEnv(name, defaultValue) ⇒

Kind: instance method of Project
Returns: Environment variable or default value

| Param | Description | | ------------ | ------------------------------------------------------------ | | name | Name of the environment variable to look for. | | defaultValue | Default value if the environment variable is not net. |

project.packageHas(jsonPath) ⇒

Kind: instance method of Project
Returns: Whether the given path is in the package file

| Param | Description | | -------- | ------------------------ | | jsonPath | The path to check |

project.packageGet(jsonPath) ⇒

Kind: instance method of Project
Returns: The value at the given path in the package file

| Param | Description | | -------- | ----------------------------------- | | jsonPath | The path to get a value from |

project.packageSet(jsonPath, value)

Kind: instance method of Project

| Param | Description | | -------- | ----------------------------------- | | jsonPath | The path to get a value from | | value | The value to set at the path |

project.hasScript(scriptFile) ⇒

Kind: instance method of Project
Returns: Full path of the script. Null if none is found.

| Param | Description | | ---------- | ------------------------------------------------- | | scriptFile | Script file to check for the existance of. |

project.hasAnyFile(fileNames)

Kind: instance method of Project

| Param | Description | | --------- | ------------------------------------------------------------------------------- | | fileNames | The filename(s) including the extension to look for in the project root. |

project.writeFile(fileName, data)

Kind: instance method of Project

| Param | Description | | -------- | ---------------------------------------------------------------------------------------- | | fileName | The name of the file to be written | | data | The data to be written to the file. Objects that are provided will be serialized. |

project.copyFile(sourceFile, newFile)

Kind: instance method of Project

| Param | Description | | ---------- | ---------------------------------------- | | sourceFile | The path to the source file. | | newFile | The path to the destination file. |

project.bin(executable)

Kind: instance method of Project

| Param | Description | | ---------- | ---------------------------------- | | executable | The name of the executable. |

project.getConcurrentlyArgs(scripts, killOthers) ⇒

Kind: instance method of Project
Returns:

| Param | Description | | ---------- | --------------------------------------------------------------- | | scripts | Object with script names as keys and commands as values. | | killOthers | Whether all scripts should be killed if one fails. |

project.executeScriptFile(scriptFile, args)

Kind: instance method of Project

| Param | Description | | ---------- | ------------------------------------------------------------------------- | | scriptFile | The script file to execute from the "scripts" directory. | | args | A list of arguments to be passed to the script function. |

project.executeFromCLI(exit) ⇒

Kind: instance method of Project
Returns: Result of script

| Param | Description | | ----- | ------------------------------------ | | exit | Whether to exit from process. |

project.execute(...executables) ⇒ IScriptResult

Kind: instance method of Project
Returns: IScriptResult -

| Param | Type | Description | | -------------- | ----------------------- | --------------------------------- | | ...executables | Executable | Executable or executables. |

Example

// Execute some commands serially and concurrently. Commands in the object are executed concurrently.
// 1. `serial-command-1` is executed first.
// 2. `serial-command-2` is executed second.
// 3. Based on a condition, `serial-command-3` might be executed.
// 4. `build doc command`, `some-other-command`, and `tsc` are executed in parallel. (object keys are names used in logs)
// 5. Lastly, `other-serial-command` is executed.
const result = project.execute(
  ["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"]],
);

printHelp(scriptNames)

Kind: global function

| Param | Description | | ----------- | ------------------------------------- | | scriptNames | The list of available scripts. |

replaceArgumentName(args, names, newName) ⇒

Kind: global function
Returns: An array with the arguments replaced.

| Param | Description | | ------- | ------------------------------------------------ | | args | Arguments array. | | names | Parameter names to look for in arguments. | | newName | Parameter names to look for in arguments. |

Example

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