UNPKG

5.71 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14var Path = require("path");
15var utils_1 = require("./utils");
16/**
17 It is important to use absolute paths and not relative paths since some helpers
18 are distributed over several processes whose execution path is not always the same,
19 therefore this module was created.
20 */
21var cache = {};
22var resolve = Path.resolve.bind(Path);
23var ascii = resolveTree(resolve(__dirname, 'ascii'), {
24 views: resolve(__dirname, 'ascii/views'),
25});
26var renderer = resolveTree(resolve(__dirname, 'renderer'), {
27 helpers: resolve(__dirname, 'renderer/helpers'),
28 templates: resolve(__dirname, 'renderer/templates'),
29});
30var translator = resolveTree(resolve(__dirname, 'translator'), {
31 translation: resolve(__dirname, 'translator/translation'),
32 locales: resolve(__dirname, 'translator/locales'),
33});
34var tortilla = resolveTree(resolve(__dirname, '..'), {
35 dump: resolve(__dirname, 'dump.js'),
36 editor: resolve(__dirname, 'editor.js'),
37 essentials: resolve(__dirname, 'essentials.js'),
38 git: resolve(__dirname, 'git.js'),
39 initializer: resolve(__dirname, 'initializer.js'),
40 localCache: resolve(__dirname, 'local-cache.js'),
41 localStorage: resolve(__dirname, 'local-storage.js'),
42 manual: resolve(__dirname, 'manual.js'),
43 package: resolve(__dirname, 'package.js'),
44 paths: resolve(__dirname, 'paths.js'),
45 rebase: resolve(__dirname, 'rebase.js'),
46 release: resolve(__dirname, 'release.js'),
47 step: resolve(__dirname, 'step.js'),
48 submodule: resolve(__dirname, 'submodule.js'),
49 utils: resolve(__dirname, 'utils.js'),
50 skeleton: resolve(__dirname, 'skeleton.tar'),
51 hooks: resolve(__dirname, 'hooks'),
52 ascii: ascii,
53 renderer: renderer,
54 translator: translator,
55});
56var cli = resolveTree(resolve(__dirname, '../cli'), {
57 tortilla: resolve(__dirname, 'cli/tortilla.js'),
58 tortillaManual: resolve(__dirname, 'cli/tortilla-manual.js'),
59 tortillaRelease: resolve(__dirname, 'cli/tortilla-release.js'),
60 tortillaStep: resolve(__dirname, 'cli/tortilla-step.js'),
61 tortillaStrict: resolve(__dirname, 'cli/tortilla-strict.js'),
62 tortillaSubmodule: resolve(__dirname, 'cli/tortilla-submodule.js'),
63});
64// Makes the root path available in the branches object using a 'resolve()' method
65// e.g. ('foo', { bar: 'bar' }) -> { resolve() -> 'foo', bar: 'bar' }
66function resolveTree(root, branches) {
67 branches = branches || {};
68 return Object.keys(branches).reduce(function (tree, name) {
69 tree[name] = branches[name];
70 return tree;
71 }, {
72 resolve: Path.resolve.bind(Path, root),
73 });
74}
75// Resolves a bunch of paths to a given tortilla project path
76function resolveProject(cwd) {
77 if (!cwd) {
78 throw TypeError('A project path must be provided');
79 }
80 if (!process.env.TORTILLA_CACHE_DISABLED && cache[cwd]) {
81 return cache[cwd];
82 }
83 var gitHeads = resolveTree(resolve(cwd, '.git/HEAD'), {
84 cherryPick: resolve(cwd, '.git/CHERRY_PICK_HEAD'),
85 orig: resolve(cwd, '.git/ORIG_HEAD'),
86 revert: resolve(cwd, '.git/REVERT_HEAD'),
87 });
88 var gitMessages = {
89 commit: resolve(cwd, '.git/COMMIT_EDITMSG'),
90 merge: resolve(cwd, '.git/MERGE_MSG'),
91 squash: resolve(cwd, '.git/SQUASH_MSG'),
92 };
93 var gitRefs = resolveTree(resolve(cwd, '.git/refs'), {
94 heads: resolve(cwd, '.git/refs/heads'),
95 remotes: resolve(cwd, '.git/refs/remotes'),
96 tags: resolve(cwd, '.git/refs/tags'),
97 });
98 var git = resolveTree(resolve(cwd, '.git'), {
99 ignore: resolve(cwd, '.gitignore'),
100 hooks: resolve(cwd, '.git/hooks'),
101 rebaseApply: resolve(cwd, '.git/rebase-apply'),
102 rebaseMerge: resolve(cwd, '.git/rebase-merge'),
103 modules: resolve(cwd, '.git/modules'),
104 heads: gitHeads,
105 messages: gitMessages,
106 refs: gitRefs,
107 });
108 var npm = {
109 ignore: resolve(cwd, '.npmignore'),
110 package: resolve(cwd, 'package.json'),
111 modules: resolve(cwd, 'node_modules'),
112 };
113 var manuals = resolveTree(resolve(cwd, '.tortilla/manuals'), {
114 templates: resolve(cwd, '.tortilla/manuals/templates'),
115 views: resolve(cwd, '.tortilla/manuals/views'),
116 });
117 var r = cache[cwd] = resolveTree(cwd, {
118 tortillaDir: resolve(cwd, '.tortilla'),
119 config: resolve(cwd, '.tortilla/config.js'),
120 locales: resolve(cwd, '.tortilla/locales'),
121 readme: resolve(cwd, 'README.md'),
122 renovate: resolve(cwd, 'renovate.json'),
123 storage: resolve(cwd, '.git/.tortilla'),
124 gitModules: resolve(cwd, '.gitmodules'),
125 travis: resolve(cwd, '.travis.yml'),
126 manuals: manuals,
127 tortilla: tortilla,
128 cli: cli,
129 git: git,
130 npm: npm,
131 resolveTree: resolveTree,
132 resolveProject: resolveProject,
133 });
134 return r;
135}
136exports.resolveProject = resolveProject;
137// Clone is necessary otherwise the original cache might be accidentally modified
138exports.Paths = __assign({}, resolveProject(utils_1.Utils.cwd()));
139// The same instance of the exported Paths module should reference different values
140utils_1.Utils.on('cwdChange', function (cwd) {
141 Object.assign(exports.Paths, resolveProject(cwd));
142});
143//# sourceMappingURL=paths.js.map
\No newline at end of file