Skip to content

Commit

Permalink
Allow specifying --current or --lts
Browse files Browse the repository at this point in the history
  • Loading branch information
pmq20 committed Aug 30, 2020
1 parent 06f6e0f commit 94dca7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
19 changes: 11 additions & 8 deletions README.md
Expand Up @@ -19,7 +19,7 @@ http://enclose.io/nodec

## Supported Node.js Versions

We maintain support for both the latest *Current* Node.js release and the latest *LTS* Node.js release. Currently the `master` branch has been updated to the following versions.
We maintain support for both the latest Current Node.js release and the latest LTS Node.js release. At the moment, the `master` branch has been updated to support the following Node.js versions.

| | Master Branch Updated to | How to Use |
|:---------------------:|:--------------------------:|:-----------------------------------:|
Expand Down Expand Up @@ -127,24 +127,27 @@ The original maintainer did not specify how to build this repo into single execu
## Usage

nodec [OPTION]... [ENTRANCE]
--current Uses the current Node.js release
--lts Uses the LTS Node.js release
-r, --root=DIR Specifies the path to the root of the application
-o, --output=FILE Specifies the path of the output file
--output=FILE Specifies the path of the output file
-d, --tmpdir=DIR Specifies the directory for temporary files
--clean-tmpdir Cleans all temporary files that were generated last time
--keep-tmpdir Keeps all temporary files that were generated last time
--make-args=ARGS Passes extra arguments to make
--vcbuild-args=ARGS Passes extra arguments to vcbuild.bat
-n, --npm=FILE Specifies the path of npm
--skip-npm-install Skips the npm install process
--auto-update-url=URL Enables auto-update and specifies the URL to get the latest version
--auto-update-base=STRING Enables auto-update and specifies the base version string
--debug Enable debug mode
-o, --dest-os=OS Destination operating system (enum: win mac solaris freebsd openbsd linux android aix)
-a, --dest-arch=ARCH Destination CPU architecture (enum: arm arm64 ia32 mips mipsel ppc ppc64 x32 x64 x86 s390 s390x)
--quiet Enable quiet mode
--debug Enables debug mode
-o, --dest-os=OS Specifies the destination operating system (enum: win mac solaris freebsd openbsd linux android aix)
-a, --dest-arch=ARCH Specifies the destination CPU architecture (enum: arm arm64 ia32 mips mipsel ppc ppc64 x32 x64 x86 s390 s390x)
--quiet Enables quiet mode
-v, --version Prints the version of nodec and exit
-V, --node-version Prints the version of the Node.js runtime and exit
-h, --help Prints this help and exit

Note: if `ENTRANCE` was not provided, then a single Node.js interpreter executable will be produced.
Note: if ENTRANCE was not provided, a single raw Node.js interpreter executable would be produced.

Note: To compile to 32-bit windows OS compatible programs on a 64-bit machine, you should use a x64 x32 cross compiling environment. You should be able to find it in your Start Menu after installing Visual Studio. Also, you have to use a 32-bit Node.js, because the arch information is detected via `node -pe process.arch`.

Expand Down
24 changes: 13 additions & 11 deletions bin/nodec
Expand Up @@ -6,9 +6,11 @@
# This file is part of Node.js Packer, distributed under the MIT License
# For full terms see the included LICENSE file

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)

require 'compiler'
require_relative '../lib/compiler'
require 'optparse'

# took directly from https://github.com/nodejs/node/blob/master/configure#L47,L50
Expand All @@ -31,7 +33,7 @@ EXAMPLES = %{
Note
If `ENTRANCE` was not provided, then a single Node.js interpreter executable will be produced.
If ENTRANCE was not provided, a single raw Node.js interpreter executable would be produced.
Examples
Expand Down Expand Up @@ -63,6 +65,14 @@ end
OptionParser.new do |opts|
opts.banner = USAGE

opts.on('--current', 'Uses the current Node.js release') do
options[:current] = true
end

opts.on('--lts', 'Uses the LTS Node.js release') do
options[:lts] = true
end

opts.on('-rDIR', '--root=DIR', 'Specifies the path to the root of the application') do |dir|
options[:root] = dir
end
Expand Down Expand Up @@ -107,14 +117,6 @@ OptionParser.new do |opts|
options[:auto_update_base] = string
end

opts.on('--current', 'Uses the current Node.js release') do
options[:current] = true
end

opts.on('--lts', 'Uses the LTS Node.js release') do
options[:lts] = true
end

opts.on('--debug', 'Enables debug mode') do
options[:debug] = true
end
Expand Down
15 changes: 10 additions & 5 deletions lib/compiler.rb
Expand Up @@ -5,9 +5,10 @@
# This file is part of Node.js Packer, distributed under the MIT License
# For full terms see the included LICENSE file

require 'compiler/constants'
require 'compiler/error'
require 'compiler/utils'
require_relative './compiler/constants'
require_relative './compiler/error'
require_relative './compiler/utils'

require 'shellwords'
require 'tmpdir'
require 'fileutils'
Expand Down Expand Up @@ -60,8 +61,12 @@ def init_entrance_and_root
end

def init_options
@current_or_lts = 'current'
raise Error, 'Please specify either --current or --lts' if @options[:current] && @options[:lts]
@current_or_lts = 'lts' if @options[:lts]

@options[:npm] ||= 'npm'
@node_dir = "node-#{VERSION}"
@node_dir = "node-#{VERSION}-#{@current_or_lts}"
@options[:make_args] ||= '-j4'
@options[:vcbuild_args] ||= `node -pe process.arch`.to_s.strip
@options[:output] ||= if Gem.win_platform?
Expand Down Expand Up @@ -91,7 +96,7 @@ def stuff_tmpdir
@utils.rm_rf(@options[:tmpdir]) if @options[:clean_tmpdir]
@utils.mkdir_p(@options[:tmpdir])
@tmpdir_node = File.join(@options[:tmpdir], @node_dir)
@utils.cp_r(File.join(PRJ_ROOT, 'node'), @tmpdir_node, preserve: true) unless Dir.exist?(@tmpdir_node)
@utils.cp_r(File.join(PRJ_ROOT, @current_or_lts), @tmpdir_node, preserve: true) unless Dir.exist?(@tmpdir_node)
end

def run!
Expand Down

0 comments on commit 94dca7a

Please sign in to comment.