diff --git a/README.md b/README.md
index 788fef8..98a2e77 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Rake tasks for working with loomlibs
loomlibs are linkable LoomScript code libraries used to expand features of the [Loom SDK][loomsdk].
-If you use [Rake][rake] and follow a consistent file layout across projects, these tasks can simplify the steps of setting up, building, installing, testing, demo-ing, and releasing loom libraries (`*.loomlib`).
+If you use [Rake][rake] and follow a consistent file layout across projects, these tasks can simplify the steps of setting up, building, installing, testing, demo-ing, documenting, and releasing loom libraries (`*.loomlib`).
The tasks install into your `.loom` directory, and can be loaded from there into the Rakefiles of your projects.
@@ -47,35 +47,39 @@ Clone this repo.
Running `rake` in your project directory will execute the default task, which prints the list of available tasks and a short description of what they do:
Foo v1.2.3 Rakefile running on Ruby 2.3.0
- rake clean # removes intermediate files to ensure a clean build
- rake cli[options] # shorthand for rake cli:run
- rake cli:build # builds cli/bin/FooDemoCLI.loom for sprint34 SDK
- rake cli:run[options] # executes cli/bin/FooDemoCLI.loom as a commandline app, with options, if provided
- rake cli:sdk[id] # sets the provided SDK version into cli/loom.config
- rake clobber # removes all generated artifacts to restore project to checkout-like state
- rake gui # shorthand for rake gui:run
- rake gui:build # builds gui/bin/FooDemoGUI.loom for sprint34 SDK
- rake gui:run # launches gui/bin/FooDemoGUI.loom as a GUI app
- rake gui:sdk[id] # sets the provided SDK version into gui/loom.config
- rake help # show detailed usage and project info
- rake lib:build # builds Foo.loomlib for sprint34 SDK
- rake lib:install # installs Foo.loomlib into sprint34 SDK
- rake lib:release # prepares sdk-specific Foo.loomlib for release, and updates version in README
- rake lib:sdk[id] # sets the provided SDK version into lib/loom.config
- rake lib:show # lists libs installed for sprint34 SDK
- rake lib:uninstall # removes Foo.loomlib from sprint34 SDK
- rake lib:version[v] # sets the library version number into lib/src/Foo.build and lib/src/Foo.ls
- rake list_sdks # lists loom sdk versions available use
- rake sdk[id] # sets the provided SDK version in the config files of lib, cli, gui, and test
- rake test # shorthand for rake test:run
- rake test:build # builds test/bin/FooTest.loom against sprint34 SDK
- rake test:ci # runs test/bin/FooTest.loom for CI
- rake test:run[seed] # runs test/bin/FooTest.loom for the console
- rake test:sdk[id] # sets the provided SDK version into test/loom.config
- rake version # reports loomlib version
- (using loomtasks v3.0.3)
-
-If you are looking for more detail on any of the tasks, use `rake help`.
+ rake clean # removes intermediate files to ensure a clean build
+ rake cli[options] # shorthand for rake cli:run
+ rake cli:build # builds cli/bin/FooDemoCLI.loom for sprint34 SDK
+ rake cli:install[b,p] # installs an executable copy of cli/bin/FooDemoCLI.loom on the system
+ rake cli:run[options] # executes cli/bin/FooDemoCLI.loom as a commandline app, with options, if provided
+ rake cli:sdk[id] # sets the provided SDK version into cli/loom.config
+ rake cli:uninstall[b,p] # uninstalls the path executable Foo
+ rake clobber # removes all generated artifacts to restore project to checkout-like state
+ rake docs # shorthand for rake docs:ghpages
+ rake docs:ghpages # creates docs ready for rendering by github pages, or jekyll
+ rake gui # shorthand for rake gui:run
+ rake gui:build # builds gui/bin/FooDemoGUI.loom for sprint34 SDK
+ rake gui:run # launches gui/bin/FooDemoGUI.loom as a GUI app
+ rake gui:sdk[id] # sets the provided SDK version into gui/loom.config
+ rake help # shows usage and project info, optionally for a specific command
+ rake lib:build # builds Foo.loomlib for sprint34 SDK
+ rake lib:install # installs Foo.loomlib into sprint34 SDK
+ rake lib:release # prepares sdk-specific Foo.loomlib for release, and updates version in README
+ rake lib:sdk[id] # sets the provided SDK version into lib/loom.config
+ rake lib:show # lists libs installed for sprint34 SDK
+ rake lib:uninstall # removes Foo.loomlib from sprint34 SDK
+ rake lib:version[v] # sets the library version number into lib/src/Foo.build and lib/src/Foo.ls
+ rake list_sdks # lists loom sdk versions available use
+ rake sdk[id] # sets the provided SDK version in the config files of lib, cli, gui, and test
+ rake test # shorthand for rake test:run
+ rake test:build # builds test/bin/FooTest.loom against sprint34 SDK
+ rake test:ci # runs test/bin/FooTest.loom for CI
+ rake test:run[seed] # runs test/bin/FooTest.loom for the console
+ rake test:sdk[id] # sets the provided SDK version into test/loom.config
+ rake version # reports loomlib version
+ (using loomtasks v3.1.0)
+
+If you are looking for more detail on any of the tasks, use `rake help`, e.g. `rake help test`.
The Rake tasks are defined with dependencies and modification triggers, so you can just run `rake test` every time you edit a source file, and the library and test app will be rebuilt as needed automatically.
@@ -89,6 +93,7 @@ The loomlib rake tasks make the following assumptions about the layout of a proj
foo-loomlib $
├─cli/
+ ├─doc/
├─gui/
├─lib/
├─Rakefile
@@ -96,10 +101,30 @@ The loomlib rake tasks make the following assumptions about the layout of a proj
* library source is under `lib/`
* source for a CLI demo is under `cli/`; the CLI demo app will consume the library and illustrate its use from the command line
+* documentation source is under `doc/`; [lsdoc][lsdoc] is the supported doc generation tool
* source for a GUI demo is under `gui/`; the GUI demo app will consume the library and illustrate its use via a graphical user interface
* the project uses a `Rakefile` for building, testing, and preparing releases
* library test source is under `test/`; the test app will consume the library and exercise it
-* [spec-ls][spec-ls] is the testing framework
+* [spec-ls][spec-ls] is the supported testing framework
+
+#### documentation
+
+Support for docs tasks comes from [`loomlib_doc.rake`](lib/tasks/rakefiles/loomlib_doc.rake).
+Use of [lsdoc][lsdoc] is assumed.
+
+`doc/` contains source files to be converted into documentation. The documentation is not packaged with the loomlib; it is generated into a `docs/` directory for [GitHub pages][gh-pages] to render. Note that this requires an option be set for the source code repository (see [Publishing from a docs/ folder][gh-docs]).
+
+ └─doc
+ ├─examples/
+ ├─guides/
+ ├─index.md
+ └─lsdoc.config
+
+* (optional) example pages are written under `doc/examples/`; they will have their own tab in the generated docs site
+* (optional) guide pages are written under `doc/examples/`; they will have their own tab in the generated docs site
+* project level configuration for lsdoc is defined in `doc/lsdoc.config`
+* the documentation home page is written in markdown as `doc/index.md`
+* [lsdoc][lsdoc] will use the data under `doc/` to create a site under `docs/` that GitHub Pages will render after it is pushed to your GitHub repository
#### demos
@@ -200,7 +225,10 @@ Use of [spec-ls][spec-ls] is assumed.
Pull requests are welcome!
-[gh-releases]: https://help.github.com/articles/about-releases/ "about GitHub releases"
+[gh-docs]: https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/#publishing-your-github-pages-site-from-a-docs-folder-on-your-master-branch "publishing your GitHub Pages site from a /docs folder on your master branch"
+[gh-pages]: https://pages.github.com/ "GitHub Pages is a static site hosting service."
+[gh-releases]: https://help.github.com/articles/about-releases/ "releases are GitHub's way of packaging and providing software to your users"
[loomsdk]: https://github.com/LoomSDK/LoomSDK "The Loom SDK, a native mobile app and game framework"
+[lsdoc]: https://github.com/pixeldroid/lsdoc "generate API documentation from doc comments in LoomScript source code"
[rake]: https://rubygems.org/gems/rake "Rake (Ruby make)"
-[spec-ls]: https://github.com/pixeldroid/spec-ls "spec-ls: a simple specification framework for loom"
+[spec-ls]: https://github.com/pixeldroid/spec-ls "a simple specification framework for loom"
diff --git a/Rakefile b/Rakefile
index a62988f..0cbc460 100644
--- a/Rakefile
+++ b/Rakefile
@@ -47,23 +47,36 @@ task :install do |t, args|
end
desc [
- "shows usage and project info",
+ "shows usage and project info, optionally for a specific command",
+ "usage: rake help",
+ " or: rake help ",
].join("\n")
task :help do |t, args|
- system("rake -D")
+ # avoid rake errors about undefined tasks; we want to pull args ourselves
+ ARGV.each do |a|
+ task a.to_sym do ; end
+ Rake::Task[a.to_sym].clear
+ end
+
+ cmd = ARGV.fetch(1, nil)
- puts "Log bugs to: https://github.com/pixeldroid/loomtasks/issues"
- puts "Project home page: https://github.com/pixeldroid/loomtasks"
- puts ''
- puts "Please see the README for additional details."
+ if (cmd)
+ system("rake -D #{cmd}")
+ else
+ system("rake -D")
+
+ puts "Log bugs to: https://github.com/pixeldroid/loomtasks/issues"
+ puts "Project home page: https://github.com/pixeldroid/loomtasks"
+ puts ''
+ puts "Please see the README for additional details."
+ end
end
desc [
- "reports loomtasks version",
+ "reports loomtasks version (v#{VERSION})",
].join("\n")
task :version do |t, args|
puts "loomtasks v#{VERSION}"
- puts ''
end
namespace :list do
@@ -105,7 +118,7 @@ end
desc [
"removes the tasks folder from the Loom home directory",
"the task folder is #{installed_tasks_dir}",
- "the entire tasks folder will be removed, so use with caution if you happened to put anything in there",
+ "the entire tasks folder will be removed, so use with caution if you added anything in there",
].join("\n")
task :uninstall do |t, args|
FileUtils.rm_r(installed_tasks_dir) if Dir.exists?(installed_tasks_dir)
diff --git a/lib/tasks/loomlib.rake b/lib/tasks/loomlib.rake
index 891af57..5cce1a1 100644
--- a/lib/tasks/loomlib.rake
+++ b/lib/tasks/loomlib.rake
@@ -80,16 +80,26 @@ task :list_targets => :check_consts do |t, args|
end
task :check_consts do |t, args|
- fail("please define the LIB_NAME constant before loading #{File.basename(__FILE__)}") unless LoomTasks.const_lib_name
- fail("please define the LIB_VERSION_FILE constant before loading #{File.basename(__FILE__)}") unless LoomTasks.const_lib_version_file
+ LoomTasks.fail("please define the LIB_NAME constant before loading #{File.basename(__FILE__)}") unless LoomTasks.const_lib_name
+ LoomTasks.fail("please define the LIB_VERSION_FILE constant before loading #{File.basename(__FILE__)}") unless LoomTasks.const_lib_version_file
end
desc [
- "show detailed usage and project info",
+ "shows usage and project info, optionally for a specific command",
+ "usage: rake help",
+ " or: rake help ",
].join("\n")
task :help do |t, args|
- system('rake -D')
+ # avoid rake errors about undefined tasks; we want to pull args ourselves
+ ARGV.each do |a|
+ task a.to_sym do ; end
+ Rake::Task[a.to_sym].clear
+ end
+
+ cmd = ARGV.fetch(1, nil)
+ system("rake -D #{cmd}") if (cmd)
+ system("rake -D") unless (cmd)
puts "Please see the README for additional details."
end
@@ -104,7 +114,7 @@ task :sdk, [:id] do |t, args|
sdk_version = args.id
lib_dir = LoomTasks.libs_path(sdk_version)
- fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
+ LoomTasks.fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
Rake::Task['lib:sdk'].invoke(sdk_version)
Rake::Task['cli:sdk'].invoke(sdk_version)
diff --git a/lib/tasks/rakefiles/loomlib_cli.rake b/lib/tasks/rakefiles/loomlib_cli.rake
index e5a8f31..6e8645b 100644
--- a/lib/tasks/rakefiles/loomlib_cli.rake
+++ b/lib/tasks/rakefiles/loomlib_cli.rake
@@ -19,6 +19,20 @@ def write_cli_config(config)
LoomTasks.write_loom_config(cli_config_file, config)
end
+def cli_wrapper()
+ ext = windows? ? 'bat' : 'sh'
+ File.join('cli', 'wrapper', "#{LoomTasks.const_lib_name}.#{ext}")
+end
+
+def cli_default_path_dir()
+ File.join(Dir.home, 'bin')
+end
+
+def cli_default_bin_dir()
+ File.join(Dir.home, '.loom', LoomTasks.const_lib_name)
+end
+
+
DEMO_CLI = File.join('cli', 'bin', "#{LoomTasks.const_lib_name}DemoCLI.loom")
[
@@ -33,7 +47,11 @@ file DEMO_CLI => LIBRARY do |t, args|
compile_demo('cli', "#{LoomTasks.const_lib_name}DemoCLI.build", cli_config)
end
-FileList[File.join('cli', 'src', '**', '*.ls')].each do |src|
+FileList[
+ File.join('cli', 'loom.config'),
+ File.join('cli', 'src', '*.build'),
+ File.join('cli', 'src', '**', '*.ls'),
+].each do |src|
file DEMO_CLI => src
end
@@ -50,6 +68,51 @@ namespace :cli do
puts "[#{t.name}] task completed, find .loom in cli/bin/"
end
+ desc [
+ "installs an executable copy of #{DEMO_CLI} on the system",
+ "the binary is renamed 'Main.loom' and stored under #{cli_default_bin_dir}; override with :b",
+ "a wrapper script is installed on the path at #{cli_default_path_dir}; override with :p",
+ ].join("\n")
+ task :install, [:b, :p] => DEMO_CLI do |t, args|
+ args.with_defaults(
+ :b => cli_default_bin_dir,
+ :p => cli_default_path_dir,
+ )
+
+ sdk_version = cli_config['sdk_version']
+ loomexec = LoomTasks.loomexec(sdk_version)
+ binary = t.prerequisites[0]
+
+ cli_bin_dir = args.b
+ cli_path_dir = args.p
+ target_bin = File.join(cli_bin_dir, LoomTasks.main_binary)
+ target_bin_dir = File.dirname(target_bin)
+ target_exe = File.join(cli_bin_dir, LoomTasks.const_lib_name)
+ target_wrapper = File.join(cli_path_dir, LoomTasks.const_lib_name)
+
+ if (Dir.exists?(cli_bin_dir))
+ puts "[#{t.name}] removing existing #{cli_bin_dir}..."
+ FileUtils.rm_r(cli_bin_dir)
+ end
+ puts "[#{t.name}] creating #{target_bin_dir}..."
+ FileUtils.mkdir_p(target_bin_dir) unless Dir.exists?(target_bin_dir)
+
+ puts "[#{t.name}] copying #{binary} into #{target_bin}..."
+ fail("could not find '#{binary}' to copy") unless File.exists?(binary)
+ FileUtils.cp(binary, target_bin)
+
+ puts "[#{t.name}] copying #{loomexec} into #{target_exe}..."
+ fail("could not find '#{loomexec}' to copy") unless File.exists?(loomexec)
+ FileUtils.cp(loomexec, target_exe)
+
+ puts "[#{t.name}] copying #{cli_wrapper} into #{target_wrapper}..."
+ fail("could not find '#{cli_wrapper}' to copy") unless File.exists?(cli_wrapper)
+ FileUtils.cp(cli_wrapper, target_wrapper)
+ FileUtils.chmod('u=wrx,go=rx', target_wrapper) # 755 on wrapper script to be executable for all, editable by user
+
+ puts "[#{t.name}] task completed, #{LoomTasks.const_lib_name} installed for use"
+ end
+
desc [
"executes #{DEMO_CLI} as a commandline app, with options, if provided",
"your demo application class should extend system.application.ConsoleApplication",
@@ -84,7 +147,7 @@ namespace :cli do
sdk_version = args.id
lib_dir = LoomTasks.libs_path(sdk_version)
- fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
+ LoomTasks.fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
cli_config['sdk_version'] = sdk_version
write_cli_config(cli_config)
@@ -92,6 +155,38 @@ namespace :cli do
puts "[#{t.name}] task completed, sdk updated to #{sdk_version}"
end
+ desc [
+ "uninstalls the path executable #{LoomTasks.const_lib_name}",
+ "the executable directory '#{cli_default_bin_dir}' is removed; override with :bin_dir",
+ "the wrapper shell script is removed from #{cli_default_path_dir}; override with :p",
+ ].join("\n")
+ task :uninstall, [:b, :p] do |t, args|
+ args.with_defaults(
+ :b => cli_default_bin_dir,
+ :p => cli_default_path_dir,
+ )
+ sdk_version = lib_config['sdk_version']
+ sdk_dir = LoomTasks.sdk_root(sdk_version)
+
+ cli_bin_dir = args.b
+ cli_path_dir = args.p
+
+ if (Dir.exists?(cli_bin_dir))
+ FileUtils.rm_r(cli_bin_dir)
+ puts "[#{t.name}] task completed, #{cli_bin_dir} removed"
+ else
+ puts "[#{t.name}] nothing to do; no #{cli_bin_dir} found"
+ end
+
+ installed_wrapper = File.join(cli_path_dir, LoomTasks.const_lib_name)
+ if (File.exists?(installed_wrapper))
+ FileUtils.rm_r(installed_wrapper)
+ puts "[#{t.name}] task completed, #{LoomTasks.const_lib_name} removed from #{cli_path_dir}"
+ else
+ puts "[#{t.name}] nothing to do; no #{LoomTasks.const_lib_name} found in #{cli_path_dir}"
+ end
+ end
+
end
desc [
diff --git a/lib/tasks/rakefiles/loomlib_doc.rake b/lib/tasks/rakefiles/loomlib_doc.rake
new file mode 100644
index 0000000..84f76d3
--- /dev/null
+++ b/lib/tasks/rakefiles/loomlib_doc.rake
@@ -0,0 +1,84 @@
+
+require 'fileutils'
+
+require File.join(File.dirname(__FILE__), 'support')
+include LoomTasks
+
+
+def build_docs(in_dir, out_dir)
+ sdk_version = lib_config['sdk_version']
+ sdk_dir = LoomTasks.sdk_root(sdk_version)
+ processor = 'ghpages'
+ template_dir = File.join(sdk_dir, 'ghpages-template')
+
+ options = [
+ "-p #{processor}",
+ "-t #{template_dir}",
+ "-l #{sdk_dir}/libs/#{LoomTasks.const_lib_name}.loomlib",
+ "-o #{out_dir}",
+ "-c #{in_dir}/lsdoc.config",
+ "-i #{in_dir}/index.md",
+ ]
+
+ examples_dir = File.join(in_dir, 'examples')
+ guides_dir = File.join(in_dir, 'guides')
+
+ options << "-e #{examples_dir}" if (Dir.exists?(examples_dir))
+ options << "-g #{guides_dir}" if (Dir.exists?(guides_dir))
+
+ cmd = "lsdoc #{options.join(' ')}"
+ try(cmd, "failed to generate docs")
+end
+
+LIB_DOC = 'docs'
+JEKYLL_CMD = 'jekyll serve -s docs/ -d docs-site -I'
+
+[
+ File.join('docs', '**'),
+].each { |f| CLEAN << f }
+[
+ 'docs',
+].each { |f| CLOBBER << f }
+
+FileList[
+ File.join('doc', '*.*'),
+].each do |src|
+ file LIB_DOC => src
+end
+
+namespace :docs do
+
+task :check_tools do |t, args|
+ LoomTasks.fail('lsdoc not installed. See https://github.com/pixeldroid/lsdoc') unless (LoomTasks.which('lsdoc'))
+end
+
+ desc [
+ "creates docs ready for rendering by github pages, or jekyll",
+ "requires lsdoc to be installed",
+ "expects user-generated documentation to be at doc/,",
+ "outputs GitHub pages compatible files at docs/,",
+ "if jekyll is installed, you can preview the doc site locally:",
+ " $ #{JEKYLL_CMD}",
+ ].join("\n")
+ task :ghpages => ['docs:check_tools', 'lib:install'] do |t, args|
+ pwd = Dir.pwd
+ in_dir = File.join(pwd, 'doc')
+ out_dir = File.join(pwd, 'docs')
+
+ if (Dir.exists?(out_dir))
+ FileUtils.rm_r(Dir.glob(File.join(out_dir, '*')))
+ puts "[#{t.name}] emptying #{out_dir} to start clean"
+ end
+
+ build_docs(in_dir, out_dir)
+
+ puts "[#{t.name}] task completed, docs generated into #{out_dir}"
+ puts "[#{t.name}] preview locally: #{JEKYLL_CMD}" if (LoomTasks.which('jekyll'))
+ end
+
+end
+
+desc [
+ "shorthand for rake docs:ghpages",
+].join("\n")
+task :docs => 'docs:ghpages'
diff --git a/lib/tasks/rakefiles/loomlib_gui.rake b/lib/tasks/rakefiles/loomlib_gui.rake
index 6669ff2..4d06cb0 100644
--- a/lib/tasks/rakefiles/loomlib_gui.rake
+++ b/lib/tasks/rakefiles/loomlib_gui.rake
@@ -33,7 +33,11 @@ file DEMO_GUI => LIBRARY do |t, args|
compile_demo('gui', "#{LoomTasks.const_lib_name}DemoGUI.build", gui_config)
end
-FileList[File.join('gui', 'src', '**', '*.ls')].each do |src|
+FileList[
+ File.join('gui', 'loom.config'),
+ File.join('gui', 'src', '*.build'),
+ File.join('gui', 'src', '**', '*.ls'),
+].each do |src|
file DEMO_GUI => src
end
@@ -87,7 +91,7 @@ namespace :gui do
sdk_version = args.id
lib_dir = LoomTasks.libs_path(sdk_version)
- fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
+ LoomTasks.fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
gui_config['sdk_version'] = sdk_version
write_gui_config(gui_config)
diff --git a/lib/tasks/rakefiles/loomlib_lib.rake b/lib/tasks/rakefiles/loomlib_lib.rake
index 5a3067d..d360103 100644
--- a/lib/tasks/rakefiles/loomlib_lib.rake
+++ b/lib/tasks/rakefiles/loomlib_lib.rake
@@ -81,7 +81,11 @@ file LIBRARY do |t, args|
end
end
-FileList[File.join('lib', 'src', '**', '*.ls')].each do |src|
+FileList[
+ File.join('lib', 'loom.config'),
+ File.join('lib', 'src', '*.build'),
+ File.join('lib', 'src', '**', '*.ls'),
+].each do |src|
file LIBRARY => src
end
@@ -141,7 +145,7 @@ namespace :lib do
sdk_version = args.id
lib_dir = LoomTasks.libs_path(sdk_version)
- fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
+ LoomTasks.fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
lib_config['sdk_version'] = sdk_version
write_lib_config(lib_config)
diff --git a/lib/tasks/rakefiles/loomlib_test.rake b/lib/tasks/rakefiles/loomlib_test.rake
index e220444..bb1b5b8 100644
--- a/lib/tasks/rakefiles/loomlib_test.rake
+++ b/lib/tasks/rakefiles/loomlib_test.rake
@@ -44,7 +44,11 @@ file TEST => LIBRARY do |t, args|
end
end
-FileList[File.join('test', 'src', '**', '*.ls')].each do |src|
+FileList[
+ File.join('test', 'loom.config'),
+ File.join('test', 'src', '*.build'),
+ File.join('test', 'src', '**', '*.ls'),
+].each do |src|
file TEST => src
end
@@ -117,7 +121,7 @@ namespace :test do
sdk_version = args.id
lib_dir = LoomTasks.libs_path(sdk_version)
- fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
+ LoomTasks.fail("no sdk named '#{sdk_version}' found in #{sdk_root}") unless (Dir.exists?(lib_dir))
test_config['sdk_version'] = sdk_version
write_test_config(test_config)
diff --git a/lib/tasks/rakefiles/support.rb b/lib/tasks/rakefiles/support.rb
index d063641..42fc0de 100644
--- a/lib/tasks/rakefiles/support.rb
+++ b/lib/tasks/rakefiles/support.rb
@@ -5,7 +5,7 @@
module LoomTasks
- VERSION = '3.0.3'
+ VERSION = '3.1.0'
EXIT_OK = 0
@@ -21,7 +21,21 @@ def fail(message)
end
def try(cmd, failure_message)
- fail(failure_message) if (exec_with_echo(cmd) != EXIT_OK)
+ LoomTasks.fail(failure_message) if (exec_with_echo(cmd) != EXIT_OK)
+ end
+
+ def which(cmd)
+ # from https://stackoverflow.com/a/5471032
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
+
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+ exts.each do |ext|
+ exe = File.join(path, "#{cmd}#{ext}")
+ return exe if File.executable?(exe) && !File.directory?(exe)
+ end
+ end
+
+ return nil
end
def bin_dir()
diff --git a/lib/tasks/scaffolding.rake b/lib/tasks/scaffolding.rake
index fd8d803..be7db84 100644
--- a/lib/tasks/scaffolding.rake
+++ b/lib/tasks/scaffolding.rake
@@ -16,7 +16,7 @@ def default_loom_sdk
end
def lib_name()
- @lib_name || fail("no lib name defined")
+ @lib_name || LoomTasks.fail("no lib name defined")
end
def template_dir
@@ -55,6 +55,16 @@ def gitignore_template()
File.join(template_dir, 'gitignore.erb')
end
+def cli_wrapper_pathname()
+ ext = windows? ? 'bat' : 'sh'
+ File.join(Dir.pwd, 'cli', 'wrapper', "#{lib_name}.#{ext}")
+end
+
+def cli_wrapper_template()
+ ext = windows? ? 'bat' : 'sh'
+ File.join(template_dir, "cli_wrapper.#{ext}")
+end
+
def demo_cli_pathname()
File.join(Dir.pwd, 'cli', 'src', "#{lib_name}DemoCLI.ls")
end
@@ -82,6 +92,22 @@ def demo_gui_template()
File.join(template_dir, 'LoomlibDemoGUI.ls.erb')
end
+def doc_config_pathname()
+ File.join(Dir.pwd, 'doc', 'lsdoc.config')
+end
+
+def doc_config_template()
+ File.join(template_dir, 'lsdoc.config.erb')
+end
+
+def doc_index_pathname()
+ File.join(Dir.pwd, 'doc', 'index.md')
+end
+
+def doc_index_template()
+ File.join(template_dir, 'index.md.erb')
+end
+
def lib_testapp_pathname()
File.join(Dir.pwd, 'test', 'src', 'app', "#{lib_name}Test.ls")
end
@@ -258,6 +284,14 @@ namespace :new do
create_from_string(loomconfig_pathname('cli'), loomconfig_cli_contents)
create_from_string(loombuild_pathname('cli', name), loombuild_demo_cli_contents)
create_from_template(demo_cli_pathname, demo_cli_template, context)
+ create_from_template(cli_wrapper_pathname, cli_wrapper_template, context)
+ end
+
+ task :doc do |t, args|
+ context = template_context
+
+ create_from_template(doc_config_pathname, doc_config_template, context)
+ create_from_template(doc_index_pathname, doc_index_template, context)
end
task :gui do |t, args|
@@ -291,12 +325,12 @@ namespace :new do
create_from_template(lib_testspec_pathname, lib_testspec_template, context)
end
- task :scaffold => [:gitignore, :rakefile, :lib, :test, :cli, :gui]
+ task :scaffold => [:gitignore, :rakefile, :lib, :test, :cli, :gui, :doc]
desc [
"scaffolds the directories and files for a new loomlib project",
"if no name argument is given, the current directory name is used",
- "creates a .gitignore file, rakefile, and template library and test code",
+ "creates a .gitignore file, rakefile, template library, test code, and docs",
"this task assumes (but does not enforce) being run in an empty directory",
].join("\n")
task :loomlib, [:name] do |t, args|
diff --git a/lib/tasks/templates/cli_wrapper.sh b/lib/tasks/templates/cli_wrapper.sh
new file mode 100755
index 0000000..ae4ed6c
--- /dev/null
+++ b/lib/tasks/templates/cli_wrapper.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+cd ~/.loom/<%= lib_name %>
+exec ./<%= lib_name %> "$@"
diff --git a/lib/tasks/templates/index.md.erb b/lib/tasks/templates/index.md.erb
new file mode 100644
index 0000000..3b60126
--- /dev/null
+++ b/lib/tasks/templates/index.md.erb
@@ -0,0 +1,15 @@
+---
+layout: page
+title: Home
+this: "**<%= lib_name %>**"
+---
+
+# {{ page.title }}
+
+{{ page.this }} is a new library ready for documentation.
+
+> Edit `doc/index.md` to change what this page looks like.
+> See [lsdoc][lsdoc] for feature and usage details
+
+
+[lsdoc]: https://github.com/pixeldroid/lsdoc "an API docs generator for LoomScript"
diff --git a/lib/tasks/templates/lsdoc.config.erb b/lib/tasks/templates/lsdoc.config.erb
new file mode 100644
index 0000000..679e1dc
--- /dev/null
+++ b/lib/tasks/templates/lsdoc.config.erb
@@ -0,0 +1,8 @@
+{
+ "project": {
+ "name": "<%= lib_name %>",
+ "repo": "",
+ "owner": "",
+ "version": "1.0.0"
+ }
+}