forked from exercism/lines-of-code-counter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
921509b
commit dba2d15
Showing
11 changed files
with
184 additions
and
100 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
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
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require("./lib/app") | ||
require("./lib/lines_of_code_counter") | ||
|
||
event = { | ||
"track" => ARGV[0], | ||
"exercise" => ARGV[1], | ||
"solution" => ARGV[2], | ||
"output" => ARGV[3] | ||
} | ||
Exercism::CountLinesOfCode.process(event: event, context: {}) | ||
LinesOfCodeCounter.process(event: event, context: {}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "json" | ||
require "mandate" | ||
require "fileutils" | ||
require "./lib/lines_of_code_counter/count_lines_of_code" | ||
require "./lib/lines_of_code_counter/exercise" | ||
require "./lib/lines_of_code_counter/ignore_file" | ||
require "./lib/lines_of_code_counter/process_request" | ||
|
||
module LinesOfCodeCounter | ||
def self.process(event:, context:) | ||
ProcessRequest.(event, context) | ||
end | ||
end |
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,40 @@ | ||
class CountLinesOfCode | ||
include Mandate | ||
|
||
initialize_with :exercise | ||
|
||
def call | ||
{ | ||
code: code, | ||
blanks: blanks, | ||
comments: comments, | ||
files: files | ||
} | ||
end | ||
|
||
private | ||
memoize | ||
def report | ||
JSON.parse(`tokei #{exercise.dir} --output json`, symbolize_names: true) | ||
end | ||
|
||
def code | ||
report[:Total][:code] | ||
end | ||
|
||
def blanks | ||
report[:Total][:blanks] | ||
end | ||
|
||
def comments | ||
report[:Total][:comments] | ||
end | ||
|
||
def files | ||
report[:Total][:children].values. | ||
flatten. | ||
map {|child| child[:name].delete_prefix("#{exercise.dir}/") }. | ||
sort. | ||
to_a | ||
end | ||
end |
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,36 @@ | ||
class Exercise | ||
include Mandate | ||
|
||
attr_reader :dir | ||
|
||
def initialize(dir) | ||
@dir = dir | ||
end | ||
|
||
def solution_files | ||
config[:files][:solution].to_a | ||
end | ||
|
||
def test_files | ||
config[:files][:test].to_a | ||
end | ||
|
||
def editor_files | ||
config[:files][:editor].to_a | ||
end | ||
|
||
def exemplar_files | ||
config[:files][:exemplar].to_a | ||
end | ||
|
||
def example_files | ||
config[:files][:example].to_a | ||
end | ||
|
||
private | ||
memoize | ||
def config | ||
filepath = File.join(dir, ".meta", "config.json") | ||
JSON.parse(File.read(filepath), symbolize_names: true) | ||
end | ||
end |
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,43 @@ | ||
class IgnoreFile | ||
include Mandate | ||
|
||
initialize_with :track, :exercise | ||
|
||
def filepath | ||
File.join(exercise.dir, ".tokeignore") | ||
end | ||
|
||
def content | ||
rules = track_specific_rules? ? track_specific_rules : default_rules | ||
rules.compact.join("\n") | ||
end | ||
|
||
memoize | ||
def track_specific_rules? | ||
File.exist?(track_ignore_filepath) | ||
end | ||
|
||
def track_specific_rules | ||
[ | ||
*File.readlines(track_ignore_filepath), | ||
*exercise.test_files, | ||
*exercise.example_files, | ||
*exercise.exemplar_files, | ||
*exercise.editor_files, | ||
"counts.json", | ||
"expected_counts.json" | ||
] | ||
end | ||
|
||
def default_rules | ||
[ | ||
"*", | ||
*exercise.solution_files.map {|s|"!#{s}"} | ||
] | ||
end | ||
|
||
private | ||
def track_ignore_filepath | ||
"tracks/#{track}.ignore" | ||
end | ||
end |
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,39 @@ | ||
class ProcessRequest | ||
include Mandate | ||
|
||
initialize_with :event, :content | ||
|
||
def call | ||
File.write(ignore_file.filepath, ignore_file.content) | ||
counts = CountLinesOfCode.(exercise) | ||
File.write(counts_filepath, counts.to_json) | ||
# FileUtils.rm(ignore_file.filepath) | ||
end | ||
|
||
private | ||
def track | ||
event["track"] | ||
end | ||
|
||
def solution_dir | ||
event["solution"] | ||
end | ||
|
||
def output_dir | ||
event["output"] | ||
end | ||
|
||
def counts_filepath | ||
File.join(output_dir, "counts.json") | ||
end | ||
|
||
memoize | ||
def exercise | ||
Exercise.new(solution_dir) | ||
end | ||
|
||
memoize | ||
def ignore_file | ||
IgnoreFile.new(track, exercise) | ||
end | ||
end |