Skip to content

Commit

Permalink
Add timestamp to routes file banner
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 19, 2024
1 parent 5b0ca77 commit 9f658cf
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v2.3.1

* Add timestamp on when routes where generated into banner

## v2.3.0

* Drop support of Rails 4.x
Expand Down
5 changes: 2 additions & 3 deletions lib/js_routes/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ def remove!

sig { returns(T::Hash[String, String]) }
def js_variables
version = Rails.version
prefix = @configuration.prefix
prefix = prefix.call if prefix.is_a?(Proc)
{
'GEM_VERSION' => JsRoutes::VERSION,
'TIMESTAMP' => Time.now.to_s,
'ROUTES_OBJECT' => routes_object,
'RAILS_VERSION' => ::Rails.version,
'DEPRECATED_GLOBBING_BEHAVIOR' => version >= '4.0.0' && version < '4.1.0',
'DEPRECATED_FALSE_PARAMETER_BEHAVIOR' => version < '7.0.0',
'DEPRECATED_FALSE_PARAMETER_BEHAVIOR' => Rails.version < '7.0.0',
'APP_CLASS' => application.class.to_s,
'DEFAULT_URL_OPTIONS' => json(@configuration.default_url_options),
'PREFIX' => json(prefix),
Expand Down
3 changes: 1 addition & 2 deletions lib/routes.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* File generated by js-routes RubyVariables.GEM_VERSION
* File generated by js-routes RubyVariables.GEM_VERSION on RubyVariables.TIMESTAMP
* Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
*/
declare type Optional<T> = {
Expand Down Expand Up @@ -64,7 +64,6 @@ declare type PartsTable = Collection<{
declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
declare const RubyVariables: {
PREFIX: string;
DEPRECATED_GLOBBING_BEHAVIOR: boolean;
DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
SPECIAL_OPTIONS_KEY: string;
DEFAULT_URL_OPTIONS: RouteParameters;
Expand Down
6 changes: 2 additions & 4 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* File generated by js-routes RubyVariables.GEM_VERSION
* File generated by js-routes RubyVariables.GEM_VERSION on RubyVariables.TIMESTAMP
* Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
*/
// eslint-disable-next-line
Expand Down Expand Up @@ -415,9 +415,7 @@ RubyVariables.WRAPPER(
value = value.join("/");
}
const result = this.path_identifier(value);
return RubyVariables.DEPRECATED_GLOBBING_BEHAVIOR
? result
: encodeURI(result);
return encodeURI(result);
}
get_prefix() {
const prefix = this.configuration.prefix;
Expand Down
7 changes: 2 additions & 5 deletions lib/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* File generated by js-routes RubyVariables.GEM_VERSION
* File generated by js-routes RubyVariables.GEM_VERSION on RubyVariables.TIMESTAMP
* Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
*/

Expand Down Expand Up @@ -82,7 +82,6 @@ type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";

declare const RubyVariables: {
PREFIX: string;
DEPRECATED_GLOBBING_BEHAVIOR: boolean;
DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
SPECIAL_OPTIONS_KEY: string;
DEFAULT_URL_OPTIONS: RouteParameters;
Expand Down Expand Up @@ -606,9 +605,7 @@ RubyVariables.WRAPPER(
value = value.join("/");
}
const result = this.path_identifier(value as any);
return RubyVariables.DEPRECATED_GLOBBING_BEHAVIOR
? result
: encodeURI(result);
return encodeURI(result);
}

get_prefix(): string {
Expand Down
3 changes: 1 addition & 2 deletions spec/js_routes/module_types/dts/routes.spec.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* File generated by js-routes RubyVariables.GEM_VERSION
* File generated by js-routes RubyVariables.GEM_VERSION on RubyVariables.TIMESTAMP
* Based on Rails RubyVariables.RAILS_VERSION routes of RubyVariables.APP_CLASS
*/
declare type Optional<T> = {
Expand Down Expand Up @@ -64,7 +64,6 @@ declare type PartsTable = Collection<{
declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
declare const RubyVariables: {
PREFIX: string;
DEPRECATED_GLOBBING_BEHAVIOR: boolean;
DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
SPECIAL_OPTIONS_KEY: string;
DEFAULT_URL_OPTIONS: RouteParameters;
Expand Down
4 changes: 3 additions & 1 deletion spec/js_routes/module_types/umd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

it "should include a comment in the header" do
app_class = "App"
fixed_time = Time.new(2023, 11, 18, 10, 15, 20)
allow(Time).to receive(:now).and_return(fixed_time)

is_expected.to include("File generated by js-routes #{JsRoutes::VERSION}")
is_expected.to include("File generated by js-routes #{JsRoutes::VERSION} on #{fixed_time}")
is_expected.to include("Based on Rails #{Rails.version} routes of #{app_class}")
end

Expand Down
12 changes: 5 additions & 7 deletions spec/js_routes/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,12 @@
let(:_options) { {:default_url_options => {format: "json"}} }
let(:_warnings) { nil }

if Rails.version >= "5"
it "should render routing with default_format" do
expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
end
it "should render routing with default_format" do
expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
end

it "should render routing with default_format and zero object" do
expectjs("Routes.inbox_path(0)").to eq(test_routes.inbox_path(0))
end
it "should render routing with default_format and zero object" do
expectjs("Routes.inbox_path(0)").to eq(test_routes.inbox_path(0))
end

it "should override default_format when spefified implicitly" do
Expand Down
4 changes: 0 additions & 4 deletions spec/support/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ def draw_routes
get "(/sep1/:first_optional)/sep2/:second_required/sep3/:third_required(/:forth_optional)",
as: :thing_deep, controller: :things, action: :show

if Rails.version < "5.0.0"
get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
end

get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
get '/other_optional(/*optional_id)' => 'foo#foo', :as => :foo_all

Expand Down

0 comments on commit 9f658cf

Please sign in to comment.