doric cli mapping
This commit is contained in:
parent
d9eb9489b8
commit
3b67e5109f
@ -14,4 +14,14 @@ program
|
||||
.action(function () {
|
||||
require('./scripts/watcher')
|
||||
})
|
||||
program
|
||||
.command('build')
|
||||
.action(function () {
|
||||
require('./scripts/command').build()
|
||||
})
|
||||
program
|
||||
.command('clean')
|
||||
.action(function () {
|
||||
require('./scripts/command').clean()
|
||||
})
|
||||
program.parse(process.argv)
|
||||
|
21
doric-cli/package-lock.json
generated
21
doric-cli/package-lock.json
generated
@ -19,6 +19,11 @@
|
||||
"resolved": "https://registry.npm.taobao.org/acorn/download/acorn-6.2.1.tgz",
|
||||
"integrity": "sha1-PthCLW3sCeYSHMeoQ8qGozCoa1E="
|
||||
},
|
||||
"amdefine": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
|
||||
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
|
||||
},
|
||||
"anymatch": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npm.taobao.org/anymatch/download/anymatch-3.0.3.tgz",
|
||||
@ -265,6 +270,22 @@
|
||||
"rechoir": "^0.6.2"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
|
||||
"integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=",
|
||||
"requires": {
|
||||
"amdefine": ">=0.0.4"
|
||||
}
|
||||
},
|
||||
"source-map-merger": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/source-map-merger/-/source-map-merger-0.2.0.tgz",
|
||||
"integrity": "sha1-vJ2EQ1uYLA/WaywliFH4wGYgRCc=",
|
||||
"requires": {
|
||||
"source-map": "^0.4.0"
|
||||
}
|
||||
},
|
||||
"to-regex-range": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npm.taobao.org/to-regex-range/download/to-regex-range-5.0.1.tgz",
|
||||
|
@ -28,6 +28,7 @@
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"rollup": "^1.18.0",
|
||||
"shelljs": "^0.8.3",
|
||||
"source-map-merger": "^0.2.0",
|
||||
"typescript": "^3.5.3"
|
||||
}
|
||||
}
|
||||
|
51
doric-cli/scripts/command.js
Normal file
51
doric-cli/scripts/command.js
Normal file
@ -0,0 +1,51 @@
|
||||
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) {
|
||||
doMerge(startPath, files[i])
|
||||
};
|
||||
};
|
||||
};
|
||||
function doMerge(startPath, fileName) {
|
||||
// console.log('-- found: ', startPath, fileName);
|
||||
const filePath = fileName ? path.join(startPath, fileName) : startPath
|
||||
// console.log('-- merge: ', filePath.replace(/bundle\//, 'build/'), filePath)
|
||||
const mergedMap = SourceMapMerger.createMergedSourceMapFromFiles([
|
||||
filePath.replace(/bundle\//, 'build/'),
|
||||
filePath,
|
||||
], true);
|
||||
fs.writeFileSync(filePath, mergedMap)
|
||||
return mergedMap
|
||||
}
|
||||
function mergeMappings() {
|
||||
fromDir("bundle", ".map")
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
build: () => {
|
||||
exec('npm run build')
|
||||
console.log('Deal mapping')
|
||||
mergeMappings()
|
||||
},
|
||||
clean: () => {
|
||||
exec('npm run clean')
|
||||
},
|
||||
mergeMappings,
|
||||
doMerge,
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
const chokidar = require('chokidar')
|
||||
const ws = require('./server')
|
||||
const fs = require("fs")
|
||||
const doMerge = require("./command").doMerge
|
||||
|
||||
require('shelljs/global')
|
||||
|
||||
@ -13,13 +14,17 @@ setTimeout(() => {
|
||||
ignored: /(^|[\/\\])\../,
|
||||
}).on('change', (path) => {
|
||||
fs.readFile(path, 'utf-8', (error, data) => {
|
||||
if (!path.endsWith('.map')) {
|
||||
console.log('File change:', path)
|
||||
const sourceMap = doMerge(path + ".map")
|
||||
ws.connections.forEach(e => {
|
||||
e.sendText(JSON.stringify({
|
||||
script: data,
|
||||
script: fs.readFileSync(path),
|
||||
source: path.match(/[^/\\]*$/)[0],
|
||||
sourceMap,
|
||||
}))
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
}, 3000);
|
||||
|
Reference in New Issue
Block a user