-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The current state of the project with the cli tool
- Loading branch information
0 parents
commit 546a6c5
Showing
6 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2022 Emmanuel Lampe | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# keshi | ||
|
||
A simple CLI for running commands concurrently. | ||
|
||
Made for laravel but works with everything. | ||
|
||
## Installation | ||
|
||
`yarn global add keshi-cli` | ||
|
||
`npm install keshi-cli --global` | ||
|
||
## Usage | ||
|
||
For starting everything you just need to run the command `keshi`. | ||
|
||
Keshi will then searches for a `keshi.default.js` with tasks, if it doesn't exist, the default built in commands will be used. | ||
|
||
### Default tasks | ||
|
||
```js | ||
export default { | ||
tasks: { | ||
laravel: 'php artisan serve', | ||
vue: 'yarn dev', | ||
}, | ||
}; | ||
``` | ||
|
||
### Running the command | ||
|
||
`keshi` | ||
|
||
## Goal | ||
|
||
I originally developed this tool for this purpose, so that I don't have to open multiple terminals each time when programming Laravel apps with VueJS. | ||
|
||
## Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Emmanuel Lampe](https://github.com/rexlmanu) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "keshi", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"bin": { | ||
"keshi": "./src/index.js" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"chalk": "^5.0.0" | ||
}, | ||
"author": { | ||
"name": "Emmanuel Lampe", | ||
"email": "[email protected]", | ||
"url": "https://github.com/rexlManu" | ||
}, | ||
"description": "A simple CLI for running commands concurrently" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env node | ||
|
||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { spawn } from 'child_process'; | ||
import chalk from 'chalk'; | ||
|
||
const cwd = process.cwd(); | ||
const defaultConfig = { | ||
tasks: { | ||
laravel: 'php artisan serve', | ||
vue: 'yarn dev', | ||
}, | ||
}; | ||
|
||
const runningTasks = []; | ||
|
||
let config = defaultConfig; | ||
|
||
// check if a windvel.config.js file exists | ||
const configFile = path.join(cwd, 'keshi.config.js'); | ||
if (fs.existsSync(configFile)) { | ||
// check if on windows | ||
const filePrefix = process.platform === 'win32' ? 'file://' : ''; | ||
const module = (await import(`${filePrefix}${configFile}`)).default; | ||
config = { ...defaultConfig, ...module }; | ||
} else { | ||
console.log(chalk.yellow('Using default config.')); | ||
console.log( | ||
chalk.yellow('No keshi.config.js file found in the current directory.'), | ||
); | ||
} | ||
|
||
// check if tasks are empty | ||
if (config.tasks.length === 0) { | ||
console.log(chalk.red('No tasks found in keshi.config.js')); | ||
process.exit(1); | ||
} | ||
|
||
// spawn a new process for each task and add them to the runningTasks array | ||
Object.keys(config.tasks).forEach((taskName) => { | ||
const task = config.tasks[taskName]; | ||
const taskProcess = spawn(task, { | ||
shell: true, | ||
}); | ||
console.log(chalk.green(`Spawned task: ${taskName} (${task})`)); | ||
const prefix = chalk.white(`[${chalk.cyan(taskName)}] `); | ||
runningTasks.push(taskProcess); | ||
// log the task output | ||
taskProcess.stdout.on('data', (data) => { | ||
// split data at newlines | ||
const lines = data.toString().split('\n'); | ||
lines.forEach((line) => { | ||
console.log(prefix + line); | ||
}); | ||
}); | ||
taskProcess.stderr.on('data', (data) => { | ||
// split data at newlines | ||
const lines = data.toString().split('\n'); | ||
lines.forEach((line) => { | ||
console.log(prefix + line); | ||
}); | ||
}); | ||
|
||
// when a task ends, remove it from the runningTasks array | ||
taskProcess.on('exit', () => { | ||
const index = runningTasks.indexOf(taskProcess); | ||
if (index > -1) { | ||
runningTasks.splice(index, 1); | ||
} | ||
}); | ||
}); | ||
|
||
// when the process gets terminated, kill all running tasks | ||
process.on('SIGINT', () => { | ||
console.log(chalk.red('\nTerminating all running tasks...')); | ||
runningTasks.forEach((task) => { | ||
task.kill('SIGINT'); | ||
}); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
chalk@^5.0.0: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.0.tgz#bd96c6bb8e02b96e08c0c3ee2a9d90e050c7b832" | ||
integrity sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ== |