UNPKG

1.74 kBJavaScriptView Raw
1"use strict";
2
3let fs = require('fs-extra');
4let path = require('path');
5let klawSync = require('klaw-sync');
6
7function cleanSourceMapRoot(mapRoot, sourcesRoot) {
8 klawSync(mapRoot, {filter: (item) => item.path.endsWith('.js.map')})
9 .map(f => f.path)
10 .forEach(fName => {
11 const sourceMap = fs.readJsonSync(fName);
12
13 // Get relative path from map file to source file
14 sourceMap.sources = sourceMap.sources.map(s => {
15 const sRel = path.relative(path.parse(fName).dir, path.resolve(path.join(sourcesRoot, s)));
16 return sRel;
17 });
18 delete sourceMap.sourceRoot;
19
20 fs.writeJsonSync(fName, sourceMap);
21 });
22}
23
24function copySources(rootDir, packageDir, ignoreMissing) {
25 // If we are ignoring missing directories, early return when source doesn't exist
26 if (!fs.existsSync(rootDir)) {
27 if (ignoreMissing) {
28 return;
29 } else {
30 throw "Source root dir does not exist!";
31 }
32 }
33 // Copy over the CommonJS files
34 fs.copySync(rootDir, packageDir);
35 fs.copySync('./LICENSE.txt', packageDir + 'LICENSE.txt');
36 fs.copySync('./README.md', packageDir + 'README.md');
37}
38
39// Create a file that exports the importTargets object
40function createImportTargets(importTargets, targetName, targetDirectory) {
41 const importMap = {};
42 for (const x in importTargets) {
43 importMap['rxjs/' + x] = ('rxjs-compat/' + targetName + importTargets[x]).replace(/\.js$/, '');
44 }
45
46 const outputData =
47`
48"use strict"
49
50var path = require('path');
51var dir = path.resolve(__dirname);
52
53module.exports = function() {
54 return ${JSON.stringify(importMap, null, 4)};
55}
56`
57
58 fs.outputFileSync(targetDirectory + 'path-mapping.js', outputData);
59}
60
61module.exports = {
62 copySources,
63 createImportTargets,
64 cleanSourceMapRoot
65}
\No newline at end of file