-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SSen
committed
Jan 19, 2019
0 parents
commit 56d626f
Showing
7 changed files
with
215 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,14 @@ | ||
/node_modules/ | ||
|
||
/*.iml | ||
/.idea/ | ||
|
||
/.yarnclean | ||
/*.log | ||
|
||
/dist-dev | ||
|
||
/tsconfig.lib.*.json | ||
/webpack.lib.*.js | ||
|
||
/package-lock.json |
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 @@ | ||
// --------------------------------------------- | ||
// Copied from https://github.com/eggplanetio/jxa/blob/reference-return/index.js | ||
// --------------------------------------------- | ||
|
||
const exec = require('child_process').execSync; | ||
|
||
function dereference(path, args) { | ||
try { | ||
args = args ? JSON.stringify(args) : ''; | ||
args = args.substr(1, args.length - 2); | ||
|
||
const cmd = `osascript -l JavaScript -e '${path}(${args})'`; | ||
const res = exec(cmd, {stdio: 'pipe'}).toString().trim(); | ||
if (res.indexOf('Application') === 0) { | ||
return createReference(res); | ||
} else { | ||
return res; | ||
} | ||
} catch (e) { | ||
// console.log(e); | ||
} | ||
} | ||
|
||
function createInspector(path) { | ||
return () => `[object JXAReference => ${dereference(path + '.toString')}]`; | ||
} | ||
|
||
function createReference(path) { | ||
return new Proxy( | ||
(recv, _, args) => dereference(path, args), | ||
{ | ||
apply: (target, thisArg, argumentsList) => dereference(path, argumentsList), | ||
|
||
get(target, propertyName) { | ||
return propertyName === 'inspect' | ||
? createInspector(path) | ||
: createReference(`${path}.${propertyName.toString()}`); | ||
}, | ||
|
||
set(target, property, value, receiver) { | ||
// TODO: Implement `set` proxy handler | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
module.exports = function (handle) { | ||
return createReference('Application("' + handle + '")'); | ||
}; |
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 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const multiplerun = require('../index'); | ||
|
||
const packageJsonPath = path.join(process.cwd(), 'package.json'); | ||
|
||
if (!fs.existsSync(packageJsonPath)) { | ||
throw new Error(`💀 Undefined "${packageJsonPath}" file.`); | ||
} | ||
|
||
const {multiplerun: layout} = JSON.parse(fs.readFileSync(packageJsonPath, {encoding: 'utf8'})); | ||
|
||
if (!layout) { | ||
throw new Error(`💀 Undefined "multiplerun" option in "${packageJsonPath}" file.`); | ||
} | ||
|
||
multiplerun(layout[process.argv[2]]); |
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,72 @@ | ||
const {exec} = require('child_process'); | ||
const Application = require('./Application'); | ||
|
||
function useDefaultTerminal(layout) { | ||
function run(command) { | ||
if (process.platform === 'darwin') { | ||
exec(`osascript -e 'tell application "Terminal" to do script "cd ${process.cwd()}; ${command};"'`); | ||
} else if (process.platform === 'win32') { | ||
exec(`start cmd /k "cd ${process.cwd()} && ${command}"`); | ||
} | ||
} | ||
|
||
for (const row of layout) { | ||
if (Array.isArray(row)) { | ||
for (const command of row) { | ||
if (typeof command !== 'string') { | ||
throw new Error('???'); | ||
} | ||
run(command); | ||
} | ||
} else if (typeof row === 'string') { | ||
run(row); | ||
} | ||
} | ||
} | ||
|
||
function useIterm(layout) { | ||
const iTerm = Application('iTerm'); | ||
|
||
iTerm.includeStandardAdditions = true; | ||
iTerm.activate(); | ||
|
||
iTerm.createWindowWithDefaultProfile(); | ||
|
||
const windowId = iTerm.currentWindow().id(); | ||
|
||
layout.forEach((row, r) => { | ||
if (r === 0) return; | ||
iTerm.windows.byId(windowId).currentTab().sessions.at(r - 1).splitVerticallyWithDefaultProfile(); | ||
}); | ||
|
||
let commandCount = 0; | ||
|
||
layout.forEach(row => { | ||
if (typeof row === 'string') { | ||
iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${process.cwd()}; ${row};`}); | ||
commandCount++; | ||
} else if (Array.isArray(row)) { | ||
row.forEach((command, c) => { | ||
if (c < row.length - 1) { | ||
iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).splitHorizontallyWithDefaultProfile(); | ||
} | ||
iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${process.cwd()}; ${command};`}); | ||
commandCount++; | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = function (layout) { | ||
if (process.platform === 'darwin') { | ||
try { | ||
useIterm(layout); | ||
} catch (error) { | ||
useDefaultTerminal(layout); | ||
} | ||
} else if (process.platform === 'win32') { | ||
useDefaultTerminal(layout); | ||
} else { | ||
console.error(`😭 Sorry! Only macOS and Windows are supported yet!`); | ||
} | ||
}; |
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,25 @@ | ||
{ | ||
"name": "multiplerun", | ||
"version": "0.1.3", | ||
"description": "Run multiple commands on multiple terminals (or iTerm split panes)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"bin": { | ||
"multiplerun": "./bin/multiplerun" | ||
}, | ||
"author": "Seoyeon Lee", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/iamssen/multiplerun.git" | ||
}, | ||
"upstream": { | ||
"git": "https://github.com/iamssen/multiplerun.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/iamssen/multiplerun/issues" | ||
}, | ||
"homepage": "https://github.com/iamssen/multiplerun" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 @@ | ||
# Run multiple commands on multiple terminals (or iTerm split panes) | ||
|
||
Install | ||
|
||
```sh | ||
npm install multiplerun --save-dev | ||
``` | ||
|
||
And add config to your `package.json` | ||
|
||
```json | ||
{ | ||
"name": "some-package", | ||
"scripts": { | ||
"multiplerun-test": "multiplerun test" | ||
}, | ||
"multiplerun": { | ||
"test": [ | ||
"echo multiplerun!", | ||
[ | ||
"echo hello", | ||
"echo world" | ||
] | ||
] | ||
} | ||
} | ||
``` | ||
|
||
```sh | ||
npm run multiplerun-test | ||
``` | ||
|
||
If you have installed [iTerm.app](https://www.iterm2.com/) on your Mac. You can see like this | ||
|
||
 | ||
|
||
Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`) |