jekyll-tsc 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/{jekyll_tsc.rb → jekyll-tsc.rb} +0 -0
- data/lib/jekyll/typescript/config.rb +9 -1
- data/lib/jekyll/typescript/manager.rb +16 -14
- data/lib/jekyll/typescript/mancache.rb +79 -0
- data/lib/jekyll/typescript/tsconfig.rb +0 -15
- data/lib/jekyll/typescript/version.rb +1 -1
- metadata +20 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184b75117bbd184b30e19a72389e5f48ca8faaa997017ab79e813897d3230461
|
4
|
+
data.tar.gz: 374ce6d9292b11c029bbb19530bf14936a5ba6e379e0677deac86c7c960667a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1cdea38df605bfed34269cdb7cf3e49f38d5c1ba4c971d40d02c883ae47c284e8075de9f90b6abf5e106b7745a81cc6644b6122227bad24e5d36f146f41cc2
|
7
|
+
data.tar.gz: b6dd17b86e2f594e91359f8f554804bfdef5b7261d18e36443628425aaf2200ecf1fb4251fd267562fd4993699adca05fcdf7ea3cece4c63caf652dedbf7ae46
|
File without changes
|
@@ -25,10 +25,18 @@ module Jekyll
|
|
25
25
|
@tsc_command ||= Array(config['command']) || ['tsc']
|
26
26
|
end
|
27
27
|
|
28
|
+
def cache_enabled?
|
29
|
+
if @cache_enabled.nil?
|
30
|
+
@cache_enabled = config.fetch('cache', true)
|
31
|
+
end
|
32
|
+
|
33
|
+
@cache_enabled
|
34
|
+
end
|
35
|
+
|
28
36
|
private
|
29
37
|
|
30
38
|
def config
|
31
|
-
@config ||= site.config['typescript']
|
39
|
+
@config ||= site.config['typescript'] || {}
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
@@ -5,6 +5,7 @@ require 'fileutils'
|
|
5
5
|
require 'shellwords'
|
6
6
|
require_relative './config'
|
7
7
|
require_relative './tsconfig'
|
8
|
+
require_relative './mancache'
|
8
9
|
|
9
10
|
module Jekyll
|
10
11
|
module Typescript
|
@@ -13,8 +14,9 @@ module Jekyll
|
|
13
14
|
SyntaxError = Class.new(ArgumentError)
|
14
15
|
|
15
16
|
include ::Singleton
|
16
|
-
include Config
|
17
|
+
include Config # jekyll config
|
17
18
|
include TSConfig
|
19
|
+
prepend ManagerCache
|
18
20
|
|
19
21
|
# whether :ext is associated with a typescript extension.
|
20
22
|
#
|
@@ -61,8 +63,6 @@ module Jekyll
|
|
61
63
|
def pre_render(site, _)
|
62
64
|
self.site = site
|
63
65
|
@pages = []
|
64
|
-
Jekyll.logger.debug('Typescript', 'clearing out temporary build directory.')
|
65
|
-
FileUtils.rm_rf(Dir.glob(File.join(temp_dir, '*')))
|
66
66
|
end
|
67
67
|
|
68
68
|
# Typescript hook run after a page has been rendered. This is used to add a
|
@@ -73,19 +73,26 @@ module Jekyll
|
|
73
73
|
@pages << page if copy_ext? page.ext
|
74
74
|
end
|
75
75
|
|
76
|
+
def page_to_output_path(page)
|
77
|
+
# TODO only change the extension of .ts files.
|
78
|
+
File.join(temp_dir,
|
79
|
+
File.dirname(page.relative_path),
|
80
|
+
File.basename(page.relative_path, '.*') + '.js')
|
81
|
+
end
|
82
|
+
|
76
83
|
# Once all the site files have been processed, compile and replace the content
|
77
84
|
# of any typescript files.
|
78
85
|
#
|
79
86
|
def post_render(*args)
|
80
87
|
setup
|
81
88
|
|
89
|
+
Jekyll.logger.debug('Typescript', 'clearing out temporary build directory.')
|
90
|
+
FileUtils.rm_rf(Dir.glob(File.join(temp_dir, '*')))
|
91
|
+
|
82
92
|
populate_temp_dir
|
83
|
-
@pages.each do |page|
|
93
|
+
@pages.select.each do |page|
|
84
94
|
next unless typescript_ext? page.ext
|
85
95
|
|
86
|
-
# change the output extension. it's a hack... but it works so good enough.
|
87
|
-
page.send(:_renderer).instance_variable_set(:@output_ext, '.js')
|
88
|
-
|
89
96
|
command = compile_command(in_temp_dir(page.relative_path))
|
90
97
|
Jekyll.logger.debug('Typescript') {
|
91
98
|
"running compile command: #{Shellwords.join(command[1..])}" }
|
@@ -95,11 +102,7 @@ module Jekyll
|
|
95
102
|
raise SyntaxError, "typescript failed to convert: #{page.path}\n" + compile_output
|
96
103
|
end
|
97
104
|
|
98
|
-
|
99
|
-
File.dirname(page.relative_path),
|
100
|
-
File.basename(page.relative_path, '.*') + '.js')
|
101
|
-
|
102
|
-
page.output = File.open(output_file, 'r', &:read)
|
105
|
+
page.output = File.read(page_to_output_path(page))
|
103
106
|
end
|
104
107
|
end
|
105
108
|
|
@@ -116,7 +119,6 @@ module Jekyll
|
|
116
119
|
def populate_temp_dir
|
117
120
|
Dir.chdir(temp_dir) do
|
118
121
|
(@pages + static_files).each do |page|
|
119
|
-
|
120
122
|
if page.is_a?(StaticFile)
|
121
123
|
FileUtils.mkdir_p('./' + page.instance_variable_get(:@dir))
|
122
124
|
FileUtils.copy(site.in_source_dir(page.relative_path),
|
@@ -141,7 +143,7 @@ module Jekyll
|
|
141
143
|
unless @tsconfig_args
|
142
144
|
config_file = 'tsconfig.json'
|
143
145
|
|
144
|
-
@tsconfig_args = if File.
|
146
|
+
@tsconfig_args = if File.exist?(config_file)
|
145
147
|
parse_tsconfig(dumb_read_json(config_file))
|
146
148
|
else
|
147
149
|
Jekyll.logger.warn('Typescript', "no config file found at #{config_file}")
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest/md5'
|
4
|
+
|
5
|
+
module Jekyll
|
6
|
+
module Typescript
|
7
|
+
# caches files involved in typescript conversions, using their hash
|
8
|
+
# and only start a new compilation if the result hash has changed
|
9
|
+
# since the last compilation.
|
10
|
+
#
|
11
|
+
module ManagerCache
|
12
|
+
def post_render(*args)
|
13
|
+
if !cache_enabled?
|
14
|
+
super
|
15
|
+
elsif pages_modified?
|
16
|
+
super
|
17
|
+
update_cache
|
18
|
+
else
|
19
|
+
set_pages_from_cache
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def pages_modified?
|
26
|
+
# avoid comparing hashes and assume compilation has to happen when
|
27
|
+
# there is no cache, or the number of files involved in the compilation
|
28
|
+
# has changed.
|
29
|
+
return true if conversion_cache.empty? ||
|
30
|
+
conversion_cache.size != pages.size + static_files.size
|
31
|
+
|
32
|
+
(pages + static_files).each do |page|
|
33
|
+
# no hash registered for the current file
|
34
|
+
cached_hash = conversion_cache[page.relative_path]
|
35
|
+
return true unless cached_hash
|
36
|
+
|
37
|
+
# recompile when the output of compilation doesn't exist.
|
38
|
+
return true unless File.exist?(page_to_output_path(page))
|
39
|
+
|
40
|
+
# content of page has been modified.
|
41
|
+
new_hash = Digest::MD5.hexdigest(get_content(page))
|
42
|
+
return true if new_hash != cached_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_content(page)
|
49
|
+
if page.is_a?(StaticFile)
|
50
|
+
File.read(page.path)
|
51
|
+
else
|
52
|
+
page.content
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_cache
|
57
|
+
@conversion_cache = {}
|
58
|
+
|
59
|
+
(pages + static_files).each do |page|
|
60
|
+
hash = Digest::MD5.hexdigest(get_content(page))
|
61
|
+
conversion_cache[page.relative_path] = hash
|
62
|
+
end
|
63
|
+
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_pages_from_cache
|
68
|
+
Jekyll.logger.debug('Typescript') {
|
69
|
+
'restoring javascript files from compilation cache.' }
|
70
|
+
|
71
|
+
pages.each { |page| page.output = File.read(page_to_output_path(page)) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def conversion_cache
|
75
|
+
@conversion_cache ||= {}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -4,9 +4,6 @@ module Jekyll
|
|
4
4
|
module Typescript
|
5
5
|
# Module providing methods to aid in the parsing of tsconfig.json files.
|
6
6
|
#
|
7
|
-
# WARN, some of this file is basically me ranting about how absurd tsc
|
8
|
-
# and some of the general web app standards are, as a Unix lover.
|
9
|
-
#
|
10
7
|
module TSConfig
|
11
8
|
# Parse a tsconfig.json JSON object into an array of equivalent commands
|
12
9
|
# line flags.
|
@@ -41,18 +38,6 @@ module Jekyll
|
|
41
38
|
|
42
39
|
# read a json file at :path, but allow for comments in the file.
|
43
40
|
#
|
44
|
-
# RANT
|
45
|
-
# Why in the great stallmans name does everyone use JSON as a config
|
46
|
-
# format when it doesn't support comments?
|
47
|
-
#
|
48
|
-
# RANT
|
49
|
-
# Why in gods name does JSON forbid comments when their pretty much
|
50
|
-
# ubiquotous?
|
51
|
-
#
|
52
|
-
# Adding an option to most parsers to allow comments doesn't seem too
|
53
|
-
# unreasonable, I mean it's not like JSON is solely used as a web
|
54
|
-
# interchange format anymore.
|
55
|
-
#
|
56
41
|
def dumb_read_json(path)
|
57
42
|
File.open(path, 'r') do |file|
|
58
43
|
# regxp partially sourced from https://stackoverflow.com/questions/19910002/remove-comments-from-json-data
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-tsc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mohsin Kaleem
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,26 +58,27 @@ dependencies:
|
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '3.9'
|
55
|
-
description: |
|
56
|
-
|
57
|
-
|
61
|
+
description: |2
|
62
|
+
provides automatic compilation of typescript files to javascript
|
63
|
+
files for your jekyll blog.
|
58
64
|
email: mohkalsin@gmail.com
|
59
65
|
executables: []
|
60
66
|
extensions: []
|
61
67
|
extra_rdoc_files: []
|
62
68
|
files:
|
69
|
+
- lib/jekyll-tsc.rb
|
63
70
|
- lib/jekyll/typescript/config.rb
|
64
71
|
- lib/jekyll/typescript/converter.rb
|
65
72
|
- lib/jekyll/typescript/generator.rb
|
66
73
|
- lib/jekyll/typescript/manager.rb
|
74
|
+
- lib/jekyll/typescript/mancache.rb
|
67
75
|
- lib/jekyll/typescript/tsconfig.rb
|
68
76
|
- lib/jekyll/typescript/version.rb
|
69
|
-
|
70
|
-
homepage:
|
77
|
+
homepage:
|
71
78
|
licenses:
|
72
79
|
- MIT
|
73
80
|
metadata: {}
|
74
|
-
post_install_message:
|
81
|
+
post_install_message:
|
75
82
|
rdoc_options: []
|
76
83
|
require_paths:
|
77
84
|
- lib
|
@@ -86,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
93
|
- !ruby/object:Gem::Version
|
87
94
|
version: '0'
|
88
95
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
90
|
-
signing_key:
|
96
|
+
rubygems_version: 3.1.3
|
97
|
+
signing_key:
|
91
98
|
specification_version: 4
|
92
99
|
summary: compile typescript files on your jekyll blog.
|
93
100
|
test_files: []
|