1 | ;
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const BroccoliPlugin = require("broccoli-plugin");
|
11 | const path = require("path");
|
12 | const fs = __importStar(require("fs-extra"));
|
13 | const tmp = require("tmp");
|
14 | /* eslint-disable-next-line @typescript-eslint/no-var-requires */
|
15 | const ensureSymlink = require("ensure-symlink");
|
16 | /**
|
17 | * Creates symlinks to the source files specified.
|
18 | *
|
19 | * BroccoliSymbolicLinker
|
20 | */
|
21 | class BroccoliSymbolicLinker extends BroccoliPlugin {
|
22 | constructor(fileMap, options = {}) {
|
23 | let pluginOpts = { needsCache: false };
|
24 | Object.assign(pluginOpts, options);
|
25 | super([], pluginOpts);
|
26 | this.files = Object.assign({}, fileMap);
|
27 | }
|
28 | reset(fileMap) {
|
29 | this.files = Object.assign({}, fileMap);
|
30 | }
|
31 | /**
|
32 | * Record that a symlink should be created from src to dest.
|
33 | *
|
34 | * This can be called many times before the build method is invoked.
|
35 | * Calling it after will not have an effect until the next time build() is
|
36 | * invoked.
|
37 | *
|
38 | * @param src The file that should be symlinked into the tree.
|
39 | * @param dest the relative path from the tree's root to the location of the
|
40 | * symlink. the filename does not have to be the same.
|
41 | * @returns the absolute path to the location where the symlink will be created.
|
42 | */
|
43 | // eslint-disable-next-line @typescript-eslint/camelcase
|
44 | ln_s(src, dest) {
|
45 | // console.log(`will link ${src} to ${dest}`);
|
46 | this.files[dest] = src;
|
47 | let tartgetDir = this.outputPath;
|
48 | if (!tartgetDir) {
|
49 | this.fakeOutputPath = this.fakeOutputPath || tmp.dirSync().name;
|
50 | tartgetDir = this.fakeOutputPath;
|
51 | }
|
52 | return path.join(tartgetDir, dest);
|
53 | }
|
54 | /**
|
55 | * Returns the number of symlinks that will be created.
|
56 | */
|
57 | numberOfFiles() {
|
58 | return Object.keys(this.files).length;
|
59 | }
|
60 | /**
|
61 | * Create the symlinks. Directories to them will be created as necessary.
|
62 | */
|
63 | build() {
|
64 | // eslint-disable-next-line no-console
|
65 | // console.log(`Building ${this.numberOfFiles()} symlinks for ${this["_annotation"]}.`);
|
66 | for (let dest of Object.keys(this.files)) {
|
67 | let src = this.files[dest];
|
68 | // console.log(`linking ${src} to ${dest}`);
|
69 | dest = path.join(this.outputPath, dest);
|
70 | let dir = path.dirname(dest);
|
71 | fs.mkdirpSync(dir);
|
72 | ensureSymlink(src, dest);
|
73 | }
|
74 | }
|
75 | /**
|
76 | * Output the symlinks that will be created for debugging.
|
77 | */
|
78 | debug() {
|
79 | return Object.keys(this.files).join("\n");
|
80 | }
|
81 | }
|
82 | exports.BroccoliSymbolicLinker = BroccoliSymbolicLinker;
|
83 | //# sourceMappingURL=broccoli-ln-s.js.map |
\ | No newline at end of file |