Skip to content

Commit fa0417a

Browse files
committed
- Fixed bug when settings were not registered until app restart.
- Fixed issue with HOME "~/" paths. - Changed code flow. Splits everything to modules for easier maintenance and development. Also makes it easier to other apps to adopt the functionality. Resolves #1 and #2.
1 parent bc536a2 commit fa0417a

12 files changed

Lines changed: 310 additions & 258 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to the Adobe Script Runner extension will be documented in t
44

55
## [Unreleased]
66

7+
- Fixed bug when settings were not registered until app restart.
8+
- Fixed issue with HOME "~/" paths.
9+
- Changed code flow. Splits everything to modules for easier maintenance and development. Also makes it easier to other apps to adopt the functionality.
10+
711
## Released
812

913
## [0.1.2] 2018-03-14

extension.js

Lines changed: 0 additions & 257 deletions
This file was deleted.

lib/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const vscode = require('vscode');
2+
3+
function update() {
4+
return vscode.workspace.getConfiguration('adobeScriptRunner');
5+
}
6+
7+
module.exports.update = update;

lib/editor.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const vscode = require('vscode');
2+
3+
const editor = {
4+
getActiveTextEditor() {
5+
return vscode.window.activeTextEditor;
6+
},
7+
8+
hasPath(activeTextEditor) {
9+
return !activeTextEditor.document.isUntitled;
10+
},
11+
12+
isDirty(activeTextEditor) {
13+
return activeTextEditor.document.isDirty && this.hasPath(activeTextEditor);
14+
},
15+
16+
getText(activeTextEditor) {
17+
return activeTextEditor.document.getText();
18+
},
19+
20+
getPath(activeTextEditor) {
21+
return activeTextEditor.document.fileName;
22+
},
23+
24+
save(activeTextEditor) {
25+
activeTextEditor.document.save();
26+
}
27+
}
28+
29+
module.exports = editor;

lib/extension.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const buildCommand = require('./static/buildCommand.js');
2+
const hostApps = require('./static/hostApps.js');
3+
const vscode = require('vscode');
4+
5+
/**
6+
* @description Method is called when extension is activated.
7+
* Extension is activated the very first time the command is executed.
8+
* @param {any} context vscode.ExtensionContext
9+
*/
10+
function activate(context) {
11+
hostApps.forEach(hostApp => {
12+
vscode.commands.registerCommand(
13+
`adobeScriptRunner.${hostApp.shortName}`,
14+
() => buildCommand(hostApp)
15+
);
16+
});
17+
}
18+
19+
exports.activate = activate;

lib/message.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const vscode = require('vscode');
2+
const message = {
3+
success (message) {
4+
vscode.window.showInformationMessage(message);
5+
},
6+
7+
info (message) {
8+
vscode.window.showWarningMessage(message);
9+
},
10+
11+
error (message) {
12+
vscode.window.showErrorMessage(string);
13+
}
14+
}
15+
16+
module.exports = message;

lib/static/buildCommand.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const cp = require('child_process');
2+
const getScriptFile = require('./getScriptFile.js');
3+
const getShellCommand = require('./getShellCommand.js');
4+
5+
const config = require('../config.js');
6+
const message = require('../message.js');
7+
8+
/**
9+
* @description Implementation of the activation command.
10+
* @param {any} hostApp Object, entry from hostApps[hostApp].
11+
* @returns {boolean} Nothing on success. 'null' on error.
12+
*/
13+
function buildCommand(hostApp) {
14+
try {
15+
const settings = config.update();
16+
const scriptFile = getScriptFile(settings);
17+
const command = getShellCommand(hostApp, scriptFile, settings);
18+
19+
console.log('Running shell command:', command);
20+
cp.exec(command, (err, result, raw) => {
21+
if (err) {
22+
return console.error(err);
23+
}
24+
console.log(result);
25+
console.log(raw);
26+
});
27+
28+
message.success(`Script sent to ${hostApp.appName}`);
29+
30+
} catch (err) {
31+
if (err) {
32+
message.error(err.toString());
33+
console.log(err);
34+
}
35+
}
36+
}
37+
38+
module.exports = buildCommand;

0 commit comments

Comments
 (0)