Commit 7f47b3d7 authored by rockyl's avatar rockyl

init

parent e301b761
{"id":"svga","url":"svga.bbb584f45f3ee647d0611653cb854c5d5bb8fb47.js"} {"id":"svga","url":"svga.min.7c72732a9d648931449e0a98ee3974bf1cebf067.js","url_dbg":"svga.cfb325090b121cc3241616b34fca39c0100f4eab.js"}
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"dts-bundle": "^0.7.3",
"glob": "^7.1.6", "glob": "^7.1.6",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-node-resolve": "^5.2.0",
...@@ -12,21 +11,25 @@ ...@@ -12,21 +11,25 @@
"rollup-plugin-typescript": "^1.0.1", "rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-typescript2": "^0.25.2", "rollup-plugin-typescript2": "^0.25.2",
"rollup-plugin-uglify": "^6.0.3", "rollup-plugin-uglify": "^6.0.3",
"typescript": "^2.7.2" "typescript": "^2.7.2",
"dts-bundle-generator": "^4.3.0"
}, },
"dependencies": { "dependencies": {
"protobufjs": "^6.8.8", "protobufjs": "^6.8.8",
"tslib": "^1.10.0", "tslib": "^1.10.0",
"typescript": "^2.7.2" "typescript": "^2.7.2"
}, },
"scripts": { "scripts": {
"dev": "rollup -c -m -w", "dev": "rollup -c -m -w",
"declare": "node scripts/declare.js src/svga/index.ts", "build": "rollup -c -o dist/svga.js",
"rollup": "rollup -c -o dist/svga.js", "build:prod": "rollup -c -o dist/svga.min.js --environment BUILD:production",
"rollup:prod": "rollup -c -o dist/svga.js --environment BUILD:production", "preprocess:prod": "node scripts/pre-process.js svga dist/svga.min.js prod",
"rollup:debug": "rollup -c -m ", "preprocess:debug": "node scripts/pre-process.js svga dist/svga.js",
"preprocess": "node scripts/pre-process.js svga dist/svga.js", "pack:prod": "yarn build:prod && yarn preprocess:prod",
"build": "rm -rf dist&&yarn rollup:prod && yarn preprocess && ali-oss-publish -c oss.config.js -e dist", "pack:debug": "yarn build && yarn preprocess:debug",
"build:debug": "rm -rf dist&&yarn rollup && yarn preprocess && ali-oss-publish -c oss.config.js -e dist" "upload": "ali-oss-publish -c oss.config.js -e dist",
"publish": "rm -rf dist && yarn pack:debug && yarn pack:prod && yarn upload",
"token": "uglifyjs -m -c -o px-token.min.js px-token.js",
"dts": "dts-bundle-generator -o types.d.ts src/index.ts"
} }
} }
...@@ -6,7 +6,7 @@ const crypto = require('crypto'); ...@@ -6,7 +6,7 @@ const crypto = require('crypto');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const [_, __, id, fileName] = process.argv; const [_, __, id, fileName, isProd] = process.argv;
const stream = fs.createReadStream(fileName); const stream = fs.createReadStream(fileName);
const fsHash = crypto.createHash('sha1'); const fsHash = crypto.createHash('sha1');
...@@ -26,10 +26,16 @@ function loadComplete(md5) { ...@@ -26,10 +26,16 @@ function loadComplete(md5) {
const newFileName = fileName.substr(0, extIndex + 1) + md5 + fileName.substr(extIndex); const newFileName = fileName.substr(0, extIndex + 1) + md5 + fileName.substr(extIndex);
fs.renameSync(fileName, newFileName); fs.renameSync(fileName, newFileName);
let manifest = { let manifest;
id, if (fs.existsSync('manifest.json')) {
url: path.basename(newFileName), manifest = JSON.parse(fs.readFileSync('manifest.json', 'utf-8'));
}; } else {
manifest = {
id,
};
}
manifest[isProd ? 'url' : 'url_dbg'] = path.basename(newFileName);
fs.writeFileSync('manifest.json', JSON.stringify(manifest)); fs.writeFileSync('manifest.json', JSON.stringify(manifest));
} }
...@@ -31,18 +31,13 @@ export class Svga extends MovieClip { ...@@ -31,18 +31,13 @@ export class Svga extends MovieClip {
if (value.indexOf(assetScheme) === 0) { if (value.indexOf(assetScheme) === 0) {
let uuid = value.replace(assetScheme, ''); let uuid = value.replace(assetScheme, '');
let mv = engine.globalLoader.get(uuid); let mv = engine.globalLoader.get(uuid);
engine.globalLoader['loadSvga'](engine["assetResolver"](uuid)) this.init(mv);
.then(mv => { this._dataInitialized();
this.children.length=0
this.init(mv);
this._dataInitialized();
this.mouseChildren=false;
});
needLoad = false; needLoad = false;
} }
} }
if(needLoad){ if(this._source && needLoad){
engine.globalLoader['loadSvga'](value) engine.globalLoader['loadSvga'](value)
.then(mv => { .then(mv => {
this.init(mv); this.init(mv);
...@@ -59,6 +54,31 @@ export class Svga extends MovieClip { ...@@ -59,6 +54,31 @@ export class Svga extends MovieClip {
} }
}) })
} }
clone(withEvents?: boolean, withScripts?: boolean): any {
let target = new Svga();
const originConfig = this['__originConfig'];
const {name, properties, events, scripts} = originConfig;
target.name = name;
target['__originConfig'] = originConfig;
engine.injectProperties(target, properties);
if (withScripts) {
if (scripts && scripts.length > 0) {
for (let scriptConfig of scripts) {
engine.instantiateScript(target, scriptConfig);
}
}
}
if (withEvents) {
if (events) {
target['eventsProxy'].start(events);
}
}
return target;
}
} }
engine.registerNodeType('svga', Svga); engine.registerNodeType('svga', Svga);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment