diff --git a/tool/presets/new_addon.lua b/tool/presets/new_addon.lua index 695fe5c..63c50b6 100644 --- a/tool/presets/new_addon.lua +++ b/tool/presets/new_addon.lua @@ -79,6 +79,7 @@ return function(name) end io.write("\n") end + print("You can change this setting using 'ssswtool userconfig'") end if UserConfig.intellisense_autoupdate_allowed() then local should_update_intellisense = false @@ -121,16 +122,21 @@ return function(name) end end + local files = { + ["ssswtool.json"] = {contents=SSSWTOOL_JSON_FMT:format(name)}, + ["script.lua"] = {contents=SCRIPT}, + [".gitignore"] = {contents=GITIGNORE}, + [".vscode/settings.json"] = {contents=VSCODE_SETTINGS}, + } + if PresetsUtils.exists("addon/intellisense.lua") then + files["intellisense.lua"] = {replace=true, contents=PresetsUtils.read_file("addon/intellisense.lua")} + else + print_warn("Preset is missing 'intellisense.lua', this is likely due to automatic intellisense updates being disabled.") + end ---@type SSSWTool.NewPreset return { expect_empty_path = true, - files = { - ["ssswtool.json"] = {contents=SSSWTOOL_JSON_FMT:format(name)}, - ["script.lua"] = {contents=SCRIPT}, - ["intellisense.lua"] = {replace=true, contents=PresetsUtils.read_file("addon/intellisense.lua")}, - [".gitignore"] = {contents=GITIGNORE}, - [".vscode/settings.json"] = {contents=VSCODE_SETTINGS}, - }, + files = files, } end diff --git a/tool/presets_utils.lua b/tool/presets_utils.lua index 59e0897..6503981 100644 --- a/tool/presets_utils.lua +++ b/tool/presets_utils.lua @@ -1,30 +1,37 @@ -local lfs = require "lfs" -local AvPath = require "avpath" - -local Utils = require "SelenScript.utils" - - -local PRESETS_PATH = AvPath.join{require "tool.tool_path", "presets"} - -local PresetsUtils = {} -PresetsUtils.PRESETS_PATH = PRESETS_PATH - - ----@param path string ----@param binary boolean? -function PresetsUtils.read_file(path, binary) - path = AvPath.join{PRESETS_PATH, path} - return Utils.readFile(path, binary) -end - ----@param path string ----@param data string ----@param binary boolean? -function PresetsUtils.write_file(path, data, binary) - path = AvPath.join{PRESETS_PATH, path} - lfs.mkdir(AvPath.base(path)) - Utils.writeFile(path, data, binary) -end - - +local lfs = require "lfs" +local AvPath = require "avpath" + +local Utils = require "SelenScript.utils" + + +local PRESETS_PATH = AvPath.join{require "tool.tool_path", "presets"} + +local PresetsUtils = {} +PresetsUtils.PRESETS_PATH = PRESETS_PATH + + +---@param path string +function PresetsUtils.exists(path) + path = AvPath.join{PRESETS_PATH, path} + return AvPath.exists(path) +end + + +---@param path string +---@param binary boolean? +function PresetsUtils.read_file(path, binary) + path = AvPath.join{PRESETS_PATH, path} + return Utils.readFile(path, binary) +end + +---@param path string +---@param data string +---@param binary boolean? +function PresetsUtils.write_file(path, data, binary) + path = AvPath.join{PRESETS_PATH, path} + lfs.mkdir(AvPath.base(path)) + Utils.writeFile(path, data, binary) +end + + return PresetsUtils \ No newline at end of file