Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gorillamoe committed Oct 1, 2024
1 parent 3b53dbb commit 6e43903
Show file tree
Hide file tree
Showing 19 changed files with 4,308 additions and 119 deletions.
7 changes: 3 additions & 4 deletions lua/kulala/cmd/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local PARSER = require("kulala.parser")
local EXT_PROCESSING = require("kulala.external_processing")
local INT_PROCESSING = require("kulala.internal_processing")
local Api = require("kulala.api")
local Scripts = require("kulala.scripts")
local INLAY = require("kulala.inlay")
local UV = vim.loop
local Logger = require("kulala.logger")
Expand Down Expand Up @@ -61,7 +60,7 @@ end

---Runs the command and returns the result
---@param cmd table command to run
---@param callback function callback function
---@param callback function|nil callback function
M.run = function(cmd, callback)
vim.fn.jobstart(cmd, {
on_stderr = function(_, datalist)
Expand Down Expand Up @@ -124,7 +123,7 @@ M.run_parser = function(req, callback)
end
end
INT_PROCESSING.redirect_response_body_to_file(result.redirect_response_body_to_files)
Scripts.javascript.run("post_request", result.scripts.post_request)
PARSER.scripts.javascript.run("post_request", result.scripts.post_request)
Api.trigger("after_request")
end
Fs.delete_request_scripts_files()
Expand Down Expand Up @@ -179,7 +178,7 @@ M.run_parser_all = function(doc, callback)
end
end
INT_PROCESSING.redirect_response_body_to_file(result.redirect_response_body_to_files)
Scripts.javascript.run("post_request", result.scripts.post_request)
PARSER.scripts.javascript.run("post_request", result.scripts.post_request)
Api.trigger("after_request")
end
Fs.delete_request_scripts_files()
Expand Down
2 changes: 1 addition & 1 deletion lua/kulala/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local CONFIG = require("kulala.config")
local JUMPS = require("kulala.jumps")
local Graphql = require("kulala.graphql")
local Logger = require("kulala.logger")
local ScriptsUtils = require("kulala.scripts.utils")
local ScriptsUtils = require("kulala.parser.scripts.utils")
local M = {}

M.setup = function(config)
Expand Down
8 changes: 5 additions & 3 deletions lua/kulala/parser/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local M = {}
M.scripts = {}
local CONFIG = require("kulala.config")
local DB = require("kulala.db")
local DYNAMIC_VARS = require("kulala.parser.dynamic_vars")
Expand All @@ -11,9 +13,9 @@ local PARSER_UTILS = require("kulala.parser.utils")
local TS = require("kulala.parser.treesitter")
local PLUGIN_TMP_DIR = FS.get_plugin_tmp_dir()
local CURL_FORMAT_FILE = FS.get_plugin_path({ "parser", "curl-format.json" })
local Scripts = require("kulala.scripts")
local Logger = require("kulala.logger")
local M = {}

M.scripts.javascript = require("kulala.parser.scripts.javascript")

local function parse_string_variables(str, variables, env)
local function replace_placeholder(variable_name)
Expand Down Expand Up @@ -492,7 +494,7 @@ function M.parse(start_request_linenr)
return nil
end

Scripts.javascript.run("pre_request", req.scripts.pre_request)
M.scripts.javascript.run("pre_request", req.scripts.pre_request)
local env = ENV_PARSER.get_env()

DB.update().previous_request = DB.find_unique("current_request")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
local FS = require("kulala.utils.fs")
local GLOBALS = require("kulala.globals")
local CONFIG = require("kulala.config")
local Logger = require("kulala.logger")
local M = {}

local NPM_EXISTS = vim.fn.executable("npm") == 1
local NODE_EXISTS = vim.fn.executable("node") == 1
local SCRIPTS_DIR = FS.get_scripts_dir()
local REQUEST_SCRIPTS_DIR = FS.get_request_scripts_dir()
local BASE_FILE_PRE = FS.join_paths(SCRIPTS_DIR, "pre_request_base.js")
local BASE_FILE_POST = FS.join_paths(SCRIPTS_DIR, "post_request_base.js")
local BASE_DIR = FS.join_paths(SCRIPTS_DIR, "engines", "javascript", "lib")
local BASE_FILE_PRE = FS.join_paths(SCRIPTS_DIR, "engines", "javascript", "lib", "dist", "pre_request_base.js")
local BASE_FILE_POST = FS.join_paths(SCRIPTS_DIR, "engines", "javascript", "lib", "dist", "post_request_base.js")

M.install = function()
vim.system({ "npm", "install", "--prefix", BASE_DIR }):wait()
vim.system({ "npm", "run", "build", "--prefix", BASE_DIR }):wait()
end

local generate_one = function(script_type, is_external_file, script_data)
local lines
Expand Down Expand Up @@ -70,8 +78,20 @@ end
---@param data ScriptData
M.run = function(type, data)
if not NODE_EXISTS then
Logger.error("node not found, please install nodejs")
return
end

if not NPM_EXISTS then
Logger.error("npm not found, please install nodejs")
return
end

if not FS.file_exists(BASE_FILE_PRE) or not FS.file_exists(BASE_FILE_POST) then
Logger.warn("Javascript base files not found. Installing dependencies...")
M.install()
end

local scripts = generate_all(type, data)
if scripts == nil then
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = [
{
...require('eslint-config-love'),
files: ['src/**/*.ts'],
},
]
Loading

0 comments on commit 6e43903

Please sign in to comment.