-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathframework-configs.ts
More file actions
107 lines (103 loc) · 2.56 KB
/
framework-configs.ts
File metadata and controls
107 lines (103 loc) · 2.56 KB
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
import type { Config, FrameworkConfig } from './definitions.js';
const FRAMEWORK_CONFIGS: FrameworkConfig[] = [
{
name: 'Angular',
isMatch: (config) => hasDependency(config, '@angular/cli'),
webDir: 'dist',
priority: 3,
},
{
name: 'Create React App',
isMatch: (config) => hasDependency(config, 'react-scripts'),
webDir: 'build',
priority: 3,
},
{
name: 'Ember',
isMatch: (config) => hasDependency(config, 'ember-cli'),
webDir: 'dist',
priority: 3,
},
{
name: 'Gatsby',
isMatch: (config) => hasDependency(config, 'gatsby'),
webDir: 'public',
priority: 2,
},
{
name: 'Ionic Angular',
isMatch: (config) => hasDependency(config, '@ionic/angular'),
webDir: 'www',
priority: 1,
},
{
name: 'Ionic React',
isMatch: (config) => hasDependency(config, '@ionic/react'),
webDir: 'build',
priority: 1,
},
{
name: 'Ionic Vue',
isMatch: (config) => hasDependency(config, '@ionic/vue'),
webDir: 'public',
priority: 1,
},
{
name: 'Next',
isMatch: (config) => hasDependency(config, 'next'),
webDir: 'public',
priority: 2,
},
{
name: 'Preact',
isMatch: (config) => hasDependency(config, 'preact-cli'),
webDir: 'build',
priority: 3,
},
{
name: 'Stencil',
isMatch: (config) => hasDependency(config, '@stencil/core'),
webDir: 'www',
priority: 3,
},
{
name: 'Svelte',
isMatch: (config) => hasDependency(config, 'svelte') && hasDependency(config, 'sirv-cli'),
webDir: 'public',
priority: 3,
},
{
name: 'Vite',
isMatch: (config) => hasDependency(config, 'vite'),
webDir: 'dist',
priority: 2,
},
{
name: 'Vue',
isMatch: (config) => hasDependency(config, '@vue/cli-service'),
webDir: 'dist',
priority: 3,
},
];
export function detectFramework(config: Config): FrameworkConfig | undefined {
const frameworks = FRAMEWORK_CONFIGS.filter((f) => f.isMatch(config)).sort((a, b) => {
if (a.priority < b.priority) return -1;
if (a.priority > b.priority) return 1;
return 0;
});
return frameworks[0];
}
function hasDependency(config: Config, depName: string): boolean {
const deps = getDependencies(config);
return deps.includes(depName);
}
function getDependencies(config: Config): string[] {
const deps: string[] = [];
if (config?.app?.package?.dependencies) {
deps.push(...Object.keys(config.app.package.dependencies));
}
if (config?.app?.package?.devDependencies) {
deps.push(...Object.keys(config.app.package.devDependencies));
}
return deps;
}