Skip to content

Commit 228508d

Browse files
author
Lucas Vogel
committed
fixes #10 | Create the command line interface with commanderjs and improved tests
1 parent d54e12f commit 228508d

File tree

9 files changed

+76
-14
lines changed

9 files changed

+76
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules
22
*.sublime-*
3-
dist
3+
test/dist
44
.tmp
55

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules

index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
var extendscriptr = require('commander');
3+
var packageJson = require('./package.json');
4+
var browserify = require('browserify');
5+
var prependify = require('prependify');
6+
var fs = require('fs');
7+
8+
extendscriptr
9+
.version(packageJson.version)
10+
.usage('[options]')
11+
.option('-s, --script <path>', 'The input file to compile into an executable extendscript')
12+
.option('-o, --output <path>', 'The path to the wished compiled output file')
13+
.option('-t, --target [targetApp]', 'The Adobe Application the script is intended for. i.e. InDesign [targetApp]')
14+
.parse(process.argv);
15+
16+
console.log('Running extendscriptr with following options:');
17+
extendscriptr.options.forEach(function(opt) {
18+
if (opt.long === '--version') return;
19+
var optionName = opt.long.replace('--', '');
20+
console.log(
21+
opt.long + ': ' +
22+
extendscriptr[optionName] +
23+
(opt.optional === 0 ? '' : ' (optional)')
24+
);
25+
});
26+
27+
var prototypePolyfills = fs.readFileSync('./node_modules/extendscript.prototypes/dist/extendscript.prototypes.0.0.5.jsx');
28+
var browserifyPlugins = [ [ prependify, prototypePolyfills ] ];
29+
30+
var adobeTarget = String(extendscriptr.target).toLowerCase();
31+
if ( adobeTarget &&
32+
(adobeTarget.indexOf('indesign') >= 0 ||
33+
adobeTarget.indexOf('photoshop') >= 0 ||
34+
adobeTarget.indexOf('illustrator') >= 0 ||
35+
adobeTarget.indexOf('aftereffects') >= 0)) {
36+
browserifyPlugins.push([ prependify, '#target ' + extendscriptr.target + '\n' ]);
37+
}
38+
39+
var b = browserify({
40+
entries: [ extendscriptr.script ],
41+
transform: 'babelify',
42+
plugin: browserifyPlugins
43+
});
44+
45+
b.bundle().pipe(fs.createWriteStream(extendscriptr.output));

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
2+
"bin": {
3+
"extendscriptr": "./index.js"
4+
},
25
"name": "extendscriptr",
36
"version": "1.0.0",
47
"description": "A node build configuration to develop extendScripts with es2015 javascript code",
58
"scripts": {
6-
"clean:temp": "rm -rf ./.tmp",
7-
"clean:dist": "rm -rf ./dist",
8-
"clean": "npm run clean:temp & npm run clean:dist ; mkdir dist & mkdir .tmp",
9-
"insert-polyfills": "cat ./node_modules/extendscript.prototypes/dist/extendscript.prototypes.0.0.5.jsx >> ./dist/output.js",
10-
"insert-bundle": "cat ./.tmp/script.js >> ./dist/output.js",
11-
"bundle": "browserify -e ./src/index.js -o .tmp/script.js -t [ babelify ]",
12-
"compile": "npm run clean ; npm run insert-polyfills ; npm run bundle ; npm run insert-bundle ; npm run clean:temp",
13-
"start": "npm run compile"
9+
"clean:temp": "rm -rf ./.tmp ; mkdir ./.tmp",
10+
"clean:dist": "rm -rf ./test/dist ; mkdir ./test/dist",
11+
"compile:test:illustrator": "node ./index.js -s test/src/illustrator.js -o test/dist/illustrator.js -t 'illustrator'",
12+
"compile:test:indesign": "node ./index.js -s test/src/indesign.js -o test/dist/indesign.js -t 'indesign'",
13+
"compile:test:aftereffects": "node ./index.js -s test/src/aftereffects.js -o test/dist/aftereffects.js -t 'aftereffects'",
14+
"compile:test:photoshop": "node ./index.js -s test/src/photoshop.js -o test/dist/photoshop.js -t 'photoshop'",
15+
"compile:test:all": "npm run compile:test:illustrator & npm run compile:test:indesign & npm run compile:test:aftereffects & npm run compile:test:photoshop",
16+
"test": "npm run clean:dist ; npm run compile:test:all ; npm run clean:temp"
1417
},
1518
"repository": {
1619
"type": "git",
@@ -43,6 +46,8 @@
4346
"babel-preset-es2015": "^6.6.0",
4447
"babelify": "^7.3.0",
4548
"browserify": "^13.0.0",
46-
"extendscript.prototypes": "0.0.5"
49+
"commander": "^2.9.0",
50+
"extendscript.prototypes": "0.0.5",
51+
"prependify": "^1.2.0"
4752
}
4853
}

test/src/aftereffects.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as lib from './libs/lib';
2+
3+
lib.write(`Hello World ${lib.calc()} ${lib.something}`);
4+

src/index.js renamed to test/src/illustrator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const doc = app.documents.add(null,width,height);
99
const m = 30;
1010
const path1 = doc.pathItems.add();
1111
path1.setEntirePath ([
12-
[m,m],
13-
[m,height-m],
14-
[width-m,height-m],
15-
[width-m,m]
12+
[m, m],
13+
[m, height - m],
14+
[width - m, height - m],
15+
[width - m, m]
1616
]);
1717

1818
const text1 = doc.textFrames.areaText( path1 );

test/src/indesign.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as lib from './libs/lib';
2+
3+
lib.write(`Hello World ${lib.calc()} ${lib.something}`);
File renamed without changes.

test/src/photoshop.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as lib from './libs/lib';
2+
3+
lib.write(`Hello World ${lib.calc()} ${lib.something}`);

0 commit comments

Comments
 (0)