UNPKG

2.01 kBJavaScriptView Raw
1"use strict";
2
3var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) {
6 try {
7 step(generator.next(value));
8 } catch (e) {
9 reject(e);
10 }
11 }
12
13 function rejected(value) {
14 try {
15 step(generator["throw"](value));
16 } catch (e) {
17 reject(e);
18 }
19 }
20
21 function step(result) {
22 result.done ? resolve(result.value) : new P(function (resolve) {
23 resolve(result.value);
24 }).then(fulfilled, rejected);
25 }
26
27 step((generator = generator.apply(thisArg, _arguments || [])).next());
28 });
29};
30
31Object.defineProperty(exports, "__esModule", {
32 value: true
33});
34
35const env_1 = require("../env");
36
37const config_1 = require("./config");
38
39exports.Config = config_1.Config;
40
41const project_1 = require("./project");
42
43exports.Project = project_1.Project;
44
45const paths_1 = require("./paths");
46
47class Workspace {
48 constructor(root, env, project, paths, config) {
49 this.root = root;
50 this.env = env;
51 this.project = project;
52 this.paths = paths;
53 this.config = config;
54 }
55
56 get name() {
57 return this.config.name;
58 }
59
60 duplicate(env = this.env) {
61 return new Workspace(this.root, env, this.project, this.paths, this.config);
62 }
63
64}
65
66exports.Workspace = Workspace;
67
68function loadWorkspace(env = new env_1.default({
69 target: 'client',
70 mode: 'development'
71}), runner, {
72 config: configPath
73} = {}) {
74 return __awaiter(this, void 0, void 0, function* () {
75 const root = process.cwd();
76
77 try {
78 const project = yield project_1.default(root);
79 const config = yield config_1.default(configPath, env, project, runner);
80 const paths = paths_1.default(root, env, config, project);
81 return new Workspace(root, env, project, paths, config);
82 } catch (error) {
83 runner.logger.error(error);
84 return runner.fail();
85 }
86 });
87}
88
89exports.default = loadWorkspace;
\No newline at end of file