Skip to content
Open
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
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
},
"homepage": "https://github.com/rkamysz/adobe-node#readme",
"devDependencies": {
"@types/node": "^12.12.5"
"@types/node": "^12.12.5",
"typescript": "^3.8.2"
},
"dependencies": {
"@types/minimist": "^1.2.0",
Expand Down
48 changes: 37 additions & 11 deletions src/broadcast.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
import { AdobeAppName, BroadcastBuilder, BroadcastMessage, Config } from "./api";
import { exec } from 'child_process';

const broadcastMethods: Map<AdobeAppName, (cmd: string) => string> = new Map<AdobeAppName, (cmd: string) => string>([
[AdobeAppName.Animate, (cmd: string) => `FLfile.runCommandLine("${cmd}");`],
[AdobeAppName.Photoshop, (cmd: string) => `app.system("${cmd}");`],
[AdobeAppName.Illustrator, (cmd: string) => `app.system("${cmd}");`],
]);
const createPayload = (command: string): string => {
return `{\\"command\\":\\"${command}\\",\\"stdout\\":\\"" + __stdout + "\\", \\"stderr\\":\\"" + __stderr + "\\" }`;
};

const buildBroadcastCommand = (host: string, port: number, message: string): string => {
return `adobe-broadcast --host='${host}' --port=${port} --msg='${message}'`;
}

const buildBroadcastCommand = (host: string, port: number, message: string) =>
`adobe-broadcast --host='${host}' --port=${port} --msg='${message}'`;
const broadcastMethods: Map<AdobeAppName, (host: string, port: number, command: string) => string> = new Map<AdobeAppName, (host: string, port: number, command: string) => string>([
[AdobeAppName.Animate, (host: string, port: number, command: string) => `FLfile.runCommandLine("${buildBroadcastCommand(host, port, createPayload(command))}");`],
[AdobeAppName.Photoshop, (host: string, port: number, command: string) => `app.system("${buildBroadcastCommand(host, port, createPayload(command))}");`],
[AdobeAppName.Illustrator, (host: string, port: number, command: string) => {
const cmd = `adobe-broadcast --host='${host}' --port=${port}`;
return `
if (!__stdout) {
__stdout = "{}";
}
if (!__stderr) {
__stderr = "";
}
const bt = new BridgeTalk();
bt.target = 'bridge';
const btCmd = '${cmd.replace(/'/g, "\\'")}';
bt.body = 'const cmd = "' + btCmd + '";';
bt.body += 'const msg = \\\'{"command": "${command}", "stdout": ' + __stdout + ', "stderr": "' + __stderr + '"}\\\';';
bt.body += 'const sys = cmd + " --msg=\\\'" + msg + "\\\'";';
bt.body += 'app.system(sys);';
bt.onError = function(bt)
{
alert("Error from BridgeTalk: " + bt.body);
};
bt.send();
`
}
]
]);

export const newBroadcastBuilder = (config: Config): BroadcastBuilder => {

return {
build(command: string) {
const payload: string = `{\\"command\\":\\"${command}\\",\\"stdout\\":\\"" + __stdout + "\\", \\"stderr\\":\\"" + __stderr + "\\" }`;
const broadcast: (msg: string) => string = broadcastMethods.get(config.app.name);
const cmd: string = buildBroadcastCommand(config.host, config.port, payload);
return broadcast(cmd);
const broadcast = broadcastMethods.get(config.app.name);
return broadcast(config.host, config.port, command);
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@ import { AdobeEventListener, BroadcastMessage } from './api';
import { Socket, Server, createServer } from 'net';

const newAdobeAppListener = (host: string, port: number, callback: (commandName: string) => void): AdobeEventListener => {

const callbacks: Map<string, Function> = new Map<string, Function>();
let server: Server;
let client:Socket;
let client: Socket;

function connectionListener(socket: Socket) {
client = socket;
socket.on('data', (buffer: Buffer) => {
const data: BroadcastMessage = JSON.parse(buffer.toString());

if (callbacks.has(data.command)) {
callbacks.get(data.command)(data.stdout, data.stderr);
try {
const dataString = buffer.toString();
const data: any = JSON.parse(dataString);
if (callbacks.has(data.command)) {
const callback = callbacks.get(data.command);
callback(data.stdout, data.stderr);
}
callback(data.command);
} catch (error) {
console.error("Failed to convert data: " + error);
}

callback(data.command);
});
}

function disposeServer() {
if(client) {
if (client) {
client.end();
}
server = null;
Expand Down
5 changes: 2 additions & 3 deletions src/script-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ var ___{{__command__}} = (function() {
__stdout = {{__fn__}}
} catch (e) {
__stderr = e;
} finally {
{{__broadcast__}}
}
}
{{__broadcast__}}
})();`;

const newAdobeScriptBuilder = (): AdobeScriptBuilder => {
Expand Down