Import Index Generator
Simple tool which read the content of a directory (without reading the content of its subdirectories) and generates an JS2015 Javascript file which import all those files and has a default export with an array which contains for each file its name and what it exports, because they are assumed to be Javascript module files.
Considerations
This tool has been developed with NodeJS v7 and we don't think to add support for previous versions.
Install
With NPM
npm install import-index-generator
With Yarn
yarn add import-index-generator
Docs
The tool will show their own help command if your run it without any argument.
If you don't have installed it globally (it's preferable not to so, for the reasons mentioned on yarn docs comemnt), then run ./node_modules/.bin/iigen
You will get the same below message
iigen [-r] [src-dir-path] [output] [list-extensions]
Get the list of the file just contained in the passed source directory path and
generates "index" files which exports a list of objects with the file name
(just the name with the extension but without the path) and the exported stuff.
The [-r] flag indicates to recur the source directory to list all the files on
it and its sub directories. It's optional, hence, by default, the tool doesn't
recur the directory. The flag can be set in any position, it isn't stricly
necessary to appear in the same position written in this help message.
The [ouput] parameter is optional an it's the file path used to write the
generated "index" file, otherwise a temporary file is generated.
The third parameter [list-extensions] is optional and only can be provided if
the [output] parameters is provided; it's a list of file extensions, comma
separated (with no spaces) which are considered to be Javascript modules, js by
default.
The command print out to the stdout the path to the autogenerated "index" file.
Example:
if the list of files in "my-src/components/" directory is
- module.js
- auth.vue
- ignoreme
executing: iigen my-src/components components-index.js js,vue
The command will output in the stdout 'components-index.js' and will generate
such file with the next content:
import * as i0 from './my-src/components/auth.vue'
import * as i1 from './my-src/components/module.js'
export default [{ filename: 'auth.vue', exported: i0 }, { filename: 'module.js', exported: i1 }]
NOTE the tool doens't check the content of the files, so they are assumed to be
wel formatted Javascript modules
Development
Install dependencies npm install
or yarn install
(recommended).
lint
All the JS code is linted using standard
npm run lint
or yarn run lint
Test
npm test
or yarn test
License
The MIT License (MIT)
Copyright (c) 2017 cycloid.io
Read the LICENSE file for more information.