0.2.11 • Published 8 months ago
@produck/workspace v0.2.11
workspace
A tool module for define path aliases and build folder.
Installation
$ npm install @produck/workspaceExample
process.cwd(); // /home/user/exampleDefine 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');