0.2.4 • Published 10 months ago

@produck/workspace v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

lerna npm (scoped) NPM npm

workspace

A tool module for define path aliases and build folder.

Installation

$ npm install @produck/workspace

Example

process.cwd(); // /home/user/example

Define path alias and get resolved path.

setPath: Define alias for path.\ getPath: Get path by path alias.\ resolve: Get resolved path by path alias and passed path name.\ names: Get generator for registered path alias.\ entries: Get generator for registered path.

import Workspace from '@produck/workspace';

const workspace = new Workspace();

worksapce.setPath('root', '.test');
workspace.getPath('root'); // /home/user/example/.test

workspace.setPath('log', 'log');
workspace.getPath('log'); // /home/user/example/.test/log

workspace.getPath('subLog'); // Error: 'The path named subLog is NOT existed.'

workspace.resolve('log', 'subLog'); // /home/user/example/.test/log/subLog

[...workspace.names()]; // ['root', 'log']
[...workspace.entries()];
// [['root', '/home/user/example/.test'], ['log', '/home/user/example/.test/log']]

Build folder.

buildRoot: Build folder for registered root path.\ build: Build folder by path alias and passed path name.\ buildAll: Build folder by all registered path.

workspace.buildRoot();
/**
 * /home/user/example
 *     └──.test
*/
// OR
workspace.build('log', '2023', '0710');
/**
 * /home/user/example
 *    └──.test
 *        └──log
 *            └──2023
 *                └──0710
*/
// OR
workspace.buildAll();
/**
 * /home/user/example
 *    └──.test
 *        └──log
 *
*/

Usage

As esModule,

import Workspace from '@produck/workspace';

const workspace = new Workspace();

As CommonJS,

const Workspace = require('@produck/workspace');
0.2.1

10 months ago

0.2.0

11 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.4

10 months ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago