lib/arli/commands/generate.rb in arli-1.0.2 vs lib/arli/commands/generate.rb in arli-1.1.0

- old
+ new

@@ -13,11 +13,10 @@ extend Forwardable def_delegators :@settings, :project_name, :project_name=, :workspace, :workspace=, :libs, :libs=, :template_repo attr_accessor :settings, :dir - def setup config.generate.project_name = config.runtime.argv.first self.settings = config.generate @@ -30,68 +29,72 @@ end def run Dir.chdir(workspace) do run_with_info( - "grabbing the template from\n • #{template_repo.bold.green}...", + "Grabbing the template from\n • #{template_repo.bold.green}...", "git clone -v #{template_repo} #{project_name} 2>&1" ) Dir.chdir(project_name) do FileUtils.rm_rf('.git') FileUtils.rm_rf('example') run_with_info( - "configuring the new project #{project_name.bold.yellow}", + "Configuring the new project #{project_name.bold.yellow}", 'git init .' ) - run_with_info('customizing your README and other files...') + run_with_info('Customizing your README and other files...') rename_files! configure_template! run_with_info( - 'running bin/build — to setup and build the project', + 'Running setup of the dependencies...', + 'bin/setup' ) - system('bin/build setup') - puts '[OK]'.bold.green + run_with_info("The project #{project_name.bold.yellow} is ready.\n" + + 'Follow README.md for build instructions.') end end + __pt hr end def run_with_info(message, command = nil) - info("\n" + message.cyan) + indent = ' ' + ok_indent = indent + ' ✔ '.green + err_indent = indent + ' X '.red + info("\n" + message.magenta) return unless command - o, e, s = run_system_command(command) - ok_indent = ' ✔ '.green - err_indent = ' x '.red + info(indent + command.bold.yellow) + o, e, s = run_system_command(command) info(ok_indent + o.chomp.gsub(/\n/, "\n#{ok_indent}").blue) if o && o.chomp != '' warn(err_indent + +e.chomp.gsub(/\n/, "\n#{err_indent}").red) if e && e.chomp != '' end def additional_info - "\nGenerating project #{project_name.bold.green}\nDestination: #{workspace.bold.yellow}\n" + "\nGenerating project #{project_name.bold.green} into #{workspace.bold.yellow}\n" + + "Template: #{template_repo.bold.red}\n" end private def rename_files! FileUtils.mv('README.md', 'README-Arli-CMake.md') Dir.chdir('src') do FileUtils.mv('MyProject.cpp', "#{project_name}.cpp") - run_system_command "sed -i 's/MyProject/#{project_name}/g' CMakeLists.txt" + run_with_info('Updating CMakeLists.txt file...', + "sed -i 's/MyProject/#{project_name}/g' CMakeLists.txt") end - run_system_command "sed -i 's/MyProject/#{project_name}/g' CMakeLists.txt" + run_with_info('Updating CMakeLists.txt file...', + "sed -i 's/MyProject/#{project_name}/g' CMakeLists.txt") end def configure_template! File.open('README.md', 'w') do |f| f.write <<-EOF - -> This project has been auto-generated using: +> **NOTE**: This project has been auto-generated using: > > * [arli](https://github.com/kigster/arli) Arduino toolkit, and using the `generate` command. Thank you for using Arli! -> > * [arli-cmake](https://github.com/kigster/arli-cmake) is the template project that was used as a source for this one. -> > * [arduino-cmake](https://github.com/arduino-cmake/arduino-cmake) is the CMake-based build system for Arduino projects. > > There is a discussion board for Arli/CMake-based projects. Please join if you have any questions or suggestions! > [![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/arduino-cmake-arli/) @@ -110,40 +113,21 @@ * Requires ruby, 2.3 or 2.4+ installed. On a Mac's Terminal, run `ruby --version`. If for some reason you don't have it installed, the `bin/setup` script will prompt you to install it. ## Building #{project_name} -### Using the BASH Helper `bin/build` - -This project contains a BASH script that can automate your setup and build process. The following script takes care of most dependencies, including a missing Ruby. - ```bash $ cd ~/workspace/#{project_name} -$ bin/build [ setup | clean | make-flags ] -``` - -You should see a bunch of output, and upon completion, run `arli` without arguments to see if the command got installed and shows you proper help message. If you get `command not found`, please `[sudo] gem install arli --no-ri --no-rdoc`. Add sudo if your ruby installation is the system one, ie, `which ruby` returns `/usr/bin/ruby`. - - -### Manual Build - -If you prefer to have more control over the build, you can of course build manually, -and manage `CMakeLists.txt` however you want. - -Once you've run the setup, the manual build is: - -```bash -$ cd ~/workspace/#{project_name} $ rm -rf build && mkdir -p build && cd build $ cmake .. $ make # this builds the image $ make upload # this uploads it to the device $ # this next command opens a serial port monitor inside a screen session $ make #{project_name}-serial ``` -#### Customizing the Build +### Customizing the Build You can use environment variables to set the board, CPU and the port. Simply prefix the following variables before you run `cmake ..` ```bash $ rm -rf build @@ -160,9 +144,25 @@ Your repo contains `Arlifile` inside the `src` folder. Please [read the documentation](https://github.com/kigster/arli#command-bundle) about the format of `Arlifile`. Go ahead and edit that file, and under `dependencies:` you want to list all of your libraries by their exact name, and an optional version. The best way to do that is to **first search for the library** using the `arli search terms` command. Once you find the library you want, just copy it's name as is into `Arlifile`. If it contains spaces, put quotes around it. + +For example: + +```bash +❯ arli search /adafruit.*bmp085/i + +Arli (1.0.2), Command: search +Library Path: ~/Documents/Arduino/Libraries + +Adafruit BMP085 Library (1.0.0) ( 1 total versions ) +Adafruit BMP085 Unified (1.0.0) ( 1 total versions ) +——————————————————————— + Total Versions : 2 +Unique Libraries : 2 +——————————————————————— +``` If the library is not in the official database, just add it with a name and a url. Arli will use the url field to fetch it. To verify that your Arlifile can resolve all libraries, please run `arli bundle` inside the `src` folder. If Arli suceeds, you've got it right, and the `libraries` folder inside `src` should contain all referenced libraries.