From 1529491b48836db9ed8e842b42c54ae11839403e Mon Sep 17 00:00:00 2001 From: Ridwan Olanrewaju Date: Sat, 13 Jun 2020 00:08:34 +0100 Subject: [PATCH 1/2] made changes to the readme file --- readme.md | 129 +++++++++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 59 deletions(-) diff --git a/readme.md b/readme.md index bc9f478..a5ab9b3 100644 --- a/readme.md +++ b/readme.md @@ -10,13 +10,17 @@ This package contains scripts that help build client code: - `inline-environment-variables` replaces references to `process.env.` with their values in a JS file. -# Installation +--- + +## Installation `npm i --save-dev inline-scripts` -# CLI Examples +--- + +## CLI Examples -## `inline-script-tags` +### inline-script-tags ```html @@ -26,29 +30,31 @@ This package contains scripts that help build client code: ```js // src/main.js -console.log('Welcome'); +console.log("Welcome"); ``` -`$ inline-scripts src/index.html out/index.html` +`$ inline-script-tags src/index.html out/index.html` ```html

Welcome

- + ``` -## `inline-stylesheets` +### inline-stylesheets ```html

Welcome

- + ``` ```css /* src/style.css */ body { - color: red; + color: red; } ``` @@ -57,17 +63,19 @@ body { ```html

Welcome

- + ``` -## `inline-images` +### inline-images ```html

Welcome

- + ``` `$ inline-images src/index.html out/index.html` @@ -75,26 +83,27 @@ body { ```html

Welcome

- + ``` -## `inline-requires` +### inline-requires ```js // src/main.js -let math = require('./mathHelper'); -console.log('10 ^ 2 =', math.square(10)); +let math = require("./mathHelper"); +console.log("10 ^ 2 =", math.square(10)); ``` ```js // src/mathHelper.js module.exports = { - square: a => a * a, - add: (a, b) => a + b, - double: a => a * 2, - increment: a => a++, + square: (a) => a * a, + add: (a, b) => a + b, + double: (a) => a * 2, + increment: (a) => a++, }; - ``` `$ inline-requires src/main.js out/main.js` @@ -102,67 +111,69 @@ module.exports = { ```js // out/main.js let dependencies = { - 'main': (require, module) => { - let math = require('./mathHelper'); - console.log('10 ^ 2 =', math.square(10)); - }, - 'mathHelper': (require, module) => { - module.exports = { - square: a => a * a, - add: (a, b) => a + b, - double: a => a * 2, - increment: a => a++, - }; - } + main: (require, module) => { + let math = require("./mathHelper"); + console.log("10 ^ 2 =", math.square(10)); + }, + mathHelper: (require, module) => { + module.exports = { + square: (a) => a * a, + add: (a, b) => a + b, + double: (a) => a * 2, + increment: (a) => a++, + }; + }, }; let fakeRequire = (currentPath, dependencyPath) => { - currentPath.pop(); - dependencyPath - .replace(/.js$/, '') - .split('/') - .filter(a => a !== '.') - .forEach(pathFragment => { - if (pathFragment === '..') - currentPath.pop(); - else - currentPath.push(pathFragment); - }); - - let module = {}; - dependencies[currentPath.toString()](fakeRequire.bind(null, currentPath), module); - return module.exports; + currentPath.pop(); + dependencyPath + .replace(/.js$/, "") + .split("/") + .filter((a) => a !== ".") + .forEach((pathFragment) => { + if (pathFragment === "..") currentPath.pop(); + else currentPath.push(pathFragment); + }); + + let module = {}; + dependencies[currentPath.toString()]( + fakeRequire.bind(null, currentPath), + module + ); + return module.exports; }; -dependencies['main'](fakeRequire.bind(null, ['main'])); +dependencies["main"](fakeRequire.bind(null, ["main"])); ``` -## `inline-environment-variables` - +### `inline-environment-variables` ```js // src/main.js -console.log('server URL is' + process.env.SERVER_URL); +console.log("server URL is" + process.env.SERVER_URL); ``` `$ inline-environment-variables src/main.js out/main.js` ```js // out/main.js -console.log('server URL is' + 'https://api.github.com'); +console.log("server URL is" + "https://api.github.com"); ``` -## Note on parameters +### Note on parameters All scripts usually take 2 parameters: the input and output files. -`$ inline-scripts src/index.html out/index.html .` +`$ inline-[script_type] src/index.html out/index.html .` For convenience, if the 2nd parameter is `.`, the output will replace the input file. -`$ inline-scripts out/index.html .` +`$ inline-[script_type] out/index.html .` + +--- -# JS API +## JS API `const {inlineEnvironmentVariables, inlineRequires, inlineScriptTags} = require(inline-scripts);` From b3883c9af1afc11e2620af76e6f1db70f7bac0aa Mon Sep 17 00:00:00 2001 From: Ridwan Olanrewaju Date: Sat, 13 Jun 2020 00:20:27 +0100 Subject: [PATCH 2/2] corrected some text --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index a5ab9b3..580a33b 100644 --- a/readme.md +++ b/readme.md @@ -147,7 +147,7 @@ let fakeRequire = (currentPath, dependencyPath) => { dependencies["main"](fakeRequire.bind(null, ["main"])); ``` -### `inline-environment-variables` +### inline-environment-variables ```js // src/main.js @@ -165,11 +165,11 @@ console.log("server URL is" + "https://api.github.com"); All scripts usually take 2 parameters: the input and output files. -`$ inline-[script_type] src/index.html out/index.html .` +`$ inline-[script_type] src/index.html out/index.html` For convenience, if the 2nd parameter is `.`, the output will replace the input file. -`$ inline-[script_type] out/index.html .` +`$ inline-[script_type] src/index.html .` ---