This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-cli/scripts/command.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-15 10:51:58 +08:00
require('shelljs/global')
const fs = require("fs")
const path = require("path")
const SourceMapMerger = require("source-map-merger");
function fromDir(startPath, filter) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return;
}
const files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
const filename = path.join(startPath, files[i]);
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
fromDir(filename, filter);
}
else if (filename.indexOf(filter) >= 0) {
2019-11-29 15:07:32 +08:00
try {
doMerge(startPath, files[i])
} catch (e) {
console.log(e)
}
2019-08-15 10:51:58 +08:00
};
};
};
function doMerge(startPath, fileName) {
const filePath = fileName ? path.join(startPath, fileName) : startPath
2020-03-13 15:22:19 +08:00
if (filePath.indexOf('.es5.') >= 0){
return
}
2021-02-05 16:35:52 +08:00
console.log('File changed:', filePath)
2019-08-15 10:51:58 +08:00
const mergedMap = SourceMapMerger.createMergedSourceMapFromFiles([
filePath.replace(/bundle\//, 'build/'),
filePath,
], true);
fs.writeFileSync(filePath, mergedMap)
return mergedMap
}
2021-02-05 16:35:52 +08:00
2019-08-15 10:51:58 +08:00
function mergeMappings() {
fromDir("bundle", ".map")
}
module.exports = {
build: () => {
exec('npm run build')
console.log('Deal mapping')
mergeMappings()
},
clean: () => {
exec('npm run clean')
},
mergeMappings,
doMerge,
}