UNPKG

1.51 kBPlain TextView Raw
1import * as fs from "fs-extra";
2import * as path from "path";
3import {LocalUpdater} from "../builders/LocalUpdater";
4import {IProjectConfig} from "../commons/IProjectConfig";
5
6export async function localUpdateAsync(argv: { watch: boolean; config?: string }): Promise<void> {
7 process.env.NODE_ENV = "development";
8
9 let configFilePath = argv.config;
10 configFilePath = configFilePath ? path.resolve(process.cwd(), configFilePath)
11 : fs.existsSync(path.resolve(process.cwd(), "simplism.ts")) ? path.resolve(process.cwd(), "simplism.ts")
12 : fs.existsSync(path.resolve(process.cwd(), "simplism.js")) ? path.resolve(process.cwd(), "simplism.js")
13 : path.resolve(process.cwd(), "simplism.json");
14
15 if (path.extname(configFilePath) === ".ts") {
16 // tslint:disable-next-line
17 require("ts-node/register");
18 }
19
20 // tslint:disable-next-line:no-eval
21 const projectConfig = eval("require(configFilePath)") as IProjectConfig;
22
23 const promiseList: Promise<void>[] = [];
24 if (projectConfig.localDependencies) {
25 for (const packageName of Object.keys(projectConfig.localDependencies)) {
26 const packagePath = projectConfig.localDependencies[packageName];
27
28 if (fs.existsSync(packagePath)) {
29 promiseList.push(new LocalUpdater(packageName, packagePath).runAsync());
30 if (argv.watch) {
31 promiseList.push(new LocalUpdater(packageName, packagePath).runAsync(true));
32 }
33 }
34 }
35 }
36
37 await Promise.all(promiseList);
38}