pandoc_wasm 1.0.0

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.
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'fileutils'
6
+ require 'uri'
7
+
8
+ module PandocWasm
9
+ class Downloader
10
+ REPO_OWNER = 'NathanHimpens'
11
+ REPO_NAME = 'pandoc-wasm'
12
+ ASSET_NAME = 'pandoc.wasm'
13
+
14
+ def self.wasm_path
15
+ File.join(File.dirname(__FILE__), ASSET_NAME)
16
+ end
17
+
18
+ # Download pandoc.wasm from GitHub Releases if it doesn't exist
19
+ def self.download_if_needed
20
+ return if File.exist?(wasm_path)
21
+
22
+ puts "pandoc.wasm not found. Attempting to download from GitHub Releases..."
23
+ download
24
+ end
25
+
26
+ # Download pandoc.wasm from the latest GitHub release
27
+ def self.download
28
+ begin
29
+ tag = get_latest_release_tag
30
+ download_asset(tag)
31
+ rescue StandardError => e
32
+ warn "Error downloading pandoc.wasm: #{e.message}"
33
+ warn "\nYou can:"
34
+ warn "1. Build it yourself following the instructions in README.md"
35
+ warn "2. Manually download it from a GitHub release"
36
+ warn "3. Copy it from the build directory after compilation"
37
+ warn "\n⚠️ Installation will continue, but pandoc.wasm must be added manually."
38
+ false
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ # Get the latest release tag from GitHub API
45
+ def self.get_latest_release_tag
46
+ uri = URI("https://api.github.com/repos/#{REPO_OWNER}/#{REPO_NAME}/releases/latest")
47
+
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ http.use_ssl = true
50
+ http.read_timeout = 30
51
+
52
+ request = Net::HTTP::Get.new(uri)
53
+ request['User-Agent'] = 'pandoc-wasm-ruby-downloader'
54
+ request['Accept'] = 'application/vnd.github.v3+json'
55
+
56
+ response = http.request(request)
57
+
58
+ case response.code
59
+ when '200'
60
+ release = JSON.parse(response.body)
61
+ release['tag_name']
62
+ when '404'
63
+ # No releases yet, try to use version from gem
64
+ version = PandocWasm::VERSION
65
+ puts "No GitHub release found. Using version #{version} from gem."
66
+ "v#{version}"
67
+ else
68
+ raise "GitHub API returned status #{response.code}: #{response.body}"
69
+ end
70
+ end
71
+
72
+ # Download the asset from GitHub Releases
73
+ def self.download_asset(tag)
74
+ # Get release info to find asset URL
75
+ uri = URI("https://api.github.com/repos/#{REPO_OWNER}/#{REPO_NAME}/releases/tags/#{tag}")
76
+
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+ http.use_ssl = true
79
+ http.read_timeout = 30
80
+
81
+ request = Net::HTTP::Get.new(uri)
82
+ request['User-Agent'] = 'pandoc-wasm-ruby-downloader'
83
+ request['Accept'] = 'application/vnd.github.v3+json'
84
+
85
+ response = http.request(request)
86
+
87
+ case response.code
88
+ when '404'
89
+ puts "Release #{tag} not found on GitHub. Skipping download."
90
+ puts 'You can manually download pandoc.wasm from the repository or build it yourself.'
91
+ return false
92
+ when '200'
93
+ # Continue
94
+ else
95
+ raise "GitHub API returned status #{response.code}: #{response.body}"
96
+ end
97
+
98
+ release = JSON.parse(response.body)
99
+ asset = release['assets'].find { |a| a['name'] == ASSET_NAME }
100
+
101
+ unless asset
102
+ puts "Asset #{ASSET_NAME} not found in release #{tag}."
103
+ puts 'You can manually download pandoc.wasm from the repository or build it yourself.'
104
+ return false
105
+ end
106
+
107
+ # Download the asset
108
+ puts "Downloading #{ASSET_NAME} from release #{tag}..."
109
+ puts "Size: #{(asset['size'] / 1024.0 / 1024.0).round(2)} MB"
110
+
111
+ download_uri = URI(asset['browser_download_url'])
112
+ download_http = Net::HTTP.new(download_uri.host, download_uri.port)
113
+ download_http.use_ssl = true
114
+ download_http.read_timeout = 300 # 5 minutes for large file
115
+
116
+ download_request = Net::HTTP::Get.new(download_uri)
117
+ download_request['User-Agent'] = 'pandoc-wasm-ruby-downloader'
118
+ download_request['Accept'] = 'application/octet-stream'
119
+
120
+ FileUtils.mkdir_p(File.dirname(wasm_path))
121
+
122
+ File.open(wasm_path, 'wb') do |file|
123
+ download_http.request(download_request) do |response|
124
+ case response.code
125
+ when '200'
126
+ response.read_body do |chunk|
127
+ file.write(chunk)
128
+ end
129
+ else
130
+ FileUtils.rm_f(wasm_path)
131
+ raise "Failed to download asset: #{response.code}"
132
+ end
133
+ end
134
+ end
135
+
136
+ # Make executable
137
+ File.chmod(0o755, wasm_path)
138
+ puts "✓ Successfully downloaded #{ASSET_NAME}"
139
+ true
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PandocWasm
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'pandoc_wasm/version'
4
+ require_relative 'pandoc_wasm/downloader'
5
+
6
+ module PandocWasm
7
+ class Error < StandardError; end
8
+
9
+ # Get the path to the pandoc.wasm binary
10
+ #
11
+ # @return [String] The absolute path to pandoc.wasm
12
+ def self.path
13
+ wasm_path = File.join(File.dirname(__FILE__), 'pandoc_wasm', 'pandoc.wasm')
14
+
15
+ # If the file doesn't exist, try to download it
16
+ unless File.exist?(wasm_path)
17
+ Downloader.download_if_needed
18
+ end
19
+
20
+ wasm_path
21
+ end
22
+
23
+ # Check if pandoc.wasm is available
24
+ #
25
+ # @return [Boolean] true if pandoc.wasm exists
26
+ def self.available?
27
+ File.exist?(path)
28
+ end
29
+
30
+ # Get the absolute path to pandoc.wasm
31
+ #
32
+ # @return [String] The absolute path to pandoc.wasm
33
+ def self.absolute_path
34
+ File.expand_path(path)
35
+ end
36
+ end
data/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@nathanhimpens/pandoc-wasm",
3
+ "version": "1.0.0",
4
+ "description": "Pandoc 3.8.3 compiled to WebAssembly for document conversion in WASI environments",
5
+ "main": "index.js",
6
+ "type": "commonjs",
7
+ "scripts": {
8
+ "postinstall": "node lib/download.js"
9
+ },
10
+ "keywords": [
11
+ "pandoc",
12
+ "wasm",
13
+ "wasi",
14
+ "document",
15
+ "conversion",
16
+ "markdown",
17
+ "html",
18
+ "pptx",
19
+ "docx"
20
+ ],
21
+ "author": "",
22
+ "license": "GPL-2.0-or-later",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/NathanHimpens/pandoc-wasm.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/NathanHimpens/pandoc-wasm/issues"
29
+ },
30
+ "homepage": "https://github.com/NathanHimpens/pandoc-wasm#readme",
31
+ "engines": {
32
+ "node": ">=14.0.0"
33
+ },
34
+ "files": [
35
+ "index.js",
36
+ "lib/",
37
+ "README.md"
38
+ ]
39
+ }
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/pandoc_wasm/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'pandoc_wasm'
7
+ spec.version = PandocWasm::VERSION
8
+ spec.authors = ['Nathan Himpens']
9
+ spec.email = ['']
10
+
11
+ spec.summary = 'Pandoc 3.8.3 compiled to WebAssembly for document conversion in WASI environments'
12
+ spec.description = 'Pandoc 3.8.3 compiled to WebAssembly for document conversion in WASI environments'
13
+ spec.homepage = 'https://github.com/NathanHimpens/pandoc-wasm'
14
+ spec.license = 'GPL-2.0-or-later'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/NathanHimpens/pandoc-wasm'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/NathanHimpens/pandoc-wasm/blob/main/README.md'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (File.expand_path(f) == __FILE__) ||
24
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github .cursor .ralph dist-newstyle/ patches/ tests/])
25
+ end
26
+ end
27
+
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # Ruby standard library dependencies (no external gems needed)
33
+ spec.required_ruby_version = '>= 2.7.0'
34
+
35
+ # Post-install message
36
+ spec.post_install_message = <<~MSG
37
+ pandoc_wasm installed successfully!
38
+
39
+ Note: pandoc.wasm will be automatically downloaded from GitHub Releases
40
+ the first time you call PandocWasm.path in your code.
41
+
42
+ If no GitHub release exists yet, you'll need to:
43
+ 1. Build pandoc.wasm yourself (see README.md)
44
+ 2. Create a GitHub release with pandoc.wasm attached
45
+ 3. Or manually copy pandoc.wasm to the gem directory
46
+ MSG
47
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pandoc_wasm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Himpens
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Pandoc 3.8.3 compiled to WebAssembly for document conversion in WASI
13
+ environments
14
+ email:
15
+ - ''
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".npmignore"
21
+ - RALPH_TASK.md
22
+ - README.md
23
+ - Rakefile
24
+ - SECURITY.md
25
+ - cabal.project
26
+ - index.js
27
+ - lib/download.js
28
+ - lib/pandoc_wasm.rb
29
+ - lib/pandoc_wasm/downloader.rb
30
+ - lib/pandoc_wasm/version.rb
31
+ - package.json
32
+ - pandoc_wasm.gemspec
33
+ homepage: https://github.com/NathanHimpens/pandoc-wasm
34
+ licenses:
35
+ - GPL-2.0-or-later
36
+ metadata:
37
+ homepage_uri: https://github.com/NathanHimpens/pandoc-wasm
38
+ source_code_uri: https://github.com/NathanHimpens/pandoc-wasm
39
+ changelog_uri: https://github.com/NathanHimpens/pandoc-wasm/blob/main/README.md
40
+ post_install_message: |
41
+ pandoc_wasm installed successfully!
42
+
43
+ Note: pandoc.wasm will be automatically downloaded from GitHub Releases
44
+ the first time you call PandocWasm.path in your code.
45
+
46
+ If no GitHub release exists yet, you'll need to:
47
+ 1. Build pandoc.wasm yourself (see README.md)
48
+ 2. Create a GitHub release with pandoc.wasm attached
49
+ 3. Or manually copy pandoc.wasm to the gem directory
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.7.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.6.7
65
+ specification_version: 4
66
+ summary: Pandoc 3.8.3 compiled to WebAssembly for document conversion in WASI environments
67
+ test_files: []