@kundan100/pater
v3.1.0
Published
personal assistant in terminal for devs, for recurring workflows.
Readme
pater
personal assistant in terminal for devs, for recurring workflows.
|
|
| -------------------------------------------- |
how to use
- for installation, run command
npm install -g @kundan100/pater - for usage, run command
pater. - few features run out of box without any configuration e.g.
- feature: kill port
- feature: System > Performance > Clear temp files
- few features need some configuration (e.g.your project-local-path)
- feature: Copy Local Changes
- you can also create your own custom-menu-item and link it to your-own-utility to run.
feature list:
- kill port
- when propmted, enter port-number and hit ENTER key.
- System > Performance > Clear temp files
- will clean temp files.
- Copy Local Changes
- use case: keep local changes in a local companion file and apply these changes in actual source file when needed.
- In your repo, make a copy of any source file and rename that by adding a prefix
cykLocal__. - You can gitignore/exclude this file from showing up in git-changes section.
- update
/config.jsonand/src/features/copyLocalChanges/copyLocalChangesConfig.jsonas explained in sectionProject setup for local dev
- Show status
- shows information (machine, processes, task-manager info etc...)
- Start service
- Stop service
command options
- Help:
pater --help- Basic:
pater
# prints: Welcome cyk-pa!- Version:
pater --version- Config:
pater --config
# prints: info regarding this tool's config- Echo (test arg forwarding):
pater --echo "hello"
# prints: hello- Verbose (prints debug info to stderr):
pater --verbose --echo hi
# prints debug info to stderr then 'hi' to stdoutProject setup for local dev
- clone the repo.
- create a file (.env for local use only) in project root.
- add these lines:
NPM_TOKEN=your-npm-token-for-publishingNODE_ENV=development
- For
DEBUG_LOG_ENABLEDto work properly,.envfile should exist (having code forNODE_ENV).
- add these lines:
- Configuration before running (follow sample)
- app level configuration
- update file
/config.jsonfor below items: OPEN_CONFIG_FILE_WHILE_CHECKING_CONFIGDEBUG_LOG_ENABLED
- update file
- configuration for shadowing file at local machine
- update file
/src/features/shadowManager/shadowManager.json
- update file
- feature level configuration (e.g. for copyLocalChanges)
- update
/src/features/copyLocalChanges/copyLocalChangesConfig.json - provide
repoRoot - provide
files(list of files) which needs to have local changes.
- update
- app level configuration
- for local testing of changes (without publishing or install):
index.jsis the entry point for this project. run caommandnpm startordotenv -e .env -- node index.js(from project root) to run this project locally.
- done.
Publish to npm
- after clone on your local, make sure that your file (./.env) has npm-token.
- for publishing:
- increase version number in package.json.
- run command (
npm run publish:env)
How to add new feature in this utility (through code)
- Add a menu-option in file (
src/menu/menuConfig.json). - Create a utility (e.g.
src/features/system/clearTempFiles.js) - Consume this newly created utility in file (
src/menu/index.js)
How to add new feature in this utility (through json configuration only)
- Add a menu-option in file (
src/menu/menuConfig.json). - Create an utility on your local machine.
- connect this (your local utility) with menu-option.
{
"key": "custom_your_world",
"label": "Custom: your world",
"enabled": true,
"action": {
"sourceType": "localMachine",
"sourceType__note": {
"localMachine": "Script should be present on the user's local machine at the specified sourcePath.",
"projectScope": "Script should be present within the project directory at the specified sourcePath."
},
"sourceBase": "userHomePath",
"sourceBase__note": {
"userHomePath": "Script path is relative to the user's home directory (C:/Users/<user-name>).",
"projectRoot": "Script path is relative to the project root directory."
},
"sourceScript": "/__cyk/util_scripts/printHi/index.js"
}
}Code workflow
index.jsis the entry point for this project.- run any command (from project root), to run this project locally:
npm start/dotenv -e .env -- node index.jsnpm start -- --config
- run any command (from project root), to run this project locally:
.envis loaded using npmdotenv-cli.- refer package.json script e.g.
"start": "dotenv -e .env -- node index.js",
- refer package.json script e.g.
handleArgsis called.- if args are passed then according to args it calls
printHelp,printVersion, etc. - if args are not passed, it calls
handleMenu.
- if args are passed then according to args it calls
- On first install, manage config files as shadow into local machine
Best practices followed
- In file
package.json, defineinternal import aliases.- It solves the classic "relative path hell".
- consume it like
const pkg = require('#root/package.json');from any part of the code.
"imports": {
"#root/*": "./*",
"#shared/*": "./src/shared/*.js",
"#features/*": "./src/features/*.js",
"#menu/*": "./src/menu/*.js",
"#args/*": "./src/args/*.js"
},Code flow diagram
create a code flow diagram for devs to understand the whole codebase and connections between different files
