Book–Console2SAAS–technical details and CD

One of the important thing about creating a book is how to have fast feedback you see it after you write some texts. I decided to go like this:

  1. Each chapter will be in his own folder  ( https://github.com/ignatandrei/console_to_saas/tree/master/Chapter01 , https://github.com/ignatandrei/console_to_saas/tree/master/Chapter02 , and so on) .
  2. The content will be in the readme.md in each chapter folder ( to have a fast feedback about how it looks)
  3. The code examples will be in the same folder as the chapters
  4. The whole book will be available for download as PDF ( also other formats)
  5. The whole book will be easy seen at Github pages ( https://ignatandrei.github.io/console_to_saas/ )

How I made this available ? As usual, GitHub actions to the rescue – and some easy javascript. First, the javascript

“use strict”;

(async () => {

console.log(`start print`);

const { badgen } = require(“badgen”);

const sloc = require(“node-sloc”);

const fs = require(“fs”);

const chapters = [

“Chapter01”,

“Chapter02”,

“Chapter03”,

“Chapter04”,

“Chapter05”,

“Chapter06”,

“Chapter07”,

];

for (var i = 0; i < chapters.length; i++) {

var item = chapters[i];

var res= await sloc({ path: `../${item}/` });

  console.log(res);

const svgString = badgen({

      label: `${item}`, // <Text>

      labelColor: “ADF”, // <Color RGB> or <Color Name> (default: ‘555’)

      status: `files:${res.sloc.files};lines:${res.sloc.loc}`, // <Text>, required

      color: “blue”, // <Color RGB> or <Color Name> (default: ‘blue’)

      style: “flat”, // ‘flat’ or ‘classic’ (default: ‘classic’)

//icon: ‘data:image/svg+xml;base64,…’, // Use icon (default: undefined)

//iconWidth: 13,    // Set this if icon is not square (default: 13)

      scale: 1, // Set badge scale (default: 1)

    });

    fs.writeFileSync(`../${item}.svg`, svgString);

}

var markdownpdf = require(“markdown-pdf”);

var mdDocs = [

“../README.md”,

“../1-break.md”,

“../Chapter01/readme.md”,

“../1-break.md”,

“../Chapter02/readme.md”,

“../1-break.md”,

“../Chapter03/readme.md”,

“../1-break.md”,

“../Chapter04/readme.md”,

“../1-break.md”,

“../Chapter05/readme.md”,

“../1-break.md”,

“../Chapter06/readme.md”,

“../1-break.md”,

“../Chapter07/readme.md”,

“../1-break.md”,

“../conclusions.md”

  ],

  bookPath = “../book-raw.pdf”;

var options = {

  remarkable: {

      html: true,

      breaks: true

  },

  runningsPath: ‘running.js’

}

function generateBook() {

return new Promise(function(resolve, reject) {

    markdownpdf(options)

      .concat.from(mdDocs)

      .to(bookPath, function () {

        console.log(“Created”, bookPath);

        resolve(bookPath);

      });

  });

}

var bookPath = await generateBook();

const PDFMerger = require(‘pdf-merger-js’);

var merger = new PDFMerger();

merger.add(“../cover.pdf”);

merger.add(“../book-raw.pdf”);

await merger.save(“../book.pdf”);

})();

As you see , I am using those JS packages

“badgen”: “3.0.1”,

“markdown-pdf”: “10.0.0”,

“pdf-merger-js”: “3.0.5”,

“node-sloc”: “0.1.12”

Forgetting number of lines and badges, I use badgen and node-sloc . For generating pdf, I use markdown-pdf and pdf-merger ( to put images)

For generating ODT, I use githb actions directly :

name: ‘CD for generate book and docs folder’

env:

ChaptersMD : Chapter01/readme.md Chapter02/readme.md  Chapter03/readme.md Chapter04/readme.md  Chapter05/readme.md Chapter06/readme.md  Chapter07/readme.md

on:

push:

paths:

    – ‘**.md’

    – ‘**.yml’

    – ‘**.txt’

    – ‘**.json’

    – ‘**.js’

jobs:

build:

runs-on: ubuntu-latest

steps:

    – uses: actions/checkout@v2

    – name: generate pdf

run: |

        chmod +x ./print/getBook.bat

        cd print       

        ./getBook.bat

        ls -lh

        cp ./book.pdf ../docs/ConsoleToSaas.pdf

        cp ./Chapter01.svg ../docs/Chapter01.svg

        cp ./Chapter02.svg ../docs/Chapter02.svg

        cp ./Chapter03.svg ../docs/Chapter03.svg

        cp ./Chapter04.svg ../docs/Chapter04.svg

        cp ./Chapter05.svg ../docs/Chapter05.svg

        cp ./Chapter06.svg ../docs/Chapter06.svg

        cp ./Chapter07.svg ../docs/Chapter07.svg

        # cp ./Chapter01.svg ../Chapter01/Chapter01.svg

        # cp ./Chapter02.svg ../Chapter02/Chapter02.svg

        # cp ./Chapter03.svg ../Chapter03/Chapter03.svg

        # cp ./Chapter04.svg ../Chapter04/Chapter04.svg

        # cp ./Chapter05.svg ../Chapter05/Chapter05.svg

    – name: upload pdf to artifacts

uses: actions/upload-artifact@v1

with:

name: ConsoleToSaas.pdf

path: ./print/book.pdf

    – name: Commit files

run: |

        git config –local user.email “action@github.com”

        git config –local user.name “GitHub Action”

        git commit -m “generate pdf” -a –allow-empty

    – name: Push changes

uses: ad-m/github-push-action@master

with:

github_token: ${{ secrets.GITHUB_TOKEN }}

convert_via_pandoc:

runs-on: ubuntu-18.04

needs: build

steps:

      – uses: actions/checkout@v2

      – run: |

          echo chapters to generate $ChaptersMD

          git pull

          mkdir output

      – name: generate odt

uses: docker://pandoc/latex:2.9

with: # needs a README in your repo root!

args: “cover.md README.md Chapter01/readme.md Chapter02/readme.md  Chapter03/readme.md Chapter04/readme.md Chapter05/readme.md Chapter06/readme.md Chapter07/readme.md conclusions.md –standalone -f gfm -t odt  –toc -o output/output.odt –metadata title=CLI/Console2SAAS”

      – name: generate epub

uses: docker://pandoc/latex:2.9

with: # needs a README in your repo root!

args: “cover.md README.md Chapter01/readme.md Chapter02/readme.md  Chapter03/readme.md Chapter04/readme.md Chapter05/readme.md Chapter06/readme.md Chapter07/readme.md conclusions.md –standalone -f gfm -t epub  –toc -o output/output.epub –metadata title=CLI/Console2SAAS”

      – name: generate docx

uses: docker://pandoc/latex:2.9

with: # needs a README in your repo root!

args: “cover.md README.md Chapter01/readme.md Chapter02/readme.md  Chapter03/readme.md Chapter04/readme.md Chapter05/readme.md Chapter06/readme.md  Chapter07/readme.md conclusions.md –standalone -f gfm -t docx  –toc -o output/output.docx –metadata title=CLI/Console2SAAS”

      – name: generate html

uses: docker://pandoc/latex:2.9

with: # needs a README in your repo root!

#args: “–standalone –output=output/README.html README.md”

args: “cover.md README.md Chapter01/readme.md Chapter02/readme.md  Chapter03/readme.md Chapter04/readme.md Chapter05/readme.md Chapter06/readme.md  Chapter07/readme.md  conclusions.md –standalone -f gfm -t html  –include-in-header=header.txt –toc -o output/output.html –metadata title=CLI/Console2SAAS”

      – uses: actions/upload-artifact@master

with:

name: output

path: output

      – run: |

          cp ./output/output.html ./docs/index.html

          cp ./output/output.epub ./docs/ConsoleToSaas.epub  

          cp ./output/output.docx ./docs/ConsoleToSaas.docx

          cp ./output/output.odt ./docs/ConsoleToSaas.odt

          rm -rf ./output

      – name: Commit files

run: |

          git config –local user.email “action@github.com”

          git config –local user.name “GitHub Action”

          git commit -m “generate html” -a –allow-empty

      – name: Push changes

uses: ad-m/github-push-action@master

with:

github_token: ${{ secrets.GITHUB_TOKEN }}

zipSources:

runs-on: ubuntu-latest

needs: [build,convert_via_pandoc]

steps:

    – uses: actions/checkout@v2

    – name: pulling latest

run: |

        echo chapters to generate $ChaptersMD

        git pull     

        rm ./docs/sources/*.zip

# – uses: montudor/action-zip@v0.1.0

#   with:

#     args: zip -qq -r ./Chapter01.zip ./docs/sources/Chapter01.zip

    – name: Zip Release Chapter01

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter01.zip

path: ./Chapter01/FastExtractDocumentMetadata

    – name: Zip Release Chapter02

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter02.zip

path: ./Chapter02/FastExtractDocumentMetadata

    – name: Zip Release Chapter03

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter03.zip

path: ./Chapter03/FastExtractDocumentMetadata

    – name: Zip Release Chapter04

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter04.zip

path: ./Chapter04/FastExtractDocumentMetadata

    – name: Zip Release Chapter05

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter05.zip

path: ./Chapter05/FastExtractDocumentMetadata

    – name: Zip Release Chapter06

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter06.zip

path: ./Chapter06/FastExtractDocumentMetadata

    – name: Zip Release Chapter07

uses: TheDoctor0/zip-release@v0.2.1

with:       

filename: ./docs/sources/Chapter07.zip

path: ./Chapter07/FastExtractDocumentMetadata

# – name: Zip Release Chapter05

#   uses: TheDoctor0/zip-release@v0.2.1

#   with:       

#     filename: ./docs/sources/Chapter05.zip       

#     path: ./Chapter05/FastExtractDocumentMetadata

    – name: Commit files

run: |

        git config –local user.email “action@github.com”

        git config –local user.name “GitHub Action”

        git add –all

        git commit -m “generate zip files” -a –allow-empty

    – name: Push changes

uses: ad-m/github-push-action@master

with:

github_token: ${{ secrets.GITHUB_TOKEN }}

#   runs-on: windows-latest  

#   # runs:

#   #   using: ‘docker’

#   #   image: ‘print/exportPDF.txt’

#   steps:

#   – uses: actions/checkout@v2

#   – name: print pdf

#     run: |

#       cd print

#       ./getBook.bat

I know that are really lot of code, but the scope was done: genreating pdf  , odt, word and epub.

Blog posts about this topic

Console2SAAS

A mini-e-book about how to transform a Console to a SAAS application
Download the book for free from https://ignatandrei.github.io/console_to_saas/consoleToSaas.pdf.html
Buy the book from Amazon , if you want to support me : https://www.amazon.com/dp/B08N56SD4D
NoBlog 
1Introduction
2Technical Details
3Console2SAAS-Chapter1
4Console2SAAS-Chapter2
5Console2SAAS-Chapter3
6Console2SAAS-Chapter4
7Console2SAAS-Chapter5
8Console2SAAS-Chapter6
9Console2SAAS-Chapter7
10Console2SAAS-PM