UNPKG

2.46 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7const path_1 = require("path");
8
9const fs_extra_1 = require("fs-extra"); // eslint-disable-next-line no-warning-comments
10// TODO: assert on "guaranteed" packages and throw if not present
11
12
13function loadPaths(root, env, config, project) {
14 let sewingKit = path_1.resolve(__dirname, '../..');
15
16 if (path_1.basename(sewingKit) === 'lib') {
17 sewingKit = path_1.resolve(sewingKit, '..');
18 }
19
20 const pathsPlugin = config.for('paths');
21 const customPaths = pathsPlugin ? pathsPlugin.paths : {};
22 const appPath = customPaths.app || (project.isNode ? path_1.join(root, config.library ? 'src' : 'app') : path_1.join(root, 'app/ui'));
23 const buildPath = customPaths.build || defaultBuildDirectory(env, project, root);
24 const cachePath = customPaths.cache || (project.isRails ? path_1.join(root, 'tmp', 'cache', 'sewing-kit') : path_1.join(buildPath, 'cache'));
25 const rootTSConfig = path_1.join(root, 'tsconfig.json');
26 const tsConfig = env.match({
27 serviceWorker: pathIfExists(path_1.join(root, 'service-worker', 'tsconfig.json')) || rootTSConfig,
28 server: rootTSConfig,
29 client: rootTSConfig
30 });
31 return {
32 sewingKit,
33 sewingKitNodeModules: path_1.join(sewingKit, 'node_modules'),
34 root,
35 private: customPaths.private || path_1.join(root, '.sewing-kit'),
36 playground: customPaths.playground || path_1.join(root, 'playground'),
37 packages: customPaths.packages || pathIfExists(path_1.join(root, 'packages')),
38 nodeModules: customPaths.nodeModules || path_1.join(root, 'node_modules'),
39 app: appPath,
40 styles: customPaths.styles || path_1.join(appPath, 'styles'),
41 components: customPaths.components || path_1.join(appPath, 'components'),
42 sections: customPaths.sections || path_1.join(appPath, 'sections'),
43 build: buildPath,
44 cache: cachePath,
45 tests: customPaths.tests || path_1.join(root, 'tests'),
46 defaultPostCSSConfig: path_1.resolve(__dirname, 'postcss.config'),
47 tsConfig
48 };
49}
50
51exports.default = loadPaths;
52
53function pathIfExists(filepath) {
54 return fs_extra_1.existsSync(filepath) ? filepath : undefined;
55}
56
57function defaultBuildDirectory({
58 isDevelopment
59}, {
60 isRails
61}, root) {
62 if (isRails) {
63 if (isDevelopment) {
64 return path_1.join(root, 'tmp/sewing-kit');
65 } else {
66 return path_1.join(root, 'public', 'bundles');
67 }
68 } else {
69 return path_1.join(root, 'build');
70 }
71}
\No newline at end of file