-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·263 lines (187 loc) · 8.72 KB
/
main.js
File metadata and controls
executable file
·263 lines (187 loc) · 8.72 KB
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
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */
/** CCExtBuilder Extension
Create HTML based Extensions for Creative Cloud applications
*/
define(function (require, exports, module) {
'use strict';
//console.log("INITIALIZING CCExtBuilder 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!panel.html");
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
var AppInit = brackets.getModule("utils/AppInit");
var NodeConnection = brackets.getModule("utils/NodeConnection");
var CCEXT_MENU_ID = "CCExtBuilder.menu";
var CCEXT_MENU_NAME = "CC Extension Builder";
var NEW_CCEXT_CMDID = "CCExtBuilder.newExt";
var NEW_CCEXT_MENU_NAME = "New Creative Cloud Extension";
var DEBUGMODE_ON_CMDID = "CCExtBuilder.setDebugMode";
var DEBUGMODE_ON_CMDNAME = "Enable Debug Mode";
var SDK_FOLDER_NAME = "/CC-EXT-SDK/";
var NODE_DOMAIN_LOCATION = "node/CCExtDomain";
var SUCCESS_MSG = "Extension successfully created. Please Edit the manifest file according to your needs and launch the corresponding CC app.";
var HOSTS = [
'<Host Name="PHXS" Version="[14.0,2100.0]" /><Host Name="PHSP" Version="[14.0,2100.0]" />',
'<Host Name="ILST" Version="[17.0,2100.0]" />',
'<Host Name="PPRO" Version="[7.0,2100.0]" />',
'<Host Name="PRLD" Version="[2.0,2100.0]" />',
'<Host Name="IDSN" Version="[9.1,2100.0]" />',
'<Host Name="FLPR" Version="[13.1,2100.0]" />',
'<Host Name="AEFT" Version="[13.0,2100.0]" />'
];
var isWin = true;
var userHomeDir;
var nodeConnection;
var moduleFolder;
var sdkFolder;
function enableDebugging(){
var cmd = "";
if(isWin) {
cmd = '"'+sdkFolder.fullPath + 'setdebugmode.bat"';
} else {
cmd = "'"+sdkFolder.fullPath + "setdebugmode.sh'" ;
}
console.log("Brackets cmd:"+cmd);
var exePromise = nodeConnection.domains.ccext.execmd(cmd);
exePromise.fail(function (err) {
console.error("[brackets-ccext-node] failed to run ccext.execmd", err);
});
exePromise.done(function (stdout) {
alert("Debug Mode ON");
});
}
function createExtension(data) {
var cmd = "";
if(isWin) {
cmd = '"'+sdkFolder.fullPath + "createext.bat" + '" default ' + data.extid + "'";
} else {
cmd = "'"+sdkFolder.fullPath + "createext.sh" + "' default " + data.extid;
}
console.log("Brackets cmd:"+cmd);
var exePromise = nodeConnection.domains.ccext.execmd(cmd);
exePromise.fail(function (err) {
console.error("[brackets-ccext-node] failed to run ccext.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;
var reg1 = new RegExp("com.example.ext", "g");
str = str.replace(reg1, data.extid);
var reg2 = new RegExp("Extension-Name", "g");
str = str.replace(reg2, data.extname);
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.ccext.initialize();
promise.fail(function (err) {
console.error("[brackets-ccext-node] failed to run ccext.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-ccext-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-ccext-node] failed to load domain");
});
loadPromise.done(function () {
initNodeDomain();
});
});
}
function createPanel() {
ExtensionUtils.loadStyleSheet(module, "panel.css");
Dialogs.showModalDialogUsingTemplate(PanelTemplate);
$("#ccextSubmit").on("click", function (e) {
var data = {
extid : $("#ccext-id").val(),
extname : $("#ccext-extname").val()
/*
host: HOSTS[parseInt($("#ccext-host").val(), 10)],
width: $("#ccext-extwidth").val(),
height: $("#ccext-extheight").val(),
minwidth: $("#ccext-extminwidth").val(),
minheight: $("#ccext-extminheight").val(),
maxwidth: $("#ccext-extmaxwidth").val(),
maxheight: $("#ccext-extmaxheight").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(DEBUGMODE_ON_CMDNAME, DEBUGMODE_ON_CMDID, onMenuDebugModeOn);
function onMenuDebugModeOn(){
enableDebugging();
}
CommandManager.register(NEW_CCEXT_MENU_NAME, NEW_CCEXT_CMDID, onMenuCreateNewCCExt);
function onMenuCreateNewCCExt(){
createPanel();
}
var ccextMenu = Menus.getMenu(CCEXT_MENU_ID);
if (!ccextMenu) {
ccextMenu = Menus.addMenu(CCEXT_MENU_NAME, CCEXT_MENU_ID, Menus.LAST);
}
ccextMenu.addMenuItem(DEBUGMODE_ON_CMDID);
ccextMenu.addMenuItem(NEW_CCEXT_CMDID);
//ccextMenu.addMenuDivider(Menus.BEFORE, NEW_CCEXT_COMMAND_ID);
}
setupMenu();
});