Skip to content

Commit 35a18db

Browse files
author
kbarioi
committed
feat(angular helpers): ng g c/p/s
1 parent 26ec387 commit 35a18db

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

after/plugin/remaps/angular.lua

+45-19
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,53 @@ local Remap = require("kbario.keymap")
44
local nnoremap = Remap.nnoremap
55

66
nnoremap(vim.g.mapleader .. hr.l4t .. hr.l4t, function()
7+
-- get current file name which should be the module you wish to add the comp to
78
local module = vim.api.nvim_buf_get_name(0)
8-
-- local module_name = vim.fn.fnamemodify(module, ':p:.:t')
9+
-- -- is standalone?
10+
-- local isStandaloneInput = vim.fn.input("standalone component? y/n > ")
11+
-- local isStandalone
12+
-- if isStandaloneInput == "y" then
13+
-- isStandalone = true
14+
-- else
15+
-- isStandalone = false
16+
-- end
17+
-- -- is in current module or top level?
18+
-- local isInCurrentModuleInput = vim.fn.input("put in current module? (else app module) y/n > ")
19+
-- local isInCurrentModule
20+
-- if isInCurrentModuleInput == "y" then
21+
-- isInCurrentModule = true
22+
-- else
23+
-- isInCurrentModule = false
24+
-- end
25+
-- get the path of the module without the module in it
926
local module_path = vim.fn.fnamemodify(module, ':p:.:h'):gsub('src/app/', ''):gsub('src\\app\\', '')
27+
-- get the module file name
1028
module = vim.fn.fnamemodify(module, ':p:.'):gsub('src/app/', ''):gsub('src\\app\\', '')
11-
12-
local type = vim.fn.input("file type (c, s, p)> ")
29+
-- create a table with possible options for new components
30+
local comp_tbl = {
31+
['p'] = "pipes",
32+
['s'] = "services",
33+
['c'] = "components",
34+
}
35+
-- get the type of component you want - either component, service or pipe
36+
local type = vim.fn.input("file type (c, s, p) > ")
37+
-- get the name of the file
1338
local name = vim.fn.input("file name > ")
14-
15-
local path = vim.fn.input("file path from " .. module_path .. "/ not including name > ")
16-
path = pth:new(string.format('%s/%s/%s/%s', module_path, path, name, name)).filename
17-
print(string.format(':!ng g %s %s -m %s', type, path, module))
18-
vim.cmd(string.format(':!ng g %s %s -m %s', type, path, module))
19-
20-
-- local cdub = vim.loop.cwd()
21-
-- local jsbeautifyrc = pth:new(string.format("%s/.jsbeautifyrc.json", cdub))
22-
--
23-
-- local file = pth:new(vim.api.nvim_buf_get_name(0)):make_relative(cdub)
24-
-- local filetype = vim.fn.fnamemodify(file, ":e")
25-
--
26-
-- if jsbeautifyrc:exists() and filetype == "html" then
27-
-- vim.cmd(string.format(":!js-beautify --config %s --replace %s", jsbeautifyrc.filename, file))
28-
-- print("beautified")
29-
-- end
39+
-- check if you want it put in the logical folder based on the component type
40+
local path
41+
local auto_sort = vim.fn.input("automatically file component in logical folder? (else custom) y/n > ")
42+
if auto_sort ~= 'y' and auto_sort ~= 'n' then return print('incorrect input') end
43+
-- if yes then assign path, else ask for the custom path
44+
if auto_sort == 'y' then
45+
path = comp_tbl[type]
46+
else
47+
path = vim.fn.input("file path from " .. module_path .. "/ not including name > ")
48+
end
49+
-- create the path for the new component to go to
50+
local new_comp_path = pth:new(string.format('%s/%s/%s/%s', module_path, path, name, name)).filename
51+
-- print the command
52+
print(string.format(':!ng g %s %s -m %s', type, new_comp_path, module))
53+
-- run the command
54+
-- vim.cmd(string.format(':!ng g %s %s -m %s', type, new_comp_path, module))
3055
end, { desc = "jsbeautifyrc formatting" })
56+

0 commit comments

Comments
 (0)