Author:ptrace
Comitter:ptrace
Date:2025-07-26 23:21:44 UTC
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a56aaef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
# Jai
.build
jinit
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9c058e4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) 2025 adam@p-trace.com, key.p-trace.com, Key ID: E766CB298A6D1E64
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1ff3b29
--- /dev/null
+++ b/README.md
@@ -0,0 +1,9 @@
# Jai Init
Smol program that creates some basic files and folders for Jai development.
Adapt it to your own needs.
## Usage
- `jai jinit.jai`
- add the binary to your $PATH or symlink it where appropriate
diff --git a/jinit.jai b/jinit.jai
new file mode 100755
index 0000000..203d739
--- /dev/null
+++ b/jinit.jai
@@ -0,0 +1,135 @@
#import "Basic";
File :: #import "File";
FileUtils :: #import "File_Utilities";
Process :: #import "Process";
String :: #import "String";
Cli :: #import "Command_Line";
// adapt it to your own taste
FP_SRC_DIR :: string.["src"];
JAI_ENTRYPOINT :: "src/main.jai";
JAI_BUILD :: "build.jai";
GIT_IGNORE :: ".gitignore";
OTHER_EMPTY_FILES :: string.[
"README.md",
];
CONTENT_GIT_IGNORE :: #string END
# Jai
.build
END;
CONTENT_MAIN_JAI :: #string END
#import "Basic";
main :: () {
print("Hello, Sailor!\n");
}
END;
CONTENT_BUILD_JAI :: #string END
#import "Basic";
#import "Compiler";
build :: () {
w := compiler_create_workspace();
if !w {
print("Workspace creation failed.\n");
return;
}
print("The workspace w is %\n", w);
target_options := get_build_options(w);
target_options.output_executable_name = "program";
set_build_options(target_options, w);
// add_build_file("main.jai", w);
add_build_file(tprint("%/main.jai", #filepath), w);
set_build_options_dc(.{do_output=false});
}
main :: () {}
#run build();
END;
create_git_project :: (root_fp: string, args: Arguments) {
if args.g return;
if FileUtils.file_exists(".git") return;
command := string.["git", "init"];
process_result, output_str, error_str := Process.run_command(
..command,
working_directory = root_fp,
capture_and_return_output = true
);
if process_result.exit_code != 0 {
if error_str print("Error: %\n", error_str);
if output_str print("Error: %\n", output_str);
exit(1);
}
}
create_directories :: (root_fp: string) {
for FP_SRC_DIR {
if String.starts_with(it, "/") {
print("Are you sure you want to create it at the root dir? Input: %\n", it);
exit(1);
}
File.make_directory_if_it_does_not_exist(tprint("%/%", root_fp, it));
}
}
create_file :: (fp: string, content: string = "") {
if FileUtils.file_exists(fp) return;
if !File.write_entire_file(fp, content) {
print("Cannot create or write into file: '%'\n", fp);
exit(1);
}
}
create_files :: (root_fp: string, args: Arguments) {
fp_entrypoint := tprint("%/%", root_fp, JAI_ENTRYPOINT);
fp_jai_build := tprint("%/%", root_fp, JAI_BUILD);
fp_gitignore := tprint("%/%", root_fp, GIT_IGNORE);
create_file(fp_entrypoint, CONTENT_MAIN_JAI);
create_file(fp_jai_build, CONTENT_BUILD_JAI);
if !args.g {
create_file(fp_gitignore, CONTENT_GIT_IGNORE);
}
for OTHER_EMPTY_FILES {
create_file(tprint("%/%", root_fp, it));
}
}
Arguments :: struct {
g: bool; @"?If provided, no Git repository and .gitignore file will be created."
}
main :: () {
success, args, is_set := Cli.parse_arguments(Arguments);
if !success {
exit(1);
}
current_path := get_working_directory();
if !current_path {
print("Cannot resolve root path\n");
exit(1);
}
create_directories(current_path);
create_files(current_path, args);
create_git_project(current_path, args);
print("[Jai Init]: Done\n");
}