Skip to content

Commit d5dfa03

Browse files
committedMay 8, 2018
v2.8.0
1 parent ebf1d30 commit d5dfa03

File tree

2 files changed

+58
-48
lines changed

2 files changed

+58
-48
lines changed
 

‎index.js

+56-46
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,60 @@
1-
var gkaUtils = require('gka-utils'),
2-
writeSync = gkaUtils.file.writeSync;
1+
var fs = require('fs');
2+
var path = require('path');
3+
var gkaUtils = require('gka-utils');
34
var html = require("./lib/html");
45

5-
module.exports = function (data, opts, cb) {
6-
7-
var dir = opts.imgOutput;
8-
9-
function run(data, opts, key) {
10-
var name = (key? key + '-' : '') + 'gka',
11-
dataName = name + '-data.js',
12-
htmlName = name + '.html';
13-
14-
var prefix = opts.prefix,
15-
frameduration = opts.frameduration;
16-
17-
var frames = data.frames,
18-
frame = frames[0];
19-
20-
var _data = {};
21-
_data.file = frame.file;
22-
_data.w = frame.w;
23-
_data.h = frame.h;
24-
_data.sourceW = frame.sourceW;
25-
_data.sourceH = frame.sourceH;
26-
27-
_data.frames = frames.map(function(frame){
28-
return JSON.stringify([frame.x, frame.y, frame.width, frame.height, 0, (0-frame.offX), (0-frame.offY)])
29-
});
30-
31-
writeSync([dir, '..', dataName], `var data = ${gkaUtils.data.fixArrayString(JSON.stringify(_data, null, ' '))}`);
32-
writeSync([dir, '..', htmlName], html(data, opts, dataName));
33-
writeSync([dir, '..', "easeljs-NEXT.combined.js"], gkaUtils.file.readFileSync([__dirname, 'lib/easeljs-NEXT.combined.js']));
6+
module.exports = class CreatejsTemplatePlugin {
7+
constructor() {
348
}
35-
36-
run(data, opts);
37-
38-
// 对每个子目录都进行处理
39-
gkaUtils._.effectSubFolderSync(run, data, opts);
40-
41-
cb && cb();
42-
}
43-
44-
module.exports.config = function(opts) {
45-
// console.log(opts)
46-
return {
47-
crop: 'any',
48-
sprites: true,
9+
apply(compiler) {
10+
compiler.hooks.on('templateOptions', (context, next) => {
11+
context.options.sprites = true;
12+
context.options.split = false;
13+
context.options.diff = false;
14+
next(context);
15+
})
16+
17+
compiler.hooks.on('template', (context, next) => {
18+
const {
19+
options,
20+
data,
21+
} = context;
22+
23+
const dir = options.imgOutput;
24+
25+
function run(data, opts, key) {
26+
var name = (key? key + '-' : '') + 'gka',
27+
dataName = name + '-data.js',
28+
htmlName = name + '.html';
29+
30+
var prefix = opts.prefix,
31+
frameduration = opts.frameduration;
32+
33+
var frames = data.frames,
34+
frame = frames[0];
35+
36+
var _data = {};
37+
_data.file = frame.file;
38+
_data.w = frame.w;
39+
_data.h = frame.h;
40+
_data.sourceW = frame.sourceW;
41+
_data.sourceH = frame.sourceH;
42+
43+
_data.frames = frames.map(function(frame){
44+
return JSON.stringify([frame.x, frame.y, frame.width, frame.height, 0, (0-frame.offX), (0-frame.offY)])
45+
});
46+
47+
context.assets[dataName] = `var data = ${gkaUtils.data.fixArrayString(JSON.stringify(_data, null, ' '))}`;
48+
context.assets[htmlName] = html(data, opts, dataName);
49+
context.assets['easeljs-NEXT.combined.js'] = fs.readFileSync(path.join(__dirname, 'lib/easeljs-NEXT.combined.js'), 'utf8');
50+
}
51+
52+
run(data[0], options);
53+
54+
// 对每个子目录都进行处理
55+
gkaUtils._.effectSubFolderSync(run, data[0], options);
56+
57+
next(context);
58+
})
4959
}
50-
};
60+
}

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gka-tpl-createjs",
3-
"version": "1.2.1",
3+
"version": "2.8.0",
44
"description": "gka template for createjs",
55
"main": "index.js",
66
"scripts": {},
@@ -20,6 +20,6 @@
2020
"author": "joeyguo",
2121
"license": "MIT",
2222
"dependencies": {
23-
"gka-utils": "^0.0.3"
23+
"gka-utils": "^2.8.0"
2424
}
2525
}

0 commit comments

Comments
 (0)
Please sign in to comment.