Utility functions extract project(s) information. Make production easier & faster 🔎
get-info
Contains functions that read packages, validate
readability, return path, JSON, and used extension(js|ts) for each package found in workspace.
These functions are essential to deal with monorepos ./packages/**/src
, and it works as well for a
single package project ./src
.
npm install get-info
Extracts package json, extension, and resolved path for each project name. If
names
are not passed, it returns all json objects can be found in
./packages/**/package.json
or ./package json
/**
*
* @param {string} names required packages name
*
* @returns {Object} results
* @returns {Array} results[].json - packages json related to given path
* @returns {Object} results[].pkgInfo - {ext, path}
*/
const { json, pkgInfo } = getJsonByName(...names);
import { getJsonByName } from "get-info";
const { json, pkgInfo } = getJsonByName("myFav/project", "another/project");
json
//[{name: @myFav/project, version: "1.1.1", main: "index.js", ...}, {...}]
pkgInfo[@myFav/project]
// {ext: js, path: "./myFav-project"}
const { ext, path } = pkgInfo["@myFav/project"]
// to get default entry and resolved dist path:
const srcPath = resolve(path, "src", `index.${ext}`);
const buildPath = resolve(path, "dist");
Extracts package json, extension, and resolved path for each given path. If
paths
are not passed, it returns all json objects can be found in
./packages/**/package.json
or ./package.json
/**
*
* @param {sting} paths contains paths to resolve and extracts info form.
*
* @returns {Object} results
* @returns {Array} results[].json - packages json related to given path
* @returns {Object} results[].pkgInfo - {ext, path}
*/
const { json, pkgInfo } = getJsonByPath(...paths);
import { getJsonByPath } from "get-info";
const { json, pkgInfo } = getJsonByPath("./myProject");
json
// [{name: myProject, version: "1.1.1", main: "index.js", ...}]
pkgInfo[myProject]
// {ext: ts, path: "./myProject"}
Scans root directory (workspace), returns all project in there. It filters each path returns
only packages contain valid src/index[ext]
and have package.json
/**
*
* @param {string} [dir="./packages/*"]
*
* @returns {Object[]} results
* @returns {Array} results[].path valid path directory
* @returns {Array} results[].ext extension for each path (js|ts)
*/
const { path, ext } = getPackagesPath(dir);
import { getPackagesPath } from "get-info";
const { path, ext } = getPackagesPath();
// path [
// "./packages/myProj1",
// "./packages/myProj2",
// "./packages/myProj3"
// ];
// ext ["js", "ts", "ts"];
Gets extension used for project/**/src/**
import { utils } from "get-info";
/**
*
* @param {string} dir - given directory
* @returns {string} extension.
*/
const { getFileExtension } = utils;
const extension = getFileExtension(dir);
Validates access readability for package.json
& src
.
import { utils } from "get-info";
const { validateAccess } = utils;
/**
*
* @param {string} [dir="."]
* @param {string} [ext=getFileExtension(dir/src)]
* @param {string} [srcName="src"]
*
* @returns {Object} result
* @returns {boolean} result.isValid
* @returns {string} result.ext
*/
const { isValid, ext } = validateAccess(dir, ext, srcName);
Filters array of paths by validate each path. Make sure it has package.json
& src
.
import { utils } from "get-info";
const { filterPathAccess } = utils;
/**
*
* @param {Array} [pkgPath=[]]
* @returns {Object} results[]
* @returns {Array} results[].path filtered valid paths
* @returns {Array} results[].ext extension for each path (js|ts)
*/
const { path, ext } = filterPathAccess(pkgPath);
-
packageSorter - Sorting packages for monorepos production.
-
builderz - Build your project(s) with zero configuration
-
corename - Extracts package name.
-
move-position - Moves element index in an array.
-
textics & textics-stream - Counts lines, words, chars and spaces for a given string.
npm test
This project is licensed under the GPL-3.0 License