Repository navigation
Expand file tree
/
Copy pathrun
More file actions
executable file
·115 lines (86 loc) · 3.12 KB
/
Copy pathrun
File metadata and controls
executable file
·115 lines (86 loc) · 3.12 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
108
109
110
111
112
113
114
115
#!/usr/bin/env nu
use meta/toolkit *
# Handle the meta files of the monorepo
def main [] {
^($env.CURRENT_FILE) --help
}
def "main tools ensure" [] {
tools ensure
}
# Setup the development environment of the monorepo
def "main setup" [] {
nix setup
web setup
main setup projects
}
# Check if all the monorepo doesn't has any file in bad shape
def "main check" [] {
log info "Checking run file permissions..."
ls **/run | each {|file|
if ((stat -c "%a" $file.name | into int) / 100 | math floor) != 7 {
log error $"The run file '($file.name)' doesn't have permissions 'rwx' for the user"
log info "Run './run fix' to fix the issue!"
exit 1
}
}
nix check
web check
main check projects
log info "Everything is right!"
}
# Check, lint and format everything
def "main fix" [] {
log info "Setting the execution permission of all 'run' files"
chmod u+x **/run
nix fix
web fix
main fix projects
log info "Fixed every file!"
}
# Setup all the projects in the monorepo
def "main setup projects" [] {
generic-command-in-projects "setup" | ignore
}
# Check all the projects in the monorepo
def "main check projects" [] {
generic-command-in-projects "check" | ignore
}
# Fix all the projects in the monorepo
def "main fix projects" [] {
generic-command-in-projects "fix" | ignore
}
# Try to run a command in all the 'run' files of all the projects, if the command is not available
# or the 'run' doesn't exists then the project is skipped.
def generic-command-in-projects [
command: string # The name of the command to run
] {
ls ./projects/ | where type == dir | each { |project|
let project_name = $project.name | path basename
let run_file_path = $project.name | path join run
if ($run_file_path | path type) != "file" {
log warning $"The project '($project_name)' does not have a 'run' file, skipping..."
return
}
if not (cat $run_file_path | str contains $'def "main ($command)"') {
log warning $"The project '($project_name)' does not have a '($command)' routine, skipping..."
return
}
log info $"Running ($command) in project '($project_name)'"
cd $project.name
./run $command
cd ..
}
}
# Take all the gitignore files in the './gitignores/' directory and merge them in the global one
def "main gitignore build" [] {
log info "Building new global '.gitignore' file"
const mainGitignoreFilePath = "./.gitignore"
rm -f $mainGitignoreFilePath
"#### WARNING: MACHINE GENERATED FILE, DO NOT EDIT!!!\n" | save --append $mainGitignoreFilePath
"#### To generate this file run `./run gitignore build` at the root of the monorepo\n" | save --append $mainGitignoreFilePath
ls ...(glob ./meta/gitignores/**/*.gitignore) | each { |gitignoreFragmentPath|
let header = $"\n### ($gitignoreFragmentPath.name | path basename)\n"
$header | save --append $mainGitignoreFilePath
open $gitignoreFragmentPath.name | save --append $mainGitignoreFilePath
} | ignore
}