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

- old
+ new

@@ -29,91 +29,180 @@ FileUtils.mkdir_p(workspace) unless Dir.exist?(workspace) end def run Dir.chdir(workspace) do - run_system_command "git clone -v #{template_repo} #{project_name} 2>&1" + run_with_info( + "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') - run_system_command 'git init .' - run_system_command 'bin/setup' - configure_template! + FileUtils.rm_rf('example') + run_with_info( + "configuring the new project #{project_name.bold.yellow}", + 'git init .' + ) + 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', + ) + system('bin/build setup') + puts '[OK]'.bold.green end end end + def run_with_info(message, command = nil) + info("\n" + message.cyan) + return unless command + o, e, s = run_system_command(command) + ok_indent = ' ✔ '.green + err_indent = ' x '.red + 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 - "Generating project #{project_name.bold.green} into #{workspace.bold.yellow}..." + "\nGenerating project #{project_name.bold.green}\nDestination: #{workspace.bold.yellow}\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" end + run_system_command "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: +> +> * [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/) + + # #{project_name} -Please refer to the README for the template project, available here: -[arli-cmake](#{template_repo}). +**TODO: Please update this README to reflect information about you project. :)** -## Usage +## Prerequisites -Let's cd into the project folder: + * On a Mac, you always need to run `xcode-select --install` before you can do any development. You must have `git` installed; + * Requires [CMake](https://cmake.org/download/) + + * Requires [Arduino IDE](https://www.arduino.cc/en/Main/Software) or an SDK, either for [Mac](https://downloads.arduino.cc/arduino-1.8.5-macosx.zip) or [Linux](https://downloads.arduino.cc/arduino-1.8.5-linux.zip) installed; + + * 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 #{project_name} +$ cd ~/workspace/#{project_name} +$ bin/build [ setup | clean | make-flags ] ``` -The directory structure should look as follows: +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 ``` - #{project_name} - | - |__ bin/ - | |___ setup - | |___ build - | - |__ cmake/ - | |___ Arli.cmake - | |___ ArduinoToolchain.cmake <———— provided by arduino-cmake project - | |___ Platform/ <———— provided by arduino-cmake project - | - |__ src/ - | |___ Arlifile - | |___ CMakeLists.txt - | |___ #{project_name}.cpp - | - |__ example/ - |___ Arlifile - |___ CMakeLists.txt - |___ Adafruit7SDisplay.cpp + +#### 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 +$ mkdir -p build +$ cd build +$ BOARD_NAME=nano \\ + BOARD_CPU=atmega328p \\ + BOARD_DEVICE=/dev/tty.usbserial-DA00WXFY \\ + cmake .. ``` -You might need to run `bin/setup` first to ensure you have all the dependencies. +### Adding External Libraries -Once you do that, you can build any of the source folders (i.e. either `src` or `example`) by -running `bin/build src` or `bin/build example`. +Your repo contains `Arlifile` inside the `src` folder. Please [read the documentation](https://github.com/kigster/arli#command-bundle) about the format of `Arlifile`. -### Building Manually +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 process to build and upload manually is super simple too: +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. -```bash -cd src -rm -rf build && mkdir build && cd build -cmake .. -make -make upload +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. + +### Adding Source Files + +You will notice that inside `src/CMakeLists.txt` file, there is a line: + +```cmake +set(PROJECT_SOURCES #{project_name}.cpp) ``` + +If you add any additional source files or headers, just add their names right after, separated by spaces or newlines. For example: + +```cmake +set(PROJECT_SOURCES + #{project_name}.cpp + #{project_name}.h + helpers/Loader.cpp + helpers/Loader.h + config/Configuration.h +) +``` + +The should be all you need to do add custom logic and to rebuild and upload the project. + +## Where to get Support? + +Please feel free to file bug reports and submit pull requests on GitHub — [https://github.com/kigster/arli-cmake](https://github.com/kigster/arli-cmake) is the project URL, and this is the [issues](https://github.com/kigster/arli-cmake/issues) URL. + +## License + +The original project is distributed as open source, under the terms of the [MIT License](http://opensource.org/licenses/MIT). + +However, feel free to change the license of your project, as long as you provide the credit to the original. + +Thanks! +Good luck! + EOF end end end