-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added config for single or multiple projects under 1 or many config f…
…iles
- Loading branch information
1 parent
ad70ae5
commit b98e179
Showing
9 changed files
with
481 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local BuildActions = {} | ||
|
||
|
||
--- Called before any of the build process starts. | ||
---@param config SSSWTool.Config | ||
function BuildActions.pre_build(config) | ||
end | ||
|
||
--- Called before a file is parsed. | ||
---@param config SSSWTool.Config | ||
---@param path string | ||
function BuildActions.pre_parse(config, path) | ||
end | ||
|
||
--- Called after a file is parsed but before it's transformed. | ||
---@param config SSSWTool.Config | ||
---@param path string | ||
---@param ast ASTNodeSource | ||
function BuildActions.post_parse(config, path, ast) | ||
end | ||
|
||
--- Called after a file is transformed. | ||
---@param config SSSWTool.Config | ||
---@param path string | ||
---@param ast ASTNodeSource | ||
function BuildActions.post_transform(config, path, ast) | ||
end | ||
|
||
--- Called after the entire build process finishes. | ||
--- This is the very last build action to be called. | ||
--- This is still called before `script.lua` is copied to it's output directory. | ||
---@param config SSSWTool.Config | ||
function BuildActions.post_build(config) | ||
end | ||
|
||
|
||
return BuildActions |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
local json = require "json" | ||
|
||
local Utils = require "SelenScript.utils" | ||
|
||
|
||
---@class SSSWTool.Config | ||
---@field _validate fun(config:SSSWTool.Config, data:table)? | ||
local Config = {} | ||
Config.__index = Config | ||
|
||
|
||
---@param default table? | ||
---@param validate fun(config:SSSWTool.Config, data:table)? | ||
function Config.new(default, validate) | ||
local self = setmetatable({}, Config) | ||
self._validate = validate | ||
self.data = default and Utils.shallowcopy(default) or {} | ||
if validate then | ||
local ok, err = pcall(validate, self, self.data) | ||
if not ok then | ||
error(("Failed to validate config '%s'\n%s"):format("<DEFAULT>", err:gsub(".-:.-: ", ""))) | ||
end | ||
end | ||
return self | ||
end | ||
|
||
--- Siliently ignores file not found errors and does not reset config. | ||
---@param path string | ||
function Config:read(path) | ||
local f, msg, code = io.open(path, "r") | ||
if not f then | ||
if code == 2 then | ||
return true | ||
end | ||
return false, msg, code | ||
end | ||
local src = f:read("*a") | ||
local ok, data = pcall(json.decode, src) | ||
if not ok then | ||
return false, ("Failed to parse config '%s'\n%s"):format(path, data:gsub(".-:.-: ", "")) | ||
end | ||
if self._validate then | ||
local ok, err = pcall(self._validate, self, data) | ||
if not ok then | ||
return false, ("Failed to validate config '%s'\n%s"):format(path, err:gsub(".-:.-: ", "")) | ||
end | ||
end | ||
self.data = data | ||
return true | ||
end | ||
|
||
-- ---@param path string | ||
-- function Config:write(path) | ||
-- local f, msg, code = io.open(path, "w") | ||
-- if not f then | ||
-- return false, msg, code | ||
-- end | ||
-- error("TODO") | ||
-- return true | ||
-- end | ||
|
||
|
||
return Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
local Utils = require "SelenScript.utils" | ||
|
||
local Config = require "tool.config" | ||
local Project = require "tool.project" | ||
|
||
|
||
---@class SSSWTool.MultiProject | ||
---@field config_path string # Normalized path to the project config file. | ||
---@field project_path string # Normalized path to the project. | ||
---@field projects (SSSWTool.Project|SSSWTool.MultiProject)[] | ||
---@field config SSSWTool.Config | ||
local MultiPorject = {} | ||
MultiPorject.__index = MultiPorject | ||
|
||
|
||
---@param config_path string | ||
function MultiPorject.new(config_path) | ||
local self = setmetatable({}, MultiPorject) | ||
self.config_path = config_path:gsub("\\", "/"):gsub("^%./", ""):gsub("/$", "") | ||
self.project_path = self.config_path:match("^(.*)/") or error("Failed to get parent dir from config path.") | ||
|
||
self.projects = {} | ||
self.config = Config.new() | ||
local ok, err, code = self.config:read(config_path) | ||
if not ok then | ||
return nil, err, code | ||
end | ||
if type(self.config.data) == "table" and type(self.config.data[1]) == "table" then | ||
print_info(("Multi Project config '%s'"):format(config_path)) | ||
for i, v in ipairs(self.config.data) do | ||
if type(v) == "string" then | ||
self:createMultiProject(self.project_path .. "/" .. v, ("'%s' index %s"):format(config_path, i)) | ||
else | ||
Utils.merge(Project.getDefaultConfig(self, false), v, false) | ||
self:createProject(v, ("'%s' index %s"):format(config_path, i)) | ||
end | ||
end | ||
else | ||
Utils.merge(Project.getDefaultConfig(self, true), self.config.data, false) | ||
self:createProject(self.config.data, config_path) | ||
end | ||
return self | ||
end | ||
|
||
---@param project_config SSSWTool.Project.Config | ||
---@param project_path string | ||
function MultiPorject:createProject(project_config, project_path) | ||
local project, err = Project.new(self, project_config) | ||
if not project or err then | ||
if err then | ||
print_error(("%s: %s"):format(project_config.name or project_path, err:gsub(".-:.-: ", ""))) | ||
return nil | ||
else | ||
error("ERROR project == nil") | ||
end | ||
else | ||
print_info(("Loaded config for %s"):format(project_config.name or project_path)) | ||
end | ||
table.insert(self.projects, project) | ||
return project | ||
end | ||
|
||
---@param config_path string | ||
---@param project_path string | ||
function MultiPorject:createMultiProject(config_path, project_path) | ||
local multiproject = MultiPorject.new(config_path) | ||
table.insert(self.projects, multiproject) | ||
return multiproject | ||
end | ||
|
||
---@return {[1]:SSSWTool.Project|SSSWTool.MultiProject,[2]:any[]}[] | ||
function MultiPorject:build() | ||
local results = {} | ||
for _, project in ipairs(self.projects) do | ||
print() | ||
print_info(("Buidling '%s'"):format(project.config.name)) | ||
local result = {project:build()} | ||
table.insert(results, {project, result}) | ||
end | ||
return results | ||
end | ||
|
||
|
||
return MultiPorject |
Oops, something went wrong.