Skip to content

Instantly share code, notes, and snippets.

@iamssen
Last active March 1, 2019 04:56
Show Gist options
  • Save iamssen/d1c9965448f9df8691ce2b3b0c645bc9 to your computer and use it in GitHub Desktop.
Save iamssen/d1c9965448f9df8691ce2b3b0c645bc9 to your computer and use it in GitHub Desktop.
test diff view
From b9b957e40da2a8f4a30a14528fe7ec0736a69ea2 Mon Sep 17 00:00:00 2001
From: SSen <[email protected]>
Date: Sat, 19 Jan 2019 16:33:01 +0900
Subject: [PATCH] Update readme
---
package.json | 2 +-
readme.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index aa739dc..a262b30 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "multiplerun",
- "version": "0.1.3",
+ "version": "0.1.4",
"description": "Run multiple commands on multiple terminals (or iTerm split panes)",
"main": "index.js",
"scripts": {
diff --git a/readme.md b/readme.md
index 8d4bb36..61fda8f 100644
--- a/readme.md
+++ b/readme.md
@@ -32,6 +32,6 @@ npm run multiplerun-test
If you have installed [iTerm.app](https://www.iterm2.com/) on your Mac. You can see like this
-![iTerm Example](./readme-assets/iTerm.png)
+![iTerm Example](https://raw.githubusercontent.com/iamssen/multiplerun/master/readme-assets/iTerm.png)
Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`)
\ No newline at end of file
--
2.18.0
From 44886bc16426baff5e0a0817afb053cda625bc89 Mon Sep 17 00:00:00 2001
From: SSen <[email protected]>
Date: Tue, 19 Feb 2019 15:56:08 +0900
Subject: [PATCH] 0.2 Use in script
---
bin/multiplerun | 8 +++++---
index.js | 20 ++++++++++----------
package.json | 2 +-
readme.md | 20 +++++++++++++++++++-
4 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/bin/multiplerun b/bin/multiplerun
index e2a69c1..0fb380d 100755
--- a/bin/multiplerun
+++ b/bin/multiplerun
@@ -9,10 +9,12 @@ if (!fs.existsSync(packageJsonPath)) {
throw new Error(`πŸ’€ Undefined "${packageJsonPath}" file.`);
}
-const {multiplerun: layout} = JSON.parse(fs.readFileSync(packageJsonPath, {encoding: 'utf8'}));
+const {multiplerun: config} = JSON.parse(fs.readFileSync(packageJsonPath, {encoding: 'utf8'}));
-if (!layout) {
+if (!config) {
throw new Error(`πŸ’€ Undefined "multiplerun" option in "${packageJsonPath}" file.`);
+} else if (!config[process.argv[2]]) {
+ throw new Error(`πŸ’€ Undefined "${process.argv[0]}" layout in multiplerun config.`);
}
-multiplerun(layout[process.argv[2]]);
+multiplerun(config[process.argv[2]], process.cwd());
diff --git a/index.js b/index.js
index 012abe9..0fd141e 100644
--- a/index.js
+++ b/index.js
@@ -1,12 +1,12 @@
const {exec} = require('child_process');
const Application = require('./Application');
-function useDefaultTerminal(layout) {
+function useDefaultTerminal(layout, basedir) {
function run(command) {
if (process.platform === 'darwin') {
- exec(`osascript -e 'tell application "Terminal" to do script "cd ${process.cwd()}; ${command};"'`);
+ exec(`osascript -e 'tell application "Terminal" to do script "cd ${basedir}; ${command};"'`);
} else if (process.platform === 'win32') {
- exec(`start cmd /k "cd ${process.cwd()} && ${command}"`);
+ exec(`start cmd /k "cd ${basedir} && ${command}"`);
}
}
@@ -24,7 +24,7 @@ function useDefaultTerminal(layout) {
}
}
-function useIterm(layout) {
+function useIterm(layout, basedir) {
const iTerm = Application('iTerm');
iTerm.includeStandardAdditions = true;
@@ -43,29 +43,29 @@ function useIterm(layout) {
layout.forEach(row => {
if (typeof row === 'string') {
- iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${process.cwd()}; ${row};`});
+ iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${basedir}; ${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};`});
+ iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${basedir}; ${command};`});
commandCount++;
});
}
});
}
-module.exports = function (layout) {
+module.exports = function (layout, basedir = process.cwd()) {
if (process.platform === 'darwin') {
try {
- useIterm(layout);
+ useIterm(layout, basedir);
} catch (error) {
- useDefaultTerminal(layout);
+ useDefaultTerminal(layout, basedir);
}
} else if (process.platform === 'win32') {
- useDefaultTerminal(layout);
+ useDefaultTerminal(layout, basedir);
} else {
console.error(`😭 Sorry! Only macOS and Windows are supported yet!`);
}
diff --git a/package.json b/package.json
index a262b30..c509fe7 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "multiplerun",
- "version": "0.1.4",
+ "version": "0.2.1",
"description": "Run multiple commands on multiple terminals (or iTerm split panes)",
"main": "index.js",
"scripts": {
diff --git a/readme.md b/readme.md
index 61fda8f..a9ba9cf 100644
--- a/readme.md
+++ b/readme.md
@@ -34,4 +34,22 @@ If you have installed [iTerm.app](https://www.iterm2.com/) on your Mac. You can
![iTerm Example](https://raw.githubusercontent.com/iamssen/multiplerun/master/readme-assets/iTerm.png)
-Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`)
\ No newline at end of file
+Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`)
+
+# Run in script
+
+```js
+const multiplerun = require('multiplerun');
+
+multiplerun([
+ 'echo multiplerun!',
+ [
+ 'echo hello',
+ 'echo world'
+ ]
+]);
+```
+
+API
+
+- `multiplerun(layout, [basedir = process.cwd()])`
\ No newline at end of file
--
2.18.0
import path from 'path';
describe('js test', () => {
it('test', () => {
+ expect(path.join('a/b/c', 'd/e')).toEqual('a/b/c/d/e');
})
})
From b9b957e40da2a8f4a30a14528fe7ec0736a69ea2 Mon Sep 17 00:00:00 2001
From: SSen <[email protected]>
Date: Sat, 19 Jan 2019 16:33:01 +0900
Subject: [PATCH] Update readme
---
package.json | 2 +-
readme.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index aa739dc..a262b30 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "multiplerun",
- "version": "0.1.3",
+ "version": "0.1.4",
"description": "Run multiple commands on multiple terminals (or iTerm split panes)",
"main": "index.js",
"scripts": {
diff --git a/readme.md b/readme.md
index 8d4bb36..61fda8f 100644
--- a/readme.md
+++ b/readme.md
@@ -32,6 +32,6 @@ npm run multiplerun-test
If you have installed [iTerm.app](https://www.iterm2.com/) on your Mac. You can see like this
-![iTerm Example](./readme-assets/iTerm.png)
+![iTerm Example](https://raw.githubusercontent.com/iamssen/multiplerun/master/readme-assets/iTerm.png)
Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`)
\ No newline at end of file
--
2.18.0
From 44886bc16426baff5e0a0817afb053cda625bc89 Mon Sep 17 00:00:00 2001
From: SSen <[email protected]>
Date: Tue, 19 Feb 2019 15:56:08 +0900
Subject: [PATCH] 0.2 Use in script
---
bin/multiplerun | 8 +++++---
index.js | 20 ++++++++++----------
package.json | 2 +-
readme.md | 20 +++++++++++++++++++-
4 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/bin/multiplerun b/bin/multiplerun
index e2a69c1..0fb380d 100755
--- a/bin/multiplerun
+++ b/bin/multiplerun
@@ -9,10 +9,12 @@ if (!fs.existsSync(packageJsonPath)) {
throw new Error(`πŸ’€ Undefined "${packageJsonPath}" file.`);
}
-const {multiplerun: layout} = JSON.parse(fs.readFileSync(packageJsonPath, {encoding: 'utf8'}));
+const {multiplerun: config} = JSON.parse(fs.readFileSync(packageJsonPath, {encoding: 'utf8'}));
-if (!layout) {
+if (!config) {
throw new Error(`πŸ’€ Undefined "multiplerun" option in "${packageJsonPath}" file.`);
+} else if (!config[process.argv[2]]) {
+ throw new Error(`πŸ’€ Undefined "${process.argv[0]}" layout in multiplerun config.`);
}
-multiplerun(layout[process.argv[2]]);
+multiplerun(config[process.argv[2]], process.cwd());
diff --git a/index.js b/index.js
index 012abe9..0fd141e 100644
--- a/index.js
+++ b/index.js
@@ -1,12 +1,12 @@
const {exec} = require('child_process');
const Application = require('./Application');
-function useDefaultTerminal(layout) {
+function useDefaultTerminal(layout, basedir) {
function run(command) {
if (process.platform === 'darwin') {
- exec(`osascript -e 'tell application "Terminal" to do script "cd ${process.cwd()}; ${command};"'`);
+ exec(`osascript -e 'tell application "Terminal" to do script "cd ${basedir}; ${command};"'`);
} else if (process.platform === 'win32') {
- exec(`start cmd /k "cd ${process.cwd()} && ${command}"`);
+ exec(`start cmd /k "cd ${basedir} && ${command}"`);
}
}
@@ -24,7 +24,7 @@ function useDefaultTerminal(layout) {
}
}
-function useIterm(layout) {
+function useIterm(layout, basedir) {
const iTerm = Application('iTerm');
iTerm.includeStandardAdditions = true;
@@ -43,29 +43,29 @@ function useIterm(layout) {
layout.forEach(row => {
if (typeof row === 'string') {
- iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${process.cwd()}; ${row};`});
+ iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${basedir}; ${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};`});
+ iTerm.windows.byId(windowId).currentTab().sessions.at(commandCount).write({text: `cd ${basedir}; ${command};`});
commandCount++;
});
}
});
}
-module.exports = function (layout) {
+module.exports = function (layout, basedir = process.cwd()) {
if (process.platform === 'darwin') {
try {
- useIterm(layout);
+ useIterm(layout, basedir);
} catch (error) {
- useDefaultTerminal(layout);
+ useDefaultTerminal(layout, basedir);
}
} else if (process.platform === 'win32') {
- useDefaultTerminal(layout);
+ useDefaultTerminal(layout, basedir);
} else {
console.error(`😭 Sorry! Only macOS and Windows are supported yet!`);
}
diff --git a/package.json b/package.json
index a262b30..c509fe7 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "multiplerun",
- "version": "0.1.4",
+ "version": "0.2.1",
"description": "Run multiple commands on multiple terminals (or iTerm split panes)",
"main": "index.js",
"scripts": {
diff --git a/readme.md b/readme.md
index 61fda8f..a9ba9cf 100644
--- a/readme.md
+++ b/readme.md
@@ -34,4 +34,22 @@ If you have installed [iTerm.app](https://www.iterm2.com/) on your Mac. You can
![iTerm Example](https://raw.githubusercontent.com/iamssen/multiplerun/master/readme-assets/iTerm.png)
-Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`)
\ No newline at end of file
+Or those commands will be executed via default terminal app (`cmd.exe` or `Terminal.app`)
+
+# Run in script
+
+```js
+const multiplerun = require('multiplerun');
+
+multiplerun([
+ 'echo multiplerun!',
+ [
+ 'echo hello',
+ 'echo world'
+ ]
+]);
+```
+
+API
+
+- `multiplerun(layout, [basedir = process.cwd()])`
\ No newline at end of file
--
2.18.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment