Skip to content

Commit 66c6687

Browse files
committed
Build new release
1 parent 294c364 commit 66c6687

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

build/Runner.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import _extends from 'babel-runtime/helpers/extends';
44
import _Promise from 'babel-runtime/core-js/promise';
55

66
import { parse as parsePath } from 'path';
7+
import { lstatSync } from 'fs';
78
import { exec } from 'child_process';
89

910

@@ -18,14 +19,14 @@ export default class Runner {
1819
}
1920

2021
/**
21-
* Runs an array of commands on file
22+
* Runs hook on file
2223
*
2324
* @param {string} filePath
2425
* @param {string} hook
2526
*
2627
* @return {Promise<void>}
2728
*/
28-
run(filePath, hook) {
29+
runHook(filePath, hook) {
2930
const commands = this.config.getCommands(filePath, hook);
3031
const vars = this.getVars(filePath);
3132

@@ -60,6 +61,7 @@ export default class Runner {
6061
* project: '/home/user',
6162
* root: '/',
6263
* path: '/home/user/dir/file.txt',
64+
* relative: 'dir/file.txt',
6365
* dir: '/home/user/dir',
6466
* base: 'file.txt',
6567
* ext: '.txt',
@@ -71,12 +73,18 @@ export default class Runner {
7173
* @return {Object}
7274
*/
7375
getVars(filePath) {
74-
const [projectPath] = atom.project.relativizePath(filePath);
76+
const [projectPath, relativePath] = atom.project.relativizePath(filePath);
7577
const pathParts = parsePath(filePath);
7678

79+
if (lstatSync(filePath).isDirectory()) {
80+
pathParts.name = pathParts.name + pathParts.ext;
81+
pathParts.ext = '';
82+
}
83+
7784
return _extends({
7885
project: projectPath || pathParts.dir,
79-
path: filePath
86+
path: filePath,
87+
relative: projectPath ? relativePath : pathParts.base
8088
}, pathParts);
8189
}
8290

build/atom-hooks.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ import StatusView from './views/StatusView';
88
import Config from './Config';
99
import Runner from './Runner';
1010

11-
export default {
12-
statusBarTile: null,
13-
statusView: null,
14-
subscriptions: null,
15-
config: null,
16-
runner: null,
11+
class AtomHooks {
1712

1813
activate() {
1914
this.subscriptions = new CompositeDisposable();
@@ -32,7 +27,12 @@ export default {
3227

3328
this.readConfig();
3429

35-
this.subscriptions.add(atom.commands.add('atom-text-editor', 'atom-hooks:show', () => this.onToggleHooksList()));
30+
// this handler for modal hooks list
31+
this.subscriptions.add(atom.commands.add('atom-workspace', 'atom-hooks:show', event => {
32+
const filePath = event.target.getAttribute('data-path');
33+
34+
this.onToggleHooksList(filePath);
35+
}));
3636

3737
// reload our config when it is modified
3838
this.subscriptions.add(atom.config.observe('atom-hooks', () => this.readConfig()));
@@ -42,24 +42,24 @@ export default {
4242

4343
// onSave hook
4444
this.subscriptions.add(atom.workspace.observeTextEditors(textEditor => this.subscriptions.add(textEditor.onDidSave(event => this.onSaveFile(event.path)))));
45-
},
45+
}
4646

4747
readConfig() {
4848
this.config.setConfig({
4949
scripts: atom.config.get('atom-hooks.scripts') || {},
5050
hooks: atom.config.get('atom-hooks.hooks') || {}
5151
});
52-
},
52+
}
5353

5454
getCurrentFile() {
55-
const paneItem = atom.workspace.getActivePaneItem();
55+
const paneItem = atom.workspace.getCenter().getActivePaneItem();
5656

5757
if (paneItem && paneItem.getPath) {
5858
return paneItem.getPath();
5959
}
6060

6161
return null;
62-
},
62+
}
6363

6464
consumeStatusBar(statusBar) {
6565
this.statusBarTile = statusBar.addRightTile({
@@ -68,30 +68,35 @@ export default {
6868
});
6969

7070
this.statusView.hide(); // do not show till the text editor will be active
71-
},
71+
}
7272

7373
onChangeActivePane() {
74-
if (this.getCurrentFile() && this.config.listHooks(this.getCurrentFile()).length) {
74+
const filePath = this.getCurrentFile();
75+
76+
if (filePath && this.config.listHooks(filePath).length) {
7577
this.statusView.show();
7678
} else {
7779
this.statusView.hide();
7880
}
79-
},
81+
}
8082

81-
onToggleHooksList() {
83+
onToggleHooksList(filePath) {
8284
if (!this.hooksListView) {
8385
this.hooksListView = new HooksListView({
84-
listHooks: () => this.config.listHooks(this.getCurrentFile()),
85-
runCommand: command => this.processExecutionResult(this.runner.runCommand(this.getCurrentFile(), command))
86+
runCommand: (filePath, command) => this.processExecutionResult(this.runner.runCommand(filePath, command))
8687
});
8788
}
8889

89-
this.hooksListView.toggle();
90-
},
90+
filePath = filePath || this.getCurrentFile();
91+
92+
if (filePath) {
93+
this.hooksListView.show(filePath, this.config.listHooks(filePath));
94+
}
95+
}
9196

9297
onSaveFile(filePath) {
93-
this.processExecutionResult(this.runner.run(filePath, 'onSave'));
94-
},
98+
this.processExecutionResult(this.runner.runHook(filePath, 'onSave'));
99+
}
95100

96101
processExecutionResult(result) {
97102
this.statusView.updateState('loading');
@@ -100,14 +105,14 @@ export default {
100105
this.statusView.updateState('fail');
101106
this.notifyError('Error executing onSave scripts', error);
102107
});
103-
},
108+
}
104109

105110
notifyError(message, detail) {
106111
atom.notifications.addError(message, {
107112
detail: typeof detail === 'object' ? _JSON$stringify(detail, null, 2) : detail,
108113
dismissable: true
109114
});
110-
},
115+
}
111116

112117
deactivate() {
113118
this.subscriptions.dispose();
@@ -120,9 +125,15 @@ export default {
120125

121126
this.subscriptions = null;
122127
this.statusBarTile = null;
128+
// $FlowFixMe
123129
this.hooksListView = null;
130+
// $FlowFixMe
124131
this.statusView = null;
132+
// $FlowFixMe
125133
this.config = null;
134+
// $FlowFixMe
126135
this.runner = null;
127136
}
128-
};
137+
}
138+
139+
export default new AtomHooks();

build/views/HooksListView.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import SelectListView from 'atom-select-list';
44

55
export default class HooksListView {
66

7-
constructor({
8-
listHooks,
9-
runCommand
10-
}) {
11-
this.listHooks = listHooks;
7+
constructor({ runCommand }) {
128
this.runCommand = runCommand;
139
}
1410

15-
toggle() {
11+
show(filePath, hooks) {
1612
if (!this.listView) {
1713
this.listView = new SelectListView({
1814
items: [],
@@ -22,7 +18,7 @@ export default class HooksListView {
2218
return li;
2319
},
2420
didConfirmSelection: item => {
25-
this.runCommand(item.command);
21+
this.runCommand(this.filePath, item.command);
2622
this.destroyPanel();
2723
},
2824
didCancelSelection: () => {
@@ -31,8 +27,10 @@ export default class HooksListView {
3127
});
3228
}
3329

30+
this.filePath = filePath;
3431
this.listView.update({
35-
items: this.listHooks()
32+
infoMessage: filePath,
33+
items: hooks
3634
});
3735

3836
if (!this.panel) {

build/views/StatusView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class StatusView {
6969
onListHooks(event) {
7070
event.preventDefault();
7171

72-
atom.commands.dispatch(atom.workspace.getActiveTextEditor().element, 'atom-hooks:show');
72+
atom.commands.dispatch(atom.workspace.getCenter().getActivePaneItem().element, 'atom-hooks:show');
7373
}
7474

7575
getElement() {

0 commit comments

Comments
 (0)