rogems 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "test",
3
+ "tree": {
4
+ "$className": "DataModel",
5
+
6
+ "ReplicatedStorage": {
7
+ "Common": {
8
+ "$path": "src/shared"
9
+ }
10
+ },
11
+
12
+ "ServerScriptService": {
13
+ "Server": {
14
+ "$path": "src/server"
15
+ }
16
+ },
17
+
18
+ "StarterPlayer": {
19
+ "StarterPlayerScripts": {
20
+ "Client": {
21
+ "$path": "src/client"
22
+ }
23
+ }
24
+ },
25
+
26
+ "Workspace": {
27
+ "$properties": {
28
+ "FilteringEnabled": true
29
+ },
30
+ "Baseplate": {
31
+ "$className": "Part",
32
+ "$properties": {
33
+ "Anchored": true,
34
+ "Color": [
35
+ 0.38823,
36
+ 0.37254,
37
+ 0.38823
38
+ ],
39
+ "Locked": true,
40
+ "Position": [
41
+ 0,
42
+ -10,
43
+ 0
44
+ ],
45
+ "Size": [
46
+ 512,
47
+ 20,
48
+ 512
49
+ ]
50
+ }
51
+ }
52
+ },
53
+ "Lighting": {
54
+ "$properties": {
55
+ "Ambient": [
56
+ 0,
57
+ 0,
58
+ 0
59
+ ],
60
+ "Brightness": 2,
61
+ "GlobalShadows": true,
62
+ "Outlines": false,
63
+ "Technology": "Voxel"
64
+ }
65
+ },
66
+ "SoundService": {
67
+ "$properties": {
68
+ "RespectFilteringEnabled": true
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,6 @@
1
+ -- local ruby = require(game.ReplicatedStorage.Ruby.Runtime)
2
+
3
+ print({
4
+ ["stuff"] = true,
5
+ not_stuff = false
6
+ })
@@ -0,0 +1,6 @@
1
+ {
2
+ "rootDir": "./",
3
+ "sourceDir": "src",
4
+ "outDir": "out",
5
+ "debugging": true
6
+ }
@@ -0,0 +1,4 @@
1
+ puts ({
2
+ "stuff" => true,
3
+ not_stuff => false
4
+ })
data/lib/RoGems.rb ADDED
@@ -0,0 +1,4 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "rogems")
2
+ require "CLI"
3
+
4
+ cli_interface = RoGems::CLI.new
data/lib/rogems/CLI.rb ADDED
@@ -0,0 +1,121 @@
1
+ require "json"
2
+ require "listen"
3
+ require "optparse"
4
+ require "fileutils"
5
+ require "open3"
6
+ require "Transpiler"
7
+
8
+ module RoGems
9
+ class CLI
10
+ module InitMode
11
+ NONE = 0
12
+ GAME = 1
13
+ GEM = 2
14
+ end
15
+
16
+ def get_config(base_dir)
17
+ config_name = File.join(base_dir || Dir.pwd, "rogems.json")
18
+ if !File.exist?(config_name) then
19
+ raise Exceptions::MissingConfigError.new(base_dir)
20
+ end
21
+
22
+ file = File.read(config_name)
23
+ JSON.parse(file)
24
+ end
25
+
26
+ def initialize
27
+ @usage = "Usage: rogems [options] [DIRECTORY?]"
28
+ @options = {}
29
+ OptionParser.new do |opts|
30
+ opts.banner = @usage
31
+ opts.on("-t", "--test", "Run RSpec for RoGems.") do
32
+ @options[:testing] = true
33
+ system("rspec --format doc")
34
+ end
35
+ opts.on("-w", "--watch", "Watch for changes in directory.") { |watch| @options[:watch] = watch }
36
+ opts.on("--init=INIT_MODE", "Create a new Rojo project and necessary configuration files. INIT_MODE can be \"none\", \"game\", or \"gem\"") do |init_mode| # Create a new Rojo project
37
+ @options[:init] = true
38
+ init_project(init_mode)
39
+ end
40
+ end.parse!
41
+
42
+ if @options[:init] || @options[:testing] then return end
43
+ @options[:dir] = ARGV[0]
44
+ @config = get_config(@options[:dir])
45
+ @transpiler = Transpiler.new(@config, @options[:dir])
46
+
47
+ if @options[:watch]
48
+ puts "=== Compiling in watch mode ==="
49
+ listener = Listen.to(@config["sourceDir"]) do
50
+ puts "Detected file change, compiling..."
51
+ @transpiler.transpile
52
+ end
53
+ listener.start
54
+ end
55
+
56
+ @transpiler.transpile
57
+ if @options[:watch] then sleep end
58
+ end
59
+
60
+ def init_project(init_mode = "game")
61
+ validated = validate_init_mode(init_mode)
62
+ init_command = get_init_cmd(validated)
63
+ self.check_rojo_installed
64
+ success = system(init_command)
65
+ if !success then return end
66
+
67
+ FileUtils.mv("src", "out") # rename
68
+ Dir.glob("./out/**/*").filter { |f| File.file?(f) }.each { |f| File.delete(f) }
69
+ FileUtils.cp_r("out/.", "src", :remove_destination => true) # copy dirs
70
+ path = File.join(File.dirname(__FILE__), "default_rogems.json")
71
+ default_rogems_json = File.read(path)
72
+ File.open("rogems.json", "w") { |f| f.write(default_rogems_json) }
73
+
74
+ @config = JSON.parse(default_rogems_json)
75
+ @transpiler = Transpiler.new(@config)
76
+ FileUtils.touch("./src/shared/helloWorld.rb") # create example files
77
+ File.open("./src/shared/helloWorld.rb", "w") do |file|
78
+ file.write("def helloWorld\n puts \"hello world\"\nend")
79
+ end
80
+ FileUtils.touch("./src/client/main.client.rb")
81
+ File.open("./src/client/main.client.rb", "w") do |file|
82
+ file.write("require \"shared/helloWorld\"\n\nhelloWorld()")
83
+ end
84
+ @transpiler.transpile
85
+ end
86
+
87
+ def validate_init_mode(mode = "game")
88
+ case mode.downcase
89
+ when "none"
90
+ InitMode::NONE
91
+ when "game"
92
+ InitMode::GAME
93
+ when "gem"
94
+ InitMode::GEM
95
+ else
96
+ raise Exceptions::InvalidInitModeError.new(mode, @usage)
97
+ end
98
+ end
99
+
100
+ def get_init_cmd(init_mode)
101
+ case init_mode
102
+ when InitMode::NONE, InitMode::GEM
103
+ "rojo init"
104
+ when InitMode::GAME
105
+ "rojo init --kind place"
106
+ end
107
+ end
108
+
109
+ def check_rojo_installed
110
+ rojo_installed = false
111
+ begin
112
+ stderr, stdout, status = Open3.capture3("rojo -v")
113
+ rojo_installed = stderr.nil? || stderr == ""
114
+ rescue Exception => e
115
+ rojo_installed = false
116
+ ensure
117
+ raise Exceptions::RojoNotFoundError.new unless rojo_installed
118
+ end
119
+ end
120
+ end
121
+ end