forked from innocenzi/config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreset.ts
94 lines (89 loc) · 2.28 KB
/
preset.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
export default definePreset({
name: 'innocenzi:config',
options: {
install: true,
editor: true,
eslint: false,
vue: false,
php: false,
rust: false,
bevy: false,
ghRelease: false,
},
handler: async({ options }) => {
for (const type of ['editor', 'eslint', 'php', 'vue', 'rust']) {
if (options[type]) {
await extractTemplates({ from: type, title: `extract ${type} config` })
}
}
if (options.bevy) {
await editFiles({
files: 'Cargo.toml',
operations: [
{
type: 'update-content',
skipIf: (content) => content.includes('bevy ='),
update: (content) => content.replace('[dependencies]', '[dependencies]\nbevy = { version = "0.9.0", features = ["dynamic"] }'),
},
{
type: 'update-content',
skipIf: (content) => content.includes('profile.dev'),
update: (content) => content += `
# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1
# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3
`.trimEnd(),
},
],
})
}
if (options.ghRelease) {
await extractTemplates({
title: 'extract release action',
from: 'github/release.yml',
to: '.github/workflows',
flatten: true,
})
}
if (options.install) {
if (options.eslint) {
await installPackages({ for: 'node', install: ['eslint', '@innocenzi/eslint-config', 'typescript'], dev: true, title: 'install eslint' })
}
if (options.php) {
await group({
title: 'install php-cs-fixer',
handler: async() => {
await installPackages({ for: 'php', install: ['friendsofphp/php-cs-fixer'], dev: true })
await editFiles({
title: 'ignore php-cs-fixer cache file',
files: '.gitignore',
operations: {
skipIf: (content) => content.includes('.php-cs-fixer.cache'),
type: 'add-line',
position: 'append',
lines: ['.php-cs-fixer.cache'],
},
})
await editFiles({
title: 'add "style" composer script',
files: 'composer.json',
operations: {
type: 'edit-json',
merge: {
scripts: {
style: [
'php-cs-fixer fix --allow-risky=yes',
],
},
},
},
})
},
})
}
}
},
})