Turn your collection of CSV files into a node module that exports them.
- Make a new directory for your package.
- There, make a node.js script (this example will assume the filename
csv2pojo.js
) with code like this:'use strict'; module.exports = require('export-module-csv-files-sync-pmb')(module);
- Make a
package.json
with themain
key set to"csv2pojo.js"
. - Put your
*.csv
files in that same directory or adata/
subdirectory. - Preview: Run
nodejs -p "require('.')"
to see what your package will export. - Optionally you can add custom configuration, see below.
- Optionally generate a JSON and AMD version, see below-
- Use and/or publish your package. :-)
- Replace the
(module)
part from above with({ module: module })
. That config object is merged with the defaults from cfg.default.js, go have a look for inspiration. - Add and adjust options in your config object as desired and retry the preview step.
- Back up your project, because target files will be overwritten.
- If your JSON directory (option
overrideJsonDir
, defaultdist
) doesn't exist yet, create it. - Run
nodejs csv2pojo.js --save-json
- Optionally set that command as a git hook, npm pre-publish script or similar, so your JSON and AMD files are kept in sync automatically.
- needs more/better tests and docs
ISC