@vxapp/wxss
Advanced tools
Comparing version 0.0.6 to 0.0.7
57
index.js
@@ -1,16 +0,53 @@ | ||
const fs = require('fs-extra'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const postcss = require('postcss'); | ||
const { promisify } = require('util'); | ||
const createResolver = require('@vxapp/resolve'); | ||
const wxss = (src, out, options = {}) => { | ||
const { plugins = [] } = options; | ||
const parser = postcss(plugins); | ||
return async (input, output) => { | ||
if(!fs.existsSync(input)) | ||
return console.error('[@vxapp/wxss] file does not exists:', input); | ||
const source = await fs.readFile(input); | ||
const result = await parser.process(source); | ||
fs.writeFile(output, result.css); | ||
const mkdir = promisify(fs.mkdir); | ||
const exists = promisify(fs.exists); | ||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
const ensureDir = async dir => { | ||
const paths = []; | ||
dir.split(path.sep).reduce((prev, cur) => { | ||
const result = path.join(prev, cur); | ||
paths.push(result); | ||
return result; | ||
}, path.sep); | ||
for(const cur of paths){ | ||
const isExists = await exists(cur); | ||
!isExists && await mkdir(cur); | ||
} | ||
}; | ||
const atImport = rewriter => { | ||
return root => { | ||
root.walkAtRules('import', rule => { | ||
rule.params = rewriter(JSON.parse(rule.params)); | ||
}); | ||
}; | ||
}; | ||
const wxss = options => { | ||
const resolve = createResolver(options); | ||
return atImport(name => { | ||
const info = resolve(name); | ||
wxss.compile(info); | ||
return `"${info.relative}"`; | ||
}); | ||
}; | ||
wxss.compile = async options => { | ||
const { current, source, target, plugins = [] } = options; | ||
const output = current.replace(source, target); | ||
const content = await readFile(current); | ||
const parse = postcss(plugins.concat(wxss(options))); | ||
const result = parse.process(content, { from: current, to: output }); | ||
await ensureDir(path.dirname(output)); | ||
await writeFile(output, result.css); | ||
console.log('[@vxapp/wxss] write file:', output); | ||
}; | ||
module.exports = wxss; |
{ | ||
"name": "@vxapp/wxss", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "wechat mini-program wxss parser", | ||
@@ -21,5 +21,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@vxapp/resolve": "^0.0.3", | ||
"postcss": "^7.0.6" | ||
}, | ||
"gitHead": "4e53073f3f30c345cf3abe8fcdb6a06ed295309f" | ||
"gitHead": "f6034eb2cc2bbb1eca2fc31a454507a843d57008" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4574
9
51
2
+ Added@vxapp/resolve@^0.0.3
+ Added@vxapp/resolve@0.0.3(transitive)