forked from planttheidea/micro-memoize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes-to-mjs.js
39 lines (27 loc) · 1.05 KB
/
es-to-mjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const path = require('path');
const pkg = require('./package.json');
const SOURCE = path.join(__dirname, pkg.module);
const SOURCE_MAP = `${SOURCE}.map`;
const DESTINATION = path.join(__dirname, 'mjs', 'index.mjs');
const DESTINATION_MAP = `${DESTINATION}.map`;
function getFilename(filename) {
const split = filename.split('/');
return split[split.length - 1];
}
try {
if (!fs.existsSync(path.join(__dirname, 'mjs'))) {
fs.mkdirSync(path.join(__dirname, 'mjs'));
}
fs.copyFileSync(SOURCE, DESTINATION);
const contents = fs
.readFileSync(DESTINATION, { encoding: 'utf8' })
.replace(/\/\/# sourceMappingURL=(.*)/, (match, value) => match.replace(value, 'index.mjs.map'));
fs.writeFileSync(DESTINATION, contents, { encoding: 'utf8' });
console.log(`Copied ${getFilename(SOURCE)} to ${getFilename(DESTINATION)}`);
fs.copyFileSync(SOURCE_MAP, DESTINATION_MAP);
console.log(`Copied ${getFilename(SOURCE_MAP)} to ${getFilename(DESTINATION_MAP)}`);
} catch (error) {
console.error(error);
process.exit(1);
}