forked from ReactiveX/rxjs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.make-helpers.js
65 lines (54 loc) · 1.7 KB
/
.make-helpers.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"use strict";
let fs = require('fs-extra');
let path = require('path');
let klawSync = require('klaw-sync');
function cleanSourceMapRoot(mapRoot, sourcesRoot) {
klawSync(mapRoot, {filter: (item) => item.path.endsWith('.js.map')})
.map(f => f.path)
.forEach(fName => {
const sourceMap = fs.readJsonSync(fName);
// Get relative path from map file to source file
sourceMap.sources = sourceMap.sources.map(s => {
const sRel = path.relative(path.parse(fName).dir, path.resolve(path.join(sourcesRoot, s)));
return sRel;
});
delete sourceMap.sourceRoot;
fs.writeJsonSync(fName, sourceMap);
});
}
function copySources(rootDir, packageDir, ignoreMissing) {
// If we are ignoring missing directories, early return when source doesn't exist
if (!fs.existsSync(rootDir)) {
if (ignoreMissing) {
return;
} else {
throw "Source root dir does not exist!";
}
}
// Copy over the CommonJS files
fs.copySync(rootDir, packageDir);
fs.copySync('./LICENSE.txt', packageDir + 'LICENSE.txt');
fs.copySync('./README.md', packageDir + 'README.md');
}
// Create a file that exports the importTargets object
function createImportTargets(importTargets, targetName, targetDirectory) {
const importMap = {};
for (const x in importTargets) {
importMap['rxjs/' + x] = ('rxjs-compat/' + targetName + importTargets[x]).replace(/\.js$/, '');
}
const outputData =
`
"use strict"
var path = require('path');
var dir = path.resolve(__dirname);
module.exports = function() {
return ${JSON.stringify(importMap, null, 4)};
}
`
fs.outputFileSync(targetDirectory + 'path-mapping.js', outputData);
}
module.exports = {
copySources,
createImportTargets,
cleanSourceMapRoot
}