Skip to content

Commit

Permalink
update ci configs and add prettier library
Browse files Browse the repository at this point in the history
  • Loading branch information
dorianmariecom committed Sep 14, 2024
1 parent 2cfec52 commit aacd4b0
Show file tree
Hide file tree
Showing 65 changed files with 37,120 additions and 107 deletions.
24 changes: 12 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
updates:
- directory: "/"
package-ecosystem: github-actions
schedule:
interval: daily
- directory: "/"
package-ecosystem: npm
schedule:
interval: daily
- directory: "/"
package-ecosystem: bundler
schedule:
interval: daily
- directory: "/"
package-ecosystem: github-actions
schedule:
interval: daily
- directory: "/"
package-ecosystem: npm
schedule:
interval: daily
- directory: "/"
package-ecosystem: bundler
schedule:
interval: daily
version: 2
38 changes: 19 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ jobs:
name: Bundler Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/bundler-audit check --update
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/bundler-audit check --update
npm-audit:
name: npm Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm audit
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm audit
rspec:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/test
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/test
rubocop:
name: Rubocop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/rubocop
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bin/rubocop
name: CI
"on": push
'on': push
22 changes: 11 additions & 11 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
AllCops:
Exclude:
- "*/node_modules/**/*"
- "*/vendor/**/*"
- node_modules/**/*
- vendor/**/*
- "*/node_modules/**/*"
- "*/vendor/**/*"
- node_modules/**/*
- vendor/**/*
NewCops: enable
TargetRubyVersion: 3.3
Layout/ClosingHeredocIndentation:
Expand Down Expand Up @@ -120,10 +120,10 @@ Style/StringLiterals:
Style/StringLiteralsInInterpolation:
Enabled: false
require:
- rubocop-factory_bot
- rubocop-performance
- rubocop-rails
- rubocop-rake
- rubocop-rspec
- rubocop-rspec_rails
- rubocop-capybara
- rubocop-factory_bot
- rubocop-performance
- rubocop-rails
- rubocop-rake
- rubocop-rspec
- rubocop-rspec_rails
- rubocop-capybara
3 changes: 0 additions & 3 deletions a.js

This file was deleted.

66 changes: 39 additions & 27 deletions lib/dorian/bin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Bin
.spec
.thor
.watchr
].freeze
]

RUBY_FILENAMES = %w[
.irbrc
Expand Down Expand Up @@ -73,7 +73,7 @@ class Bin
Vagabondfile
Vagrantfile
buildfile
].freeze
]

VERSION = File.read(File.expand_path("../../VERSION", __dir__))

Expand Down Expand Up @@ -355,14 +355,43 @@ def command_pretty
end

def command_format
root = File.expand_path("../../../", __dir__)
prettier_path = File.join(root, "node_modules/prettier/standalone.js")
prettier_js = File.read(prettier_path)
parser_path = File.join(root, "node_modules/prettier/plugins/babel.js")
parser_js = File.read(parser_path)
context = MiniRacer::Context.new
context.attach("puts", proc { |string| puts(string) })
context.attach("warn", proc { |string| warn(string) })
context.attach("read", proc { |path| File.read(path) })
context.attach(
"write",
proc { |path, content| File.write(filename, content) }
)
root = File.expand_path("../../", __dir__)
prettier_path = File.join(root, "vendor/prettier/standalone.js")
babel_path = File.join(root, "vendor/prettier/plugins/babel.js")
estree_path = File.join(root, "vendor/prettier/plugins/estree.js")
prettier_js = File.read(prettier_path)
babel_js = File.read(babel_path)
estree_js = File.read(estree_path)
context.eval(prettier_js)
context.eval(parser_js)
context.eval("module = { exports: {} }; exports = module.exports")
context.eval(babel_js)
context.eval("babel = module.exports;")
context.eval("module = { exports: {} }; exports = module.exports")
context.eval(estree_js)
context.eval("estree = module.exports;")
context.eval("plugins = [babel, estree];")
context.eval(<<~JS)
format = async (path, parser) => {
try {
const before = read(path);
const after = await prettier.format(before, { parser, plugins });
if (before != after) {
puts(path);
write(path, after);
}
} catch (e) {
warn(`failed to parse ${path}: ${e.message.split("\\n")[0]}`);
}
};
JS

Git.open(".").ls_files.map(&:first).each { |file| format(file, context:) }
end
Expand Down Expand Up @@ -421,7 +450,7 @@ def command_tree
down = "│   "
down_and_right = "├── "

git_ls_files = ->(path) { Git.open(".").ls_files(path).map(&:first) }
git_ls_files = lambda { |path| Git.open(".").ls_files(path).map(&:first) }

group =
lambda do |files|
Expand Down Expand Up @@ -1351,11 +1380,9 @@ def filetype(path)
return :env if path == ".env"
return :env if path.start_with?(".env.")
return unless File.exist?(path)

first_line = File.open(path, &:gets).to_s
first_line = first_line.encode("UTF-8", invalid: :replace)
return :ruby if /\A#!.*ruby\z/.match?(first_line)

false
end

Expand Down Expand Up @@ -1463,7 +1490,6 @@ def sort(object)
def format(path, context:)
return if File.symlink?(path)
return unless File.exist?(path)

before = File.read(path)

case filetype(path)
Expand All @@ -1480,21 +1506,7 @@ def format(path, context:)
when :yaml
after = sort(YAML.safe_load(before)).to_yaml
when :js
promise = context.eval(<<~JS)
prettier.format(#{before.to_json}, { "parser": "babel" })
JS
p promise
p promise.class
after = before
loop do
if promise.fulfilled?
after = promise.value
elsif promise.rejected?
raise promise.reason
else
sleep(0.01)
end
end
context.eval("format(#{path.to_json}, 'babel')")
end

if after && before != after
Expand Down
25 changes: 12 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"devDependencies": {
"dependencies": {
"prettier": "*"
},
"engines": {
"node": "22.5.1",
"npm": "10.8.2"
},
"license": "MIT"
}
}
18 changes: 14 additions & 4 deletions samples/books.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@
{
"author": "F. Scott Fitzgerald",
"available": true,
"genres": ["Novel", "Historical"],
"genres": [
"Novel",
"Historical"
],
"published_year": 1925,
"title": "The Great Gatsby"
},
{
"author": "Harper Lee",
"available": false,
"genres": ["Novel", "Southern Gothic", "Bildungsroman"],
"genres": [
"Novel",
"Southern Gothic",
"Bildungsroman"
],
"published_year": 1960,
"title": "To Kill a Mockingbird"
},
{
"author": "George Orwell",
"available": true,
"genres": ["Dystopian", "Political Fiction"],
"genres": [
"Dystopian",
"Political Fiction"
],
"published_year": 1949,
"title": "1984"
}
]
]
6 changes: 3 additions & 3 deletions samples/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
allowed_hosts:
- localhost
- example.com
- api.example.com
- localhost
- example.com
- api.example.com
app_config:
debug_mode: false
environment: production
Expand Down
4 changes: 2 additions & 2 deletions samples/config_2.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
allowed_hosts:
- example.com
- api.example.com
- example.com
- api.example.com
app_config:
debug_mode: false
environment: production
Expand Down
18 changes: 9 additions & 9 deletions samples/people.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
name: Alice Johnson
role: Software Engineer
skills:
- Python
- Ruby
- JavaScript
- Python
- Ruby
- JavaScript
- department: Marketing
full_time: false
id: 102
name: Bob Smith
role: Marketing Specialist
skills:
- SEO
- Content Writing
- Social Media
- SEO
- Content Writing
- Social Media
- department: Human Resources
full_time: true
id: 103
name: Charlie Brown
role: HR Manager
skills:
- Recruitment
- Employee Relations
- Compliance
- Recruitment
- Employee Relations
- Compliance
Loading

0 comments on commit aacd4b0

Please sign in to comment.