Bootcamp
Search…
2.ICE.2: Modules, Disk Reading

Setup

Start with the base Node repo.

Base

CSS Conversion Module

Extract CSS command line conversions from 2.POCE.1: CSS Command Line into a module file called cssConvert.js. The module should export all the conversion functions.

JavaScript Comment Reader

Read in a JavaScript file as per examples in Module 2.4. Output the line numbers that have comments in them, each on a new line with the relevant comment.
myJsFile.js
// Add 2 numbers and return the result
const add = (a, b) => {
return a + b;
};
Read in the JS file.
node index.js myJsFile.js
Command template:
node index.js <JS FILE TO READ>
Output:
Line 1: "Add 2 numbers and return the result"
Move the comment-reading code into its own module, e.g. parseJs.js, that exports a named function showComments that takes a filename as input.

index.js

import { showComments } from 'parseJs.js';
​
// ... get the filename
​
// pass it to the module
showComments(filename);

Comfortable

JS Function Parameter Reader

List all the functions in the code and their parameters. This should work for functions in general and not just the specific function in the example below.
// Add 2 numbers and return the result
const add = (a, b) => {
return a + b;
};
Read in the JS file.
node index.js myJsFile.js
Outputs:
add: a, b
  1. 1.
    Add the parameter-reading code to the above parseJs module and export it as a named function, e.g. showParams.
  2. 2.
    Import and use showParams in index.js like we did with showComments.

Param Reader with Sort Order

Add a command-line option to index.js to list functions and their parameters by line number or alphabetically by function name.

More Comfortable

Analysis on Files in Nested Folders

Allow your program to take an absolute path and find all files in that folder with the same name as the 4th argv parameter and perform either showComments or showParams analysis on those files.
For example, the following invocation may perform showParams analysis on all files named script.js inside the /Users/kai/code folder.
node index.js /Users/kai/code script.js
The following GitHub Gist shows how to read file and folder names in nested folders. https://gist.github.com/awongh/394d41f845f7f81f3b27a5cd36dccbd9​