-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathembed.ts
127 lines (108 loc) · 3.54 KB
/
embed.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { ICommand, ICommandParameter } from "../../common/definitions/commands";
import { injector } from "../../common/yok";
import { PrepareCommand } from "../prepare";
import { PrepareController } from "../../controllers/prepare-controller";
import { IOptions, IPlatformValidationService } from "../../declarations";
import { IProjectConfigService, IProjectData } from "../../definitions/project";
import { IPlatformsDataService } from "../../definitions/platform";
import { PrepareDataService } from "../../services/prepare-data-service";
import { IMigrateController } from "../../definitions/migrate";
import { resolve } from "path";
import { IFileSystem } from "../../common/declarations";
import { color } from "../../color";
export class EmbedCommand extends PrepareCommand implements ICommand {
constructor(
public $options: IOptions,
public $prepareController: PrepareController,
public $platformValidationService: IPlatformValidationService,
public $projectData: IProjectData,
public $platformCommandParameter: ICommandParameter,
public $platformsDataService: IPlatformsDataService,
public $prepareDataService: PrepareDataService,
public $migrateController: IMigrateController,
private $logger: ILogger,
private $fs: IFileSystem,
private $projectConfigService: IProjectConfigService
) {
super(
$options,
$prepareController,
$platformValidationService,
$projectData,
$platformCommandParameter,
$platformsDataService,
$prepareDataService,
$migrateController
);
}
private resolveHostProjectPath(hostProjectPath: string): string {
if (hostProjectPath.charAt(0) === ".") {
// resolve relative to the project dir
const projectDir = this.$projectData.projectDir;
return resolve(projectDir, hostProjectPath);
}
return resolve(hostProjectPath);
}
public async execute(args: string[]): Promise<void> {
const hostProjectPath = args[1];
const resolvedHostProjectPath =
this.resolveHostProjectPath(hostProjectPath);
if (!this.$fs.exists(resolvedHostProjectPath)) {
this.$logger.error(
`The host project path ${color.yellow(
hostProjectPath
)} (resolved to: ${color.yellow.dim(
resolvedHostProjectPath
)}) does not exist.`
);
return;
}
this.$options["hostProjectPath"] = resolvedHostProjectPath;
if (args.length > 2) {
this.$options["hostProjectModuleName"] = args[2];
}
return super.execute(args);
}
public async canExecute(args: string[]): Promise<boolean> {
const canSuperExecute = await super.canExecute(args);
if (!canSuperExecute) {
return false;
}
// args[0] is the platform
// args[1] is the path to the host project
// args[2] is the host project module name
const platform = args[0].toLowerCase();
// also allow these to be set in the nativescript.config.ts
if (!args[1]) {
const hostProjectPath = this.getEmbedConfigForKey(
"hostProjectPath",
platform
);
if (hostProjectPath) {
args[1] = hostProjectPath;
}
}
if (!args[2]) {
const hostProjectModuleName = this.getEmbedConfigForKey(
"hostProjectModuleName",
platform
);
if (hostProjectModuleName) {
args[2] = hostProjectModuleName;
}
}
console.log(args);
if (args.length < 2) {
return false;
}
return true;
}
private getEmbedConfigForKey(key: string, platform: string) {
// get the embed.<platform>.<key> value, or fallback to embed.<key> value
return this.$projectConfigService.getValue(
`embed.${platform}.${key}`,
this.$projectConfigService.getValue(`embed.${key}`)
);
}
}
injector.registerCommand("embed", EmbedCommand);