Skip to content

Commit 6a8c47d

Browse files
author
bastieneichenberger
committed
add shell function to indesign
1 parent 6e71351 commit 6a8c47d

File tree

6 files changed

+97
-40
lines changed

6 files changed

+97
-40
lines changed

lib/helper/config/all_helper_modules.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
//@include "../log/log.jsx"
88

9+
//@include "../shell/shell.jsx"
10+
911
//@include "../ui/ui.jsx"
1012

1113
//@include "../utils/array.jsx"

lib/helper/shell/shell.jsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Module with Utils functions
3+
* @namespace Utils
4+
* @memberOf H
5+
* @author Bastien Eichenberger
6+
*/
7+
H.Shell = (function (my) {
8+
9+
10+
/**
11+
* Function to execute a shell string
12+
* @supported for the moment this function works only on mac with InDesign
13+
* @todo add support for windows, Photoshop, Illustrator using batch files
14+
* @param shell_function
15+
* @returns {*|null}
16+
*/
17+
my.execute = function (shell_function) {
18+
var result, apple_script;
19+
20+
if ($.os.contains('Windows')) {
21+
throw {
22+
name: 'UnimplementedMethodError',
23+
message: 'this function do not work on Windows',
24+
fileName: $.fileName,
25+
line: $.line
26+
};
27+
}
28+
29+
if (app.name.indexOf('InDesign') > -1) {
30+
apple_script = 'do shell script "' + shell_function + '"';
31+
try {
32+
result = app.doScript(apple_script, ScriptLanguage.applescriptLanguage);
33+
}
34+
catch (ex) {
35+
throw {
36+
name: 'Error',
37+
message: 'the shell function '+ shell_function + ' contains an error: ' + ex.message,
38+
fileName: $.fileName,
39+
line: $.line
40+
};
41+
}
42+
}
43+
else {
44+
throw {
45+
name: 'UnimplementedMethodError',
46+
message: 'this function works only with InDesign',
47+
fileName: $.fileName,
48+
line: $.line
49+
};
50+
}
51+
52+
return result || null;
53+
}
54+
55+
return my;
56+
57+
})(H.Shell || {});

tests/Gruntfile.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,33 +94,22 @@ module.exports = function (grunt) {
9494
args: [path.resolve('test/results')]
9595
},
9696
src: 'test/fixtures/indesign/document/test_document.jsx'
97-
}
98-
},
99-
100-
illustrator: {
101-
test_log: {
102-
options: {
103-
args: [path.resolve('test/log')]
104-
},
105-
src: 'test/fixtures/helper/log/test_log.jsx'
10697
},
107-
test_gateway: {
98+
test_grep: {
10899
options: {
109-
args: [path.resolve('test/results/tests.xml')]
100+
args: [path.resolve('test/results')]
110101
},
111-
src: 'test/fixtures/helper/gateway/test_gateway.jsx'
102+
src: 'test/fixtures/indesign/document/test_grep.jsx'
112103
},
113-
test_array: {
104+
test_shell: {
114105
options: {
115-
args: [path.resolve('test/results/tests.xml')]
106+
args: [path.resolve('test/results/tests.xml'), path.resolve('test/results')]
116107
},
117-
src: ['test/fixtures/helper/utils/test_array.jsx']
108+
src: ['test/fixtures/helper/shell/test_shell.jsx']
118109
}
119110
},
120111

121-
/**
122-
* @todo it would be better to write a function to execute a jsx file in all apps
123-
all_apps: {
112+
illustrator: {
124113
test_log: {
125114
options: {
126115
args: [path.resolve('test/log')]
@@ -139,7 +128,7 @@ module.exports = function (grunt) {
139128
},
140129
src: ['test/fixtures/helper/utils/test_array.jsx']
141130
}
142-
},*/
131+
},
143132

144133
// Units tests.
145134
nodeunit: {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(function (xml_file_path, results_folder) {
2+
3+
try {
4+
//@include "../../../../../lib/helper/helper-lib.jsx"
5+
H.Config.init();
6+
7+
// shell string to build a ZIP zip -r output.zip source
8+
var shell_string = 'zip -r %s %s';
9+
shell_string = shell_string.printf(results_folder + '/output.zip', results_folder);
10+
11+
H.Shell.execute(shell_string);
12+
13+
14+
}
15+
catch (ex) {
16+
alert('file: ' + ex.fileName + '\n message: ' + ex.message + '\n line: ' + ex.line);
17+
}
18+
19+
20+
}).apply(this, [].slice.apply(this.arguments));

tests/test/fixtures/indesign/document/test_grep.jsx

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

tests/test/tests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ exports.indesign_lib = {
6464
var is_export_as_jpg = grunt.file.exists('test/results/test_jpg_indesign.jpg');
6565
test.ok(is_export_as_jpg);
6666
test.done();
67+
},
68+
save_indesign_document: function (test) {
69+
var is_export_as_indd = grunt.file.exists('test/results/document_result.indd');
70+
test.ok(is_export_as_indd);
71+
test.done();
72+
},
73+
zip_with_shell: function (test) {
74+
var is_zip_shell = grunt.file.exists('test/results/output.zip');
75+
test.ok(is_zip_shell);
76+
test.done();
6777
}
6878
};
6979

0 commit comments

Comments
 (0)