Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
{
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn",
"semi": "warn"
}
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-unreachable": "warn",
"no-unused-vars": "warn",
"semi": "warn",
"valid-typeof": "warn"
}
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.node_modules

# Ignore all Markdown files:
*.md
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "auto",
"printWidth": 100,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
10 changes: 4 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint"]
}
44 changes: 21 additions & 23 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/test"
]
}
]
}
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/test"
]
}
]
}
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
}
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All notable changes to the Adobe Script Runner extension will be documented in t

### Added

-
- ESLint + Prettier for a consistent codebase

### Changed

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Adobe Script Runner executes script in the active viewer by default. However, wh
## Installation

- ### From VSCode application

- Open `Extensions` and type `Adobe Script Runner`.
- Click `Install` and then `Reload` button.

Expand All @@ -48,7 +49,7 @@ Keyboard shortcut `Cmd+R` is bind to `adobeScriptRunner.ae` command, which will
- Open Keyboard Shortcuts editor and click on the link `keybindings.json`.
- This will open the Default Keyboard Shortcuts on the left and your `keybindings.json` file where you can overwrite the default bindings on the right.
- With `keybindings.json` in focus click `Cmd+K` twice to open an interactive keybinding modal window (or whatever it’s called) and follow the on-screen instructions. This will create a new binding entry in the `keybindings.json` file.
- Edit the `command` property to `adobeScriptRunner.XX`, where XX is an abbreviation of the application. Check available abbreviations in `Extensions > Adobe Script Runner > Contributions` tab.
- Edit the `command` property to `adobeScriptRunner.XX`, where XX is an abbreviation of the application. Check available abbreviations in `Extensions > Adobe Script Runner > Contributions` tab.

The result should look something like this:

Expand Down Expand Up @@ -108,4 +109,4 @@ Executable paths for InCopy and InDesign for Windows are not exposed because the

## Known issues

- The host application does not get focus on script run.
- The host application does not get focus on script run.
42 changes: 21 additions & 21 deletions lib/buildCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ const ide = require('./ide.js');
* @param {Object} hostApp entry from hostApps[hostApp].
*/
function buildCommand(hostApp) {
try {
getScriptFile(function(scriptFile) {
getShellCommand(hostApp, scriptFile, function(command) {
console.log('Running shell command:', command);
cp.exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
try {
getScriptFile(function (scriptFile) {
getShellCommand(hostApp, scriptFile, function (command) {
console.log('Running shell command:', command);
cp.exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}

console.log(stdout);
console.log(stderr);
});
ide.showInformationMessage(`Script sent to ${hostApp.appName}`);
});
});
} catch (error) {
if (typeof error !== 'undefined') {
console.log(error);
}
}
console.log(stdout);
console.log(stderr);
});
ide.showInformationMessage(`Script sent to ${hostApp.appName}`);
});
});
} catch (error) {
if (typeof error !== 'undefined') {
console.log(error);
}
}
}

module.exports = buildCommand;
module.exports = buildCommand;
14 changes: 6 additions & 8 deletions lib/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ const vscode = require('vscode');
/**
* @description Method is called when extension is activated.
* Extension is activated the very first time the command is executed.
* @param {any} context vscode.ExtensionContext
*/
function activate(context) {
hostApps.forEach(hostApp => {
vscode.commands.registerCommand(
`adobeScriptRunner.${hostApp.shortName}`,
() => buildCommand(hostApp)
);
});
function activate() {
hostApps.forEach((hostApp) => {
vscode.commands.registerCommand(`adobeScriptRunner.${hostApp.shortName}`, () =>
buildCommand(hostApp)
);
});
}

exports.activate = activate;
108 changes: 54 additions & 54 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,59 @@ const os = require('os');
const path = require('path');

const file = {
/**
* Checks if file exists at a given path.
* @param {String} filePath Path to file.
* @returns {Boolean} `True` if exists, `False` otherwise.
*/
exists(filePath) {
return fs.existsSync(filePath);
},

/**
* Checks whether file exists at a path is file.
* @param {String} filePath Path to file.
* @returns {Boolean} `True` if file exists and is file, `False` otherwise.
*/
isFile(filePath) {
return this.exists(filePath) && fs.lstatSync(filePath).isFile();
},

/**
* Saves contents of the file.
* @param {String} contents Contents to save.
* @param {String} filePath Path to a file.
* @returns {String} Path to a saved file.
*/
saveFile(contents, filePath) {
filePath = this.untildify(filePath);

const folder = path.dirname(filePath);
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, {
recursive: true
});
}

fs.writeFileSync(filePath, contents);

return filePath;
},

/**
* Convert a tilde '~' path to an absolute path: '~/Desktop' to '/user/XXX/Desktop'
* @param {String} pathWithTilde Path to untildify.
* @returns {String} Absolute path as string.
*/
untildify(pathWithTilde) {
const homeDirectory = os.homedir();

if (typeof pathWithTilde !== 'string') {
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
}

return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
},
/**
* Checks if file exists at a given path.
* @param {String} filePath Path to file.
* @returns {Boolean} `True` if exists, `False` otherwise.
*/
exists(filePath) {
return fs.existsSync(filePath);
},

/**
* Checks whether file exists at a path is file.
* @param {String} filePath Path to file.
* @returns {Boolean} `True` if file exists and is file, `False` otherwise.
*/
isFile(filePath) {
return this.exists(filePath) && fs.lstatSync(filePath).isFile();
},

/**
* Saves contents of the file.
* @param {String} contents Contents to save.
* @param {String} filePath Path to a file.
* @returns {String} Path to a saved file.
*/
saveFile(contents, filePath) {
filePath = this.untildify(filePath);

const folder = path.dirname(filePath);
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, {
recursive: true,
});
}

fs.writeFileSync(filePath, contents);

return filePath;
},

/**
* Convert a tilde '~' path to an absolute path: '~/Desktop' to '/user/XXX/Desktop'
* @param {String} pathWithTilde Path to untildify.
* @returns {String} Absolute path as string.
*/
untildify(pathWithTilde) {
const homeDirectory = os.homedir();

if (typeof pathWithTilde !== 'string') {
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
}

return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
},
};

module.exports = file;
module.exports = file;
Loading