/
index.ts
48 lines (42 loc) · 1.39 KB
/
index.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
import chalk from 'chalk';
import path from 'path';
import untildify from 'untildify';
import { buildSpecFromPath } from '../..';
import BaseCommand from '../../base-command';
declare const process: NodeJS.Process;
export default class Link extends BaseCommand {
async auth_required(): Promise<boolean> {
return false;
}
static description = 'Link a local component to the host to be used to power local deployments.';
static examples = [
'architect link',
'architect link -p ./mycomponent/architect.yml',
];
static flags = {
...BaseCommand.flags,
};
static args = [{
sensitive: false,
name: 'componentPath',
char: 'p',
description: 'The path of the component to link',
default: '.',
}];
async run(): Promise<void> {
const { args } = await this.parse(Link);
const component_path = path.resolve(untildify(args.componentPath));
// Try to load the component from the path to ensure it exists and is valid
try {
const component_config = buildSpecFromPath(component_path);
this.app.linkComponentPath(component_config.name, component_path);
this.log(`Successfully linked ${chalk.green(component_config.name)} to local system at ${chalk.green(component_path)}.`);
} catch (err: any) {
if (err.name === 'missing_config_file') {
this.log(chalk.red(err.message));
} else {
throw err;
}
}
}
}