ts_schema 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/generate_generator.rb +17 -0
- data/lib/generators/templates/ts_schema.rb +22 -0
- data/lib/tasks/ts_schema_tasks.rake +9 -5
- data/lib/ts_schema/conversion_table.yml +1 -1
- data/lib/ts_schema/schema_generator.rb +13 -13
- data/lib/ts_schema/version.rb +1 -1
- data/lib/ts_schema.rb +5 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ca27c32ffaa091d17e4bc7dcc6f2f6cd17b090474c17194e41a865dc37a3df
|
4
|
+
data.tar.gz: 1e6e1a099da55952ff630cea38be5c00fc4082f4696ed26c7f4e8a805de11261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2a1a3fe335a598d6c134af21d739648ef005dbf80510b66c042d4c995bad8766db5cd702f15b30ecf6d1bba4ae051c151aa0dbd986d59be47632fd0b8cacb4
|
7
|
+
data.tar.gz: 0e3a43734a1214d4c11c4dbaa18cf8ce3527c99e796baa05d6eb41008424a7ee83742bb730dca5b3c410705f1f8fd7f16e82595f7fc03b11c8c26abcf7d9a49f
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/base'
|
5
|
+
|
6
|
+
module TsSchema
|
7
|
+
module Generators
|
8
|
+
class GenerateGenerator < Rails::Generators::Base
|
9
|
+
|
10
|
+
desc "Generates a schema.d.ts file"
|
11
|
+
|
12
|
+
def generate_schema
|
13
|
+
create_file TsSchema.configuration.output, TsSchema.generate
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -9,6 +9,28 @@ TsSchema.setup do |config|
|
|
9
9
|
# config.auto_generate = true
|
10
10
|
|
11
11
|
# Add custom type mappings or overrides
|
12
|
+
#
|
13
|
+
# Default type mappings:
|
14
|
+
#
|
15
|
+
# string: string
|
16
|
+
# text: string
|
17
|
+
# integer: number
|
18
|
+
# enum: number
|
19
|
+
# bigint: number
|
20
|
+
# float: number
|
21
|
+
# decimal: number
|
22
|
+
# json: Record<string, any>
|
23
|
+
# jsonb: Record<string, any>
|
24
|
+
# binary: string
|
25
|
+
# boolean: boolean
|
26
|
+
# date: string
|
27
|
+
# datetime: string
|
28
|
+
# timestamp: string
|
29
|
+
# datetime_with_timezone: string
|
30
|
+
# inet: string
|
31
|
+
# cidr: string
|
32
|
+
# macaddr: string
|
33
|
+
#
|
12
34
|
# config.custom_types = {
|
13
35
|
#
|
14
36
|
# }
|
@@ -3,24 +3,28 @@ require "rake"
|
|
3
3
|
namespace :ts_schema do
|
4
4
|
desc "Generates a schema file in the default javascripts location, or the location specified in the ts_config initializer options"
|
5
5
|
task :generate do
|
6
|
-
TsSchema.
|
6
|
+
TsSchema.output_file
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
namespace :db do
|
11
|
+
def auto_generate_and_save_file
|
12
|
+
TsSchema.output_file if TsSchema.configuration.auto_generate
|
13
|
+
end
|
14
|
+
|
11
15
|
task migrate: :environment do
|
12
|
-
|
16
|
+
auto_generate_and_save_file
|
13
17
|
end
|
14
18
|
|
15
19
|
task rollback: :environment do
|
16
|
-
|
20
|
+
auto_generate_and_save_file
|
17
21
|
end
|
18
22
|
|
19
23
|
task reset: :environment do
|
20
|
-
|
24
|
+
auto_generate_and_save_file
|
21
25
|
end
|
22
26
|
|
23
27
|
task setup: :environment do
|
24
|
-
|
28
|
+
auto_generate_and_save_file
|
25
29
|
end
|
26
30
|
end
|
@@ -9,8 +9,19 @@ module TsSchema
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def generate
|
12
|
-
|
13
|
-
|
12
|
+
generate_typescript
|
13
|
+
end
|
14
|
+
|
15
|
+
def output_file
|
16
|
+
path = TsSchema.configuration.output
|
17
|
+
FileUtils.mkdir_p(File.dirname(path))
|
18
|
+
|
19
|
+
content = generate
|
20
|
+
return if File.exist?(path) && File.read(path) == content
|
21
|
+
|
22
|
+
File.open(path, 'w') do |f|
|
23
|
+
f.write content
|
24
|
+
end
|
14
25
|
end
|
15
26
|
|
16
27
|
private
|
@@ -77,17 +88,6 @@ module TsSchema
|
|
77
88
|
end
|
78
89
|
end
|
79
90
|
|
80
|
-
def output_file(content)
|
81
|
-
path = TsSchema.configuration.output
|
82
|
-
FileUtils.mkdir_p(File.dirname(path))
|
83
|
-
|
84
|
-
return if File.exist?(path) && File.read(path) == content
|
85
|
-
|
86
|
-
File.open(path, 'w') do |f|
|
87
|
-
f.write content
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
91
|
def indent_as_str
|
92
92
|
case TsSchema.configuration.indent.to_sym
|
93
93
|
when :space || :spaces
|
data/lib/ts_schema/version.rb
CHANGED
data/lib/ts_schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ts_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avram Walden
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- MIT-LICENSE
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
|
+
- lib/generators/generate_generator.rb
|
43
44
|
- lib/generators/install_generator.rb
|
44
45
|
- lib/generators/templates/ts_schema.rb
|
45
46
|
- lib/tasks/ts_schema_tasks.rake
|