20200522

PUTTING IT ALL TOGETHER

Let's start with a simple "front-door" to our script in cli.js that

  1. parses any arguments the user types in with yargs
  2. loads up an environment variables we've save in our .env file with dotenv
  3. requires in our various scripts (now just 1 or 2, but maybe more ultimately)

CREATING FILES

Let's start by just learning how to create files with node's fs module (docs here). Let's create a simple markdown string, for now, and then save it as a file.

const fs = require('fs');
const cp = require('child_process');
const myPlaceholderMarkdown = `
# TITLE
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam luctus neque non nisi placerat, sodales ullamcorper nulla sodales.
`

const myTool = function(options){
  fs.writeFileSync(`${ROOT_DIR}/data/test.md`, myPlaceholderMarkdown);
  cp.spawn('open', ['-a', 'Atom', `${ROOT_DIR}/data/test.md`])
}

module.exports = myTool;