Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix private-plugin path & __COMMON_STYLESHEETS__ import #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
node_modules/
package-lock.json
/.idea/

*.wxapkg
decrypted/
1 change: 1 addition & 0 deletions wuLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function mkdirs(dir, cb) {
}

function save(name, content) {
name = name.replace(/plugin-private:/g, '__plugin__');
ioEvent.encount();
mkdirs(path.dirname(name), () => ioLimit.runWithCb(fs.writeFile.bind(fs), name, content, err => {
if (err) throw Error("Save file error: " + err);
Expand Down
29 changes: 23 additions & 6 deletions wuWxss.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,29 @@ function doWxss(dir, cb, mainDir, nowDir) {
//remove setCssToHead function
mainCode = mainCode.replace('var setCssToHead = function', 'var setCssToHead2 = function');

code = code.slice(code.lastIndexOf('var setCssToHead = function(file, _xcInvalid'));
code = code.slice(code.lastIndexOf('\nvar _C= ') + 1);

code = code.slice(0, code.indexOf('\n'));
let vm = new VM({sandbox: {}});
pureData = vm.run(code + "\n_C");
let COMMON_STYLESHEETS = code.slice(
code.lastIndexOf("\nvar __COMMON_STYLESHEETS__") + 1
);
COMMON_STYLESHEETS = COMMON_STYLESHEETS.slice(
0,
COMMON_STYLESHEETS.lastIndexOf(
"\nvar setCssToHead = function(file, _xcInvalid"
)
);

code = code.slice(
code.lastIndexOf("var setCssToHead = function(file, _xcInvalid")
);
code = code.slice(
Math.max(
code.lastIndexOf("\nvar _C="),
code.lastIndexOf("\nvar _C =")
) + 1
);

code = code.slice(0, code.indexOf("\n"));
let vm = new VM({ sandbox: {} });
pureData = vm.run(COMMON_STYLESHEETS + "\n" + code + "\n_C");

console.log("Guess wxss(first turn)...");
preRun(dir, frameFile, mainCode, files, () => {
Expand Down
Loading