-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
railsArgumentResolver.ts
123 lines (107 loc) · 2.8 KB
/
railsArgumentResolver.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
/*
* Copyright 2021 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { sep as separatorPath } from 'path';
enum Webpacker {
react = 'react',
vue = 'vue',
angular = 'angular',
elm = 'elm',
stimulus = 'stimulus',
}
enum Database {
mysql = 'mysql',
postgresql = 'postgresql',
sqlite3 = 'sqlite3',
oracle = 'oracle',
sqlserver = 'sqlserver',
jdbcmysql = 'jdbcmysql',
jdbcsqlite3 = 'jdbcsqlite3',
jdbcpostgresql = 'jdbcpostgresql',
jdbc = 'jdbc',
}
enum RailsVersion {
dev = 'dev',
edge = 'edge',
master = 'master',
fromImage = 'fromImage',
}
export type RailsRunOptions = {
minimal?: boolean;
api?: boolean;
template?: string;
webpacker?: Webpacker;
database?: Database;
railsVersion?: RailsVersion;
skipBundle?: boolean;
skipWebpackInstall?: boolean;
skipTest?: boolean;
force?: boolean;
};
export const railsArgumentResolver = (
projectRoot: string,
options: RailsRunOptions,
executionOnContainer = false,
): string[] => {
const argumentsToRun: string[] = [];
if (options?.minimal) {
argumentsToRun.push('--minimal');
}
if (options?.api) {
argumentsToRun.push('--api');
}
if (options?.skipBundle) {
argumentsToRun.push('--skip-bundle');
}
if (options?.skipWebpackInstall) {
argumentsToRun.push('--skip-webpack-install');
}
if (options?.skipTest) {
argumentsToRun.push('--skip-test');
}
if (options?.force) {
argumentsToRun.push('--force');
}
if (
options?.webpacker &&
Object.values(Webpacker).includes(options?.webpacker as Webpacker)
) {
argumentsToRun.push('--webpack');
argumentsToRun.push(options.webpacker);
}
if (
options?.database &&
Object.values(Database).includes(options?.database as Database)
) {
argumentsToRun.push('--database');
argumentsToRun.push(options.database);
}
if (
options?.railsVersion !== RailsVersion.fromImage &&
Object.values(RailsVersion).includes(options?.railsVersion as RailsVersion)
) {
argumentsToRun.push(`--${options.railsVersion}`);
}
if (options?.template) {
argumentsToRun.push('--template');
argumentsToRun.push(
options.template.replace(
`.${separatorPath}`,
`${projectRoot}${executionOnContainer ? '/' : separatorPath}`,
),
);
}
return argumentsToRun;
};