1 | "use strict";
|
2 |
|
3 | let fs = require('fs-extra');
|
4 | let path = require('path');
|
5 | let klawSync = require('klaw-sync');
|
6 |
|
7 | function 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 |
|
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 |
|
24 | function copySources(rootDir, packageDir, ignoreMissing) {
|
25 |
|
26 | if (!fs.existsSync(rootDir)) {
|
27 | if (ignoreMissing) {
|
28 | return;
|
29 | } else {
|
30 | throw "Source root dir does not exist!";
|
31 | }
|
32 | }
|
33 |
|
34 | fs.copySync(rootDir, packageDir);
|
35 | fs.copySync('./LICENSE.txt', packageDir + 'LICENSE.txt');
|
36 | fs.copySync('./README.md', packageDir + 'README.md');
|
37 | }
|
38 |
|
39 |
|
40 | function 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 |
|
50 | var path = require('path');
|
51 | var dir = path.resolve(__dirname);
|
52 |
|
53 | module.exports = function() {
|
54 | return ${JSON.stringify(importMap, null, 4)};
|
55 | }
|
56 | `
|
57 |
|
58 | fs.outputFileSync(targetDirectory + 'path-mapping.js', outputData);
|
59 | }
|
60 |
|
61 | module.exports = {
|
62 | copySources,
|
63 | createImportTargets,
|
64 | cleanSourceMapRoot
|
65 | } |
\ | No newline at end of file |