-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlink.ts
55 lines (48 loc) · 1.35 KB
/
link.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Flags } from '@oclif/core';
import chalk from 'chalk';
import { WithProjects } from '../base-commands/WithProjects.js';
import { SymlinkManager } from '../utils/symlinks.js';
export default class Link extends WithProjects<typeof Link> {
static description =
'Creates symlinks in the given wp-content directory for the project(s) in this monorepo.';
static flags = {
'wp-content-dir': Flags.string({
char: 'd',
description: 'Path to the WordPress content directory.',
env: 'WP_CONTENT_DIR',
default: '',
}),
};
static args = {
...WithProjects.args,
};
symlinkManager = new SymlinkManager();
assertArgs() {
if (!this.flags['wp-content-dir']) {
throw new Error(
'Please provide a valid WordPress content directory.\n\nYou can set it using the --wp-content-dir option or the WP_CONTENT_DIR environment variable.',
);
}
super.assertArgs();
}
public async run(): Promise<void> {
try {
for (const [name, project] of this.projects) {
const symlinkPath = this.wpMonorepo.getSymlinkPath(
project,
this.flags['wp-content-dir'],
);
const result = this.symlinkManager.createSymlink({
symlinkPath,
realPath: project.dir,
});
if (result) {
this.log(result);
}
}
} catch (error) {
this.log(chalk.red((error as { message: string }).message));
process.exitCode = 1;
}
}
}