Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefixes scripts matches with a star. #77

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions yarn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ end
-- A function that matches all files in bin folder. See #74 for rationale
local bins = matchers.create_files_matcher('node_modules/.bin/*.')

-- Prefixes project.json scripts with a * (as opposed to node_module/.bin matches)
local function scripts_display_filter(project_scripts)
return function(matches)
for i, m in ipairs(matches) do
local prefix = project_scripts[m] ~= nil and '*' or ' '
matches[i] = prefix..m
end
return matches
end
end

-- Reads package.json in current directory and extracts all "script" commands defined
local function scripts(token) -- luacheck: no unused args

-- Read package.json first
local package_json = io.open('package.json')
-- If there is no such file, then close handle and return
Expand All @@ -63,8 +73,9 @@ local function scripts(token) -- luacheck: no unused args
local package_contents = package_json:read("*a")
package_json:close()

local package_scripts = JSON:decode(package_contents).scripts
return w(package_scripts):keys()
local project_scripts = w(JSON:decode(package_contents).scripts)
clink.match_display_filter = scripts_display_filter(project_scripts)
return project_scripts:keys()
end

local parser = clink.arg.new_parser
Expand Down