diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..6dbf7cb --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + ["presets": "es2015"] +} \ No newline at end of file diff --git a/.bookizarc b/.bookizarc new file mode 100644 index 0000000..533e0cd --- /dev/null +++ b/.bookizarc @@ -0,0 +1,16 @@ +{ + "token": "", + "username": "", + "email": "", + + "mode": { + "HTML": "html", + "CSS": "css", + "JS": "js", + "HEAD": "html" + }, + "urls": { + "registrationURL": "https://bubbl.in/api/register", + "baseURL": "https://bubbl.in/api/books/" + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 23ce61a..48d6732 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.DS_store +node_modules/ +npm-debug.log +crust diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3709d51 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +sudo: false +language: node_js +cache: + directories: + - node_modules +notifications: + email: false +node_js: + - '6.2' +before_install: + - npm i -g npm@latest +before_script: + - npm prune +script: + - npm run test:once +after_success: + - npm run semantic-release +branches: + except: + - /^v\d+\.\d+\.\d+$/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..549d2ba --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,47 @@ +# Bookiza Change Log +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](http://semver.org/). + + +### [Unreleased] Added 2016-06-11 + +### [Unreleased] Removed 2016-06-11 + +### [Unreleased] Reverted 2016-06-11 + +--- + +### [Unreleased] Added 2016-06-10 +- Added per batch request update and process_complete when last request returns `ok`. +- PAGES_CHUNK_SIZE +- Breaking Changes: Moved "book_id" to `.bookrc` instead of `package.json`, renamed `template.html`, `template.css` and `template.js` to `body.html`, `style.css` and `script.js` respectively for uniformity. Moved book.title to `.bookrc`. + +### [Unreleased] Reverted 2016-06-10 +- Revert to .bookrc instead of book.json because book.json sounds like actual book. See `lib/manager.js` + +### [Unreleased] Removed 2016-06-10 +- ProgressBar removed because unused + +--- + +### [Unreleased] Added 2016-06-9 +- ES2015 for client registration. See `lib/register` +- Return Promise object for .bookizarc file I/O. +- "Arc Bookiza": "0.0.13", https://www.npmjs.com/package/arc-bookiza + +--- + +### [0.0.22] Added 2016-06-3 +- Replace .bookrc with book.json for book-level mode & book_id information. +- "npm-update-module": "1.0.4" - See `update` method in `bin/bin.js`. + + +## 0.0.1 - 0.0.21 2016-05-31 +### Added +- This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG. +- CNAME file to enable GitHub Pages custom domain +- README now contains answers to common questions about CHANGELOGs +- Good examples and basic guidelines, including proper date formatting. +- Counter-examples: "What makes a unicorn cry?" +- Framework website up! \ No newline at end of file diff --git a/LICENSE.markdown b/LICENSE.markdown index 70a7053..8ba1dd3 100644 --- a/LICENSE.markdown +++ b/LICENSE.markdown @@ -1,3 +1,46 @@ # License(s) -Dual license | Offerings to be decided. \ No newline at end of file +THIS REPO IS CURRENTLY UNLICENSED. + +TODO: Dual license | To be decided. + + +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- + ___. __ .__ + \_ |__ ____ ____ | | _|__|____________ + | __ \ / _ \ / _ \| |/ / \___ /\__ \ + | \_\ ( <_> | <_> ) <| |/ / / __ \_ + |___ /\____/ \____/|__|_ \__/_____ \(____ / + \/ \/ \/ \/ + +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- + + The MIT License + +Copyright (c) 2015-2016+ Marvin Danig and The Bubblin Foundation *. + +See https://github.com/bubblin/bookiza/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + +THE SOFTWARE. + +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- \ No newline at end of file diff --git a/MIT-license.txt b/MIT-license.txt new file mode 100644 index 0000000..e13a6bd --- /dev/null +++ b/MIT-license.txt @@ -0,0 +1,39 @@ +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- + ___. __ .__ + \_ |__ ____ ____ | | _|__|____________ + | __ \ / _ \ / _ \| |/ / \___ /\__ \ + | \_\ ( <_> | <_> ) <| |/ / / __ \_ + |___ /\____/ \____/|__|_ \__/_____ \(____ / + \/ \/ \/ \/ + +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- + + The MIT License + +Copyright (c) 2015-2016+ Marvin Danig and The Bubblin Foundation *. + +See https://github.com/bubblin/bookiza/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + +THE SOFTWARE. + +----------------------------------------------------------------------------- +----------------------------------------------------------------------------- \ No newline at end of file diff --git a/README.markdown b/README.markdown index c73aab3..836a963 100644 --- a/README.markdown +++ b/README.markdown @@ -2,7 +2,7 @@ Quick and beautiful books. *Everywhere*. `Responsive` by default. -Bookiza is a book *baking tool*. It is a lightweight javascript (node 6+) framework that helps you compose book apps (SPAs). +Bookiza is a book *baking tool*. It is a lightweight javascript (node 6+) framework that helps you compose books, magazines and comics (SPAs). # Advantage Bookiza cuts your book writing & publishing time down by half. By HALF!, no less. Bringing in some of the best design and development techniques in the world, bookiza will turn your saga into a timeless product, an eternal journey of … no wait, an offline-first, well-paginated simple book app. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b132b06 --- /dev/null +++ b/README.md @@ -0,0 +1,252 @@ +# Bookiza + +Quick and beautiful books. *Everywhere*. `Responsive` by default. + +Bookiza is a book *baking tool*. It is a lightweight javascript (node 6+) framework that helps you compose book apps (SPAs). + +# Advantage +Bookiza can cut your book writing & publishing time down by half. By HALF!, no less. Integrate some of the best design and development techniques of the world into your journey of book writing. + +Get your developer & designer friends to work and collaborate with you. + +Produce delightful books that work [everywhere](https://bubbl.in/support)! + +> Visit the [Bookiza Website](http://bookiza.io) for more details. + + +![alt tag](https://raw.githubusercontent.com/bookiza/bookiza/master/assets/images/bookiza.png) + +### Support + +Books written using Bookiza are [supported](https://bubbl.in/support) on every major device, tablet and desktop out there. All it needs is a modern browser and an Internet connection (This will change!). + +Here are some [demo books](https://bubbl.in/books) created by our community. + +Despite ubiquity our effort with superbooks points mostly to yielding best reading experiences on tablets i.e. iPads(iOS 7+), Kindle 3 (Silk) and Android 5.0+ phablets. Because, well, even though it's great to support desktops, smartphones, TVs and whatnot, the most ideal situation and surface for reading books is the tablet. + +### Documentation + +Full documentation is available [here](https://bookiza.github.io/docs/) and [here](https://bubbl.in/cover/official-handbook-by-marvin-danig) and [here](https://bubbl.in/cover/bookiza-framework-by-marvin-danig). + +A quick tutorial on how to write superbooks is [here](https://marvindanig.svbtle.com/how-to-write-superbooks). + + +### What you'll need + +node > 6.2.1, git-scm, bubblin's `api_key` and a unixy-style shell/terminal. + +### Setup + +```bash +$ npm install -g bookiza +``` + +> You'll need to install bookiza and shelljs as global. + +Check installation with: + +```bash +$ bookiza --version +``` + +Register client with: + +```bash +$ bookiza register or $ b z +``` + +Provide your Bubblin credentials to connect to its sweet POST API. You're all set! + +### Getting started +To bootstrap new project, run: + +```bash +$ bookiza new MY-AWESOME-BOOK --leafs 12 --template comics # Creates project with 12 fresh leafs (24 pages) inside `manuscript/` with a comics template. +``` + +`cd` into the project and: + +```bash +$ bookiza server # Opens http://localhost:4567 on your browser! +``` + +Open the project on your favorite text editor (Sublime/Atom) and write away! Once you're ready (or even if you're not) hit: + +```bash +$ bookiza publish +``` + +Your book will be *POST'ed / PATCH'ed* over Bubblin instantly, in real time. + + +To see full CLI documentation with: + +```bash +$ bookiza --help +``` + +That's it. + +### Templates + +Bookiza comes along with several FREE, responsive and scalable [templates](https://github.com/bookiza/templates) so that you don’t have to do the layouts yourself. + +Feel free to use templates to kickstart your book/magazine in a best possible way and ensure that your work is responsive and [scalable](https://bubbl.in/support) on as many devices as possible. + +> We’re accepting new templates for all kinds of longform. Feel free to [fork](https://github.com/bookiza/templates#fork-destination-box) and submit pull requests per following [rules](https://github.com/bookiza/templates#rules) for any kind of book that you may have worked on. + + +### Configuration + +Bookiza and Bubblin default to only the building blocks of web i.e. HTML, CSS & JavaScript. Infact Bubblin accepts only clean and compiled HTML, CSS & JS to render books. + +> No preprocessor jugglery is allowed on live books that're meant for the readers! + +Bookiza lets you compose your manuscript with any preprocessor or engine you like. There are two ways to configure Bookiza so as to cater to your most general writing needs and at times, needs that are specific to a particular book. + + +#### `.bookizarc` + +When you register bookiza (`$ bookiza register` or `$ b z` ) it will automatically set up the following global runcom (.rc) file at the root. Bookiza will pick up the mode for its generators from this `arc` file. + +``` +# $ vi .bookizarc + +{ + "token": "", + "username": "", + "email": "", + + "mode": { + "HTML": "html", # markdown, haml, pug etc. + "CSS": "css", + "JS": "js", + "HEAD": "html" + }, + + "urls": { + "registrationURL": "https://bubbl.in/api/register", + "baseURL": "https://bubbl.in/api/books/" + } +} + +``` + +As you can see, configuring bookiza is as simple as setting the `mode` to use preprocessors of your liking. See full list of templating engines & preprocessors that are currently available. + +#### `.bookrc` + +Similarly, editing mode can also be set on per book basis with the following `rc` configuration inside the root of your project: + +``` +# $ vi .bookrc + +{ + "mode": { + "HTML": "html", + "CSS": "css", + "JS": "js", + "HEAD": "html" + } +} + +``` +In case of conflict of modes between `.bookrc` and `.bookizarc` the book_level configuration i.e. `.bookrc` shall prevail. + +### What is Bookiza? + +Bookiza is an open source book writing framework that makes your life easy. Be up and running with a manuscript in seconds and publish some of the best most crazy beautiful books that ever existed. + +Books baked with Bookiza use building-blocks of web i.e. HTML, CSS and JavaScript (Yeah, we got JS inside e-books!) so now you can spice up your story with underlying code, dynamic illustrations, data visualizations, interactive graphs, visual explanations and what not. + +Get the whole web inside your book! + +Check out our [demo book](http://bubbl.in/cover/the-solar-system-by-marvin-danig) on your iPad, for example. + + +### Why a framework & not wordprocessor? +We wanted to be able to write any kind of book — comics, scientific journals, magazines, novels, schoolbooks, textbooks - using the awesomeness of web. + +Wordprocessors trump the flexibility that is required for books, comics & magazines that artists all over the world can create. That's not surprising because wordprocessors originally were meant for enterprise documentation (bureaucracy?) only. For things like purchase orders, contracts or legalese which has nothing to do with nice and creative books. + +We also wanted books to feel native on the new web -- not like websites that pretend to be books. Be one that handles long form correctly and scales across all the devices and desktops out there, *ala* - responsive, adaptive and scalable (with or without touch capability). + +:metal::point_right: A framework with a powerful CL interface also ensures that we can use our existing developer toolchain to mint and print books. + + +#### What it is not. + +:book: Bookiza is not yet another javascript framework (thankfully) for mobile or app development. It doesn't prescribed a pattern or emphasizes MVC or anything like that. Bookiza is also not a blogging solution. If you wish to write short-form essays or blogposts of upto 3-4 pages (or so) we recommend you to go for a blog instead. + +At the moment bookiza will bake manuscripts that are at least 4 pages long. Read more about Superbooks on [Bubblin](https://bubbl.in). + + +### Obsession + +Bookiza is *obsessive* about live book editions and quick manuscript turnarounds. Using instant edit2publish state of web to the maximum. Our goal is to optimize books on the web, make it friendlier for people to read, write and connect. Provide a flexibility that book writers haven't had for the last twenty years. A framework that decidely leaves behind the old-school idea of downloading-a-lifeless-artifact called ebook that is nothing but a dull file sponsored by an even older lobby group that wants physical books to thrive and remain on top!. + +We want to focus on a future where web and books are unified, in a single resource that is both accessible and available everywhere. + + +#### Features + +* [x] Responsive container by default +* [x] Cover on all major devices and browsers +* [x] Support beautiful typography with @font-faces +* [x] Allow CDN resources for quick load +* [x] Open once, offline forever without needing to download any artifact +* [x] Modular pages that follow web standards +* [x] Visual explanations with in-page JavaScript +* [x] Full-bleed imagery for fashion/lifestyle journals +* [x] Support for WebGL, CSS3 or other HTML5 experiments. +* [x] Searchable & indexable content +* [x] Simplicity of `git` +* [x] Push2Deploy with real-time editions + + +## The library +Books created via Bookiza can be published directly to [bubblin](https://bubbl.in) - our substrate platform for book lovers. Or you can host it on your own website! + +Find a selection of *exclusive* and [handpicked books](https://bubbl.in/books) by our community of writers. + +## The community + +* Follow [@bookiza on Twitter](https://twitter.com/bookiza) +* Have a feature request or find a bug? [Submit an issue](https://github.com/bookiza/bookiza/issues) +* Have a question that's not a feature request or bug report? [Ask on Bookiza Bubblin forum](http://bubblin.uservoice.com/forums/228504-general) +* Read the [Bubblin Blog](http://medium.com/) + + +## Authors + +Created & maintained by [Marvin Danig](http://twitter.com/marvindanig). + +Pull requests, [issues](https://github.com/bookiza/bookiza/issues), contribution and [donations](https://bubbl.in/donations/new) are very welcome. Feedback is welcome from both developers & designers! + +See the list of [contributors](https://github.com/bookiza/bookiza/graphs/contributors). + +## Further development + +Our motto: "Books should be a first class citizen of the web" -- let web & books be together, like a single unified resource -- both accessible and *open*! + +We're also working on a draft proposal for [spine_url](https://bubblin.github.io/) to bring native support of books on the web -- like single page apps. + +### Dependencies + +async, superagent, progress, co-prompt, co, path, fs, chalk, commander, string, dateformat, shelljs, os-homedir + + +### Bookiza Commit Conventions + +* [x] PR branches must work everywhere: i.e. should have been tested on all browsers on OSX, Windows & Linux. +* [x] Commit messages must explain whys & whats. Please lint your JS before submitting your features. +* [x] Provide system related information of the dev machine(OS/Browser/Screen). + +### Up next + +* Introduce preprocessors inside page generators +* TODO: Consider introducing cover attributes within ambit of JSON. Or not. + +### LICENSE + +TBD. *UNLICENSED* \ No newline at end of file diff --git a/assets/images/logo.txt b/assets/images/logo.txt new file mode 100644 index 0000000..6483c9c --- /dev/null +++ b/assets/images/logo.txt @@ -0,0 +1,37 @@ + + + ` + , ; ; + ` ; ` + ..` :: ; + :; ; . + : ; ;;. `; ; + ; ; ` .;: .: ; + .; ; ; . ;; :`` ; + ;; ; ; ;:`; ; ` ; + `;; ; ; ;. ; ; ; ; ; ; + ;; . ; ;;, ;`;.; : ;` ; + ;::::,'';'+''+::;;,; ;. ; + ; ;::::'''''''''':::; ; ;; , :` + ` ; `;::''''''''''';,:::;; ;;; ; + , .; ,::''''''''''''';,::;`:` ; . ; + . ;;`::''''''''''''''+,::: ;;: .: + , ;;;,'''''';;;;'''''++,: ;;,; , + `: ;;;:''';;;;;;;;'''''+,::;;,: . ; + `: ;;'''';;;;;;;;;;''''+,::;,; . , + ; ;;''';;:''':;;;;;'''',::;; . ; + ;.:;''';'''''';;;;;'''+,::;`. ;` + ;; ''';''''''''';;;'''+,::;, ,; + .;;''':'''';;;'':;;'''+:::, ; + ;;''';'''';;;'';;;'''+:: : ;` + :;;'';''''''''';;;''''.,;``; + ;;''';::'''''';;''''::.`;. + ,;;'';;;:''''';;'''+:;;` + ;;''';;;:''':;'''':. + `;;'''';;;;;;''':;;`` + ,;'';'''''''';;; + ;'''';;;; + :;;; + ; + . + ` diff --git a/bash/.bookiza b/bash/.bookiza new file mode 100644 index 0000000..537ef2f --- /dev/null +++ b/bash/.bookiza @@ -0,0 +1,432 @@ +# ---------------- Works, but deprecated-----------# +# -------------------------------------------------# +# BOOKIZA SUPERBOOK WRITERS # +# -------------------------------------------------# + + +# ---------- main() class --------- # + +bookiza() { + case "$1" in + new) + new "$@" + ;; + insert) + insert "$@" + ;; + add) + add "$@" + ;; + remove) + remove "$@" + ;; + clip) + clip "$@" + ;; + length) + length + ;; + status) + status + ;; + push) + push + ;; + publish) + publish + ;; + server) + server + ;; + help) + help + ;; + update) + update + ;; + -v) + version + ;; + *) + echo $"Usage: $0 { new | insert | length | remove | clip | status | push | publish | server | help | update | -v }" + echo $"Try: $ bookiza help " + esac +} + +#--------- NEW PROJECT ---------# + +new() { + args=("$@") + + echo "Setting up project ........" + + PROJECTNAME=${args[1]} + + readValidProjectName "$PROJECTNAME" + + setupProject "$PROJECTNAME" + + BOOKLENGTH=${args[2]} + + readValidBookLength "$BOOKLENGTH" + + (pickUpTemplate; cd manuscript || exit; START_AT=1; createPages "$START_AT" "$BOOKLENGTH") + + setupNPM + + setupRepo +} + +#-------- project name ------ ## + +isValidArgument() { + test "$1" +} + +readValidProjectName() { + PROJECTNAME=$1 + while ! isValidArgument "$PROJECTNAME"; do + echo -e "Project name?: \c" + read -r PROJECTNAME + done +} + +setupProject() { + mkdir -p "$1" && cd "$1" && touch README.md license.txt .gitignore && mkdir -p "trash" "cover" "templates" "assets" "manuscript" || return $? + echo "# $1" >> README.md + (cd templates || exit; + touch template.html head.html template.css template.js; + echo "body{background:rgba(200, 235, 255, 0.99); margin:0 0; overflow:hidden;}" >> template.css) + (cd assets || exit; mkdir -p "css" "javascript" "images") +} + +## ------ Book length ------ ## + +readValidBookLength() { + BOOKLENGTH=$1 + + while ! { isValidArgument "$BOOKLENGTH" && isArgumentNumeric "$BOOKLENGTH" && isArgumentEvenNumber "$BOOKLENGTH"; }; do + echo -e 'Book length?: \c' + read -r BOOKLENGTH + done + +} + +isArgumentNumeric() { + ARGUMENT=$1 + reg='^[0-9]+$' + if ! [[ $ARGUMENT =~ $reg ]] ; then + return 1 + else + return 0 + fi +} + +isArgumentEvenNumber() { + ARGUMENT=$1 + if [ $((ARGUMENT%2)) -eq 0 ] ; then + return 0 + else + return 1 + fi +} + +createPages() { + args=("$@") + + START_AT=${args[0]} + + END_AT=${args[1]} + + q=0 + while [ "$q" -lt "$END_AT" ]; do + mkdir -p "page-$((START_AT+q))" + (cd "page-$((START_AT+q))" || exit; touch "body.html" && touch "style.css"; echo "$HTML_TEMPLATE" >> body.html) + q=$((q+1)) + done +} + +pickUpTemplate() { + HTML_TEMPLATE=$(cd "templates" || exit; cat template.html) +} + +setupNPM() { + cp -R "$HOME/.bookiza/source" "." +} + +setupRepo() { + git init + git add . -A + git commit -am "First commit: Setup new book project" --quiet + readValidRepoURL "$REPO_URL" + git remote add origin "$REPO_URL" + git push -u origin master + echo "Project is ready!" +} + +readValidRepoURL() { + REPO_URL=$1 + while ! isValidArgument "$REPO_URL"; do + echo -e "Repository URL?: \c" + read -r REPO_URL + done +} + + +# ---------- INSERT PAGES --------- # + +insert() { + args=("$@") + + INSERT_AT=${args[1]} + + readValidInsertAt "$INSERT_AT" + + NUMBER_OF_PAGES=${args[2]} + + readValidNumberOfPages "$NUMBER_OF_PAGES" + + (cd manuscript || exit; pushStackDown "$INSERT_AT" "$NUMBER_OF_PAGES") + + (pickUpTemplate; cd manuscript || exit; createPages "$INSERT_AT" "$NUMBER_OF_PAGES") + +} + +readValidInsertAt() { + INSERT_AT=$1 + + while ! { isValidArgument "$INSERT_AT" && isArgumentNumeric "$INSERT_AT" && isArgumentInRange "$INSERT_AT"; }; do + echo -e 'Insert at?: \c' + read -r INSERT_AT + done +} + +isArgumentInRange() { + ARGUMENT=$1 + + BOOKLENGTH=$(cd manuscript || exit; getLength; echo $BOOKLENGTH) + + if [[ "$ARGUMENT" -le "$BOOKLENGTH" ]] && [[ "$ARGUMENT" -gt 0 ]] ; then + return 0 + else + return 1 + fi + +} + +readValidNumberOfPages() { + NUMBER_OF_PAGES=$1 + while ! { isValidArgument "$NUMBER_OF_PAGES" && isArgumentNumeric "$NUMBER_OF_PAGES" && isArgumentEvenNumber "$NUMBER_OF_PAGES"; }; do + echo -e 'Number of pages?: \c' + read -r NUMBER_OF_PAGES + done +} + + +pushStackDown() { + args=("$@") + echo INSERT_AT: "${args[0]}", [ NUMBER_OF_PAGES: "${args[1]}" ] + + p="$INSERT_AT" + + if [ -d "page-$p" ]; then + getLength + q="$BOOKLENGTH" + + while [ "$q" -ge "$p" ]; do + mv "page-$((q))" "page-$((q+NUMBER_OF_PAGES))" + q=$((q-1)) + done + fi +} + + +# ---------- ADD PAGES --------- # + +add() { + args=("$@") + + NUMBER_OF_PAGES=${args[1]} + + readValidNumberOfPages "$NUMBER_OF_PAGES" + + (pickUpTemplate; cd manuscript || exit; getLength; createPages "$((BOOKLENGTH+1))" "$NUMBER_OF_PAGES") +} + + +# --------- REMOVE PAGE_No ----------# + + +remove() { + args=("$@") + + REMOVE_AT="${args[1]}" + + readValidRemoveAt "$REMOVE_AT" + + (cd manuscript || exit; deletePage "$REMOVE_AT") + +} + +readValidRemoveAt() { + REMOVE_AT=$1 + while ! { isValidArgument "$REMOVE_AT" && isArgumentNumeric "$REMOVE_AT" && isArgumentInRange "$REMOVE_AT"; }; do + echo -e 'Remove page at?: \c' + read -r REMOVE_AT + done +} + +deletePage() { + PAGE_NO=$1 + if [ -d "page-$PAGE_NO" ]; then + (mv "page-$PAGE_NO" "../trash/page-$PAGE_NO-$(timestamp)";) + + m="$PAGE_NO" + m=$((m+1)) + + until [ ! -d "page-$m" ]; do + mv "page-$((m))" "page-$((m-1))" + m=$((m+1)) + done + + (getLength; createPages "$((BOOKLENGTH+1))" 1) + fi + +} + +timestamp() { + date +"%T" +} + + +# --------- CLIP PAGE_No ----------# + + +clip() { + echo " + Clip statement not ready. This will remove the page from the manuscript and lower the length of the book by 1" +} + + +# ---------- BOOKLENGTH --------- # + +length() { + if [ -d manuscript/ ] ; then + (cd manuscript || exit; getLength; echo "Book length is: ${BOOKLENGTH} pages.") + else + echo "Manuscript not found, probably not in project root!" + fi +} + +getLength() { + BOOKLENGTH=1 + until [ ! -d "page-$((BOOKLENGTH+1))" ]; do + BOOKLENGTH=$((BOOKLENGTH+1)) + done +} + +# --------- PROJECT STATUS ----------# + +status() { + git status +} + + +# --------- PUSH TO REPO ----------# + +push() { + readValidGitMessage "$MESSAGE" + git commit -am "${MESSAGE}" + git push +} + +readValidGitMessage() { + MESSAGE=$1 + while ! isValidArgument "$MESSAGE"; do + echo -e "Message: \c" + read -r MESSAGE + done +} + +# --------- PUBLISH TO BUBBLIN ----------# + +publish() { + echo "# TODO: Expose authenticated POST API on https://bubbl.in" + readValidHostURL "$HOST_URL" # TODO: HOST_URL can be constructed using hyphenated $projectname & author-full-name + git remote add origin "$HOST_URL" + git push -u origin master +} + +readValidHostURL() { + HOST_URL=$1 + while ! isValidArgument "$HOST_URL"; do + echo -e "Bubblin URL?: \c" + read -r HOST_URL + done +} + +# ---------- LOCAL SERVER --------- # + +server() { + gulp +} + +# --------- FRAMEWORK GUIDE --------# + +help() { + +echo " +# -------------------------------------------------# +# BOOKIZA SUPERBOOK FRAMEWORK # +# -------------------------------------------------# +" +echo " + +Usage: $ bookiza [] + +Commands glossary: $0 { new | insert | length | remove | status | push | publish | server | help | update | -v } + +" + +echo " + $ bookiza new [expected number of pages] + Examples: + 1. Project/book name: My-Awesome-Book-Name i.e. use hyphens! + 2. Book length: 24, 100 (Must be even number. Here's why: https://bubbl.in/book/official-handbook-by-marvin-danig/36) + 3. Github URL: https://github.com/username/my-new-book.git +" + +echo " + $ bookiza insert [insert_at] [number_of_pages] + Examples: + 1. insert_at: 31, 44 (Must be integer) + 2. number_of_pages: 4, 8 (Must be even number) +" + +echo " + $ bookiza add [number_of_pages] + Examples: + 1. number_of_pages: 4, 8 (Must be even number) +" + +echo " + $ bookiza remove [page_number] + Examples: + 1. Removes page at [page_number]: 4, 17 (Must be integer) + 2. And appends a blank page at the end of the book. +" +} + + +# ---------- UPDATE SCRIPT --------- # + +update() { + (cd ~/.bookiza || exit; git pull; source ~/.bash_profile; version) +} + + +# ---------- VERSION --------- # + +version() { + echo "bookiza 0.0.1" +} \ No newline at end of file diff --git a/bin/bin.js b/bin/bin.js new file mode 100755 index 0000000..1a17d62 --- /dev/null +++ b/bin/bin.js @@ -0,0 +1,265 @@ +#! /usr/bin/env node + +const program = require('commander'); +const chalk = require('chalk'); +const fs = require('fs'); +const path = require('path'); + +program + .command('new ') + .alias('n') + .description('New book (Setup manuscript)') + .option('-l, --leafs ', 'tentative number of leafs') + .option('-t, --template