-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
268 lines (193 loc) · 9.12 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */
/** Adobe Creative Cloud Extension Builder (based on CC Extension Builder [by davidderaedt])
Create HTML extensions for Adobe Creative Cloud products
by KICreATIVO [KIDev] (kicreativo.pro)
*/
define(function (require, exports, module) {
'use strict';
//console.log("INITIALIZING ACCBuilder EXTENSION");
var CommandManager = brackets.getModule("command/CommandManager");
var DocumentManager = brackets.getModule("document/DocumentManager");
var Menus = brackets.getModule("command/Menus");
var ProjectManager = brackets.getModule("project/ProjectManager");
var FileUtils = brackets.getModule("file/FileUtils");
var FileSystem = brackets.getModule("filesystem/FileSystem");
var Dialogs = brackets.getModule("widgets/Dialogs");
var PanelTemplate = require("text!html/main.html");
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
var AppInit = brackets.getModule("utils/AppInit");
var NodeConnection = brackets.getModule("utils/NodeConnection");
var accLogo = require.toUrl("html/img/acc.svg");
var ACC_MENU_ID = "ACCBuilder.menu";
var ACC_MENU_NAME = "ACC Extension Builder";
var NEW_ACC_CMDID = "ACCBuilder.newExt";
var NEW_ACC_MENU_NAME = "New ACC Extension";
var DEBUGMODE_ON_CMDID = "ACCBuilder.setDebugMode";
var DEBUGMODE_ON_CMDNAME = "Enable Debug Mode";
var SDK_FOLDER_NAME = "/SDK/";
var NODE_DOMAIN_LOCATION = "node/ACCDomain";
var SUCCESS_MSG = "The project was successfully created. Change the manifest file if necessary and use the debug mode. Good luck :)";
var HOSTS = [
'<Host Name="PHXS" Version="[14.0,19.0]" /><Host Name="PHSP" Version="[14.0,19.0]" />',
'<Host Name="ILST" Version="[17.0,22.0]" />',
'<Host Name="PPRO" Version="[7.0,12.0]" />',
'<Host Name="PRLD" Version="[2.0,7.0]" />',
'<Host Name="IDSN" Version="[9.0,13.0]" />',
'<Host Name="FLPR" Version="[13.0,18.0]" />',
'<Host Name="AEFT" Version="[12.0,15.0]" />'
];
var isWin = true;
var userHomeDir;
var nodeConnection;
var moduleFolder;
var sdkFolder;
function enableDebugging(){
var cmd = "";
if(isWin) {
cmd = '"'+sdkFolder.fullPath + 'debugmode.bat"';
} else {
cmd = "'"+sdkFolder.fullPath + "debugmode.sh'" ;
}
console.log("Brackets cmd:"+cmd);
var exePromise = nodeConnection.domains.ACC.execmd(cmd);
exePromise.fail(function (err) {
console.error("[brackets-ACC-node] failed to run ACC.execmd", err);
});
exePromise.done(function (stdout) {
alert("Debug Mode ON");
});
}
function createExtension(data) {
var cmd = "";
if(isWin) {
cmd = '"'+sdkFolder.fullPath + "newext.bat" + '" ' + data.template + ' ' + data.extid + "'";
} else {
cmd = "'"+sdkFolder.fullPath + "newext.sh" + "' " + data.template + " " + data.extid;
}
console.log("Brackets cmd:"+cmd);
var exePromise = nodeConnection.domains.ACC.execmd(cmd);
exePromise.fail(function (err) {
console.error("[brackets-ACC-node] failed to run ACC.execmd", err);
});
exePromise.done(function (stdout) {
var nstdout = stdout.replace(/[\r\n]/g, "");// remove line breaks
var path = nstdout.replace(/\\/g,"/");// normalize windows paths
// Modify manifest file
var manifestFile = new FileSystem.getFileForPath(path + "/CSXS/manifest.xml");
processTemplateFile(manifestFile, data);
// Modify debug file
var debugFile = new FileSystem.getFileForPath(path + "/.debug");
processTemplateFile(debugFile, data);
// Open project and document
ProjectManager.openProject(path).done(
function () {
DocumentManager.getDocumentForPath(path + "/CSXS/manifest.xml").done(
function (doc) {
DocumentManager.setCurrentDocument(doc);
alert(SUCCESS_MSG);
}
);
}
);
});
}
function _processTemplate(templateString, data) {
var str = templateString;
str = str.replace(new RegExp("com.example.ext", "g"), data.extid);
str = str.replace(new RegExp("Extension-Name", "g"), data.extname);
str = str.replace(new RegExp("<!--@defheight-->", "g"), data.defheight);
str = str.replace(new RegExp("<!--@defwidth-->", "g"), data.defwidth);
str = str.replace(new RegExp("<!--@minheight-->", "g"), data.minheight);
str = str.replace(new RegExp("<!--@minwidth-->", "g"), data.minwidth);
str = str.replace(new RegExp("<!--@maxheight-->", "g"), data.maxheight);
str = str.replace(new RegExp("<!--@maxwidth-->", "g"), data.maxwidth);
return str;
}
function processTemplateFile(srcFile, data) {
var srcTxt = "";
FileUtils.readAsText(srcFile)
.done(function (rawText, readTimestamp) {
var newText = _processTemplate(rawText, data);
FileUtils.writeText(srcFile, newText)
.fail(function (err) {
console.log(err);
});
})
.fail(function (err) {
console.log(err);
});
}
function initNodeDomain() {
var promise = nodeConnection.domains.ACC.initialize();
promise.fail(function (err) {
console.error("[brackets-ACC-node] failed to run ACC.initialize", err);
});
promise.done(function (path) {
console.log("Home directory: " + path);
userHomeDir = path;
});
return promise;
}
function initNodeCnx() {
nodeConnection = new NodeConnection();
var connectionPromise = nodeConnection.connect(true);
connectionPromise.fail(function () {
console.error("[brackets-ACC-node] failed to connect to node");
});
connectionPromise.done(function () {
var path = ExtensionUtils.getModulePath(module, NODE_DOMAIN_LOCATION);
var loadPromise = nodeConnection.loadDomains([path], true);
loadPromise.fail(function () {
console.log("[brackets-ACC-node] failed to load domain");
});
loadPromise.done(function () {
initNodeDomain();
});
});
}
function createPanel() {
ExtensionUtils.loadStyleSheet(module, "main.css");
Dialogs.showModalDialogUsingTemplate(PanelTemplate);
$("#html-acc-figure img").attr("src", accLogo);
$("#ACCSubmit").on("click", function (e) {
var data = {
extid : $("#ACC-id").val(),
extname : $("#ACC-accname").val(),
host: HOSTS[parseInt($("#ACC-host").val(), 10)],
width: $("#ACC-accwidth").val(),
height: $("#ACC-accheight").val(),
minwidth: $("#ACC-accminwidth").val(),
minheight: $("#ACC-accminheight").val(),
maxwidth: $("#ACC-accmaxwidth").val(),
maxheight: $("#ACC-accmaxheight").val(),
template: $("#ACC-template").val()
};
createExtension(data);
});
}
AppInit.appReady(function () {
isWin = (brackets.platform!="mac");
moduleFolder = FileUtils.getNativeModuleDirectoryPath(module);
sdkFolder = new FileSystem.getDirectoryForPath(moduleFolder + SDK_FOLDER_NAME);
initNodeCnx();
});
function setupMenu(){
CommandManager.register(NEW_ACC_MENU_NAME, NEW_ACC_CMDID, onMenuCreateNewACC);
function onMenuCreateNewACC(){
createPanel();
}
CommandManager.register(DEBUGMODE_ON_CMDNAME, DEBUGMODE_ON_CMDID, onMenuDebugModeOn);
function onMenuDebugModeOn(){
enableDebugging();
}
var ACCMenu = Menus.getMenu(ACC_MENU_ID);
if (!ACCMenu) {
ACCMenu = Menus.addMenu(ACC_MENU_NAME, ACC_MENU_ID, Menus.LAST);
}
ACCMenu.addMenuItem(NEW_ACC_CMDID);
ACCMenu.addMenuItem(DEBUGMODE_ON_CMDID);
//ACCMenu.addMenuDivider(Menus.BEFORE, NEW_ACC_COMMAND_ID);
}
setupMenu();
});