ryardley / indexr Goto Github PK
View Code? Open in Web Editor NEWAutogenerate dynamic ES6 index modules.
Autogenerate dynamic ES6 index modules.
I am seeing quite a lot of this from libraries:
// Loading partial methods in to limit dependencies
import flatten from 'lodash/flatten';
whilst you can also do
// Loading named export
import {flatten} from 'lodash';
as well as
// Loading default property
import _ from 'lodash';
_.flatten(fooArray);
and also
import * as _ from 'lodash';
_.flatten(fooArray);
However for the reducer or dynamic module routes usecase it would also be great to have access to all the submods as an array:
import { all } from './modules';
all.map(app::use);
Because of CommonJS heritage it is intuitive that ES6 does this automatically however it does not for all the right reasons mainly because the default export is simply a named export called default.
An index should be able to provide all of this automatically.
import method1 from './method1';
import method2 from './method2';
import method3 from './method3';
export { method1 as method1 };
export { method2 as method2 };
export { method3 as method3 };
export {[
method1,
method2,
method3
] as all };
export default {
method1,
method2,
method3,
all,
};
This should probably be the default behaviour for indexr and the main usecase.
Workflow should probably be:
indexr
by default will create an index recursively unless you specify not to within the glob patterns found within .indexrignore
or .indexrrc
.indexrrc.js
to configure the different things indexr can do as it creates the indexes. Perhaps define plugins that change the way indexr works./* indexr-ignore */
Indexr should provide both named exports and custom named collections. Modules are included by default within an all collection as well as named exports. Modules can opt in to of a custom collection using /* indexr-collection reducers */
Allow for configuration via configuration file. probably .indexrc.js
or something similar
When indexr is exporting arrays. Should modules require other modules first in the list that intent should be able to be specified with some sort of dependency manifest.
It is annoying to have to sync docs before publishing. Look into ways to automatically create the docs as it should be possible to create an API markdown from the cli help output.
Need some information on this somewhere. Webpack/Browserify/Babel/Gulp.
Hi,
I just tried global installation and it choked
$ npm install indexr -g
/Users/gleb/.nvm/versions/node/v6.3.1/bin/indexr -> /Users/gleb/.nvm/versions/node/v6.3.1/lib/node_modules/indexr/dist/bin.js
/Users/gleb/.nvm/versions/node/v6.3.1/lib
└─┬ [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
~/git/utils on master*
$ indexr src
module.js:442
throw err;
^
Error: Cannot find module 'chokidar'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/gleb/.nvm/versions/node/v6.3.1/lib/node_modules/indexr/dist/modules/watch/index.js:8:17)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
index.js
whilst headers are checked to know whether or not to overwrite an index file.The create-index
package uses a specific string that acts as a command to work out if it is allowed to overwrite a file or now. I think this should be built in perhaps following the model laid down by eslint.
/* indexr-allow-overwrite */
// This file is autogenerated by indexr.
// Do not edit this file.
// Check this file into source control.
...
Currently at 93% lets get to 100%.
Example:
import {list, object, reducers} from './plugins/index.r';
This means we need to output only a single file but to implement we would need to have #12 done as the configuration would be more complex that one can easily achieve from the commandline.
The following comes from reddit:
Reddit user theillustratedlife says:
Would be much more interesting if it did named exports. I have literally never wanted to export an array of modules as an index. Two problems:
How am I supposed to know which modules are at which index?
const [a, c] = require('./');
What if module b gets added to a folder that contains a and c? If I rerun indexr, I'll have code that should point at c (position 1 in the old array) and now points at b (position 1 in the new array). This is very bad.
The index I really want lets me do this:
import {
a,
c,
} from './';
Though even then, I'd want to test my build process to verify that it properly tree-shakes imported but unused modules. And since imports can have side-effects, I'm not sure that could always work.
Hi,
Nice project!
I have however a question; I usually name my export like following:
// test.js
export function foo() {
return 'foo';
}
export function foo() {
return 'bar';
}
But when I use indexr
, it will create the following content (indexr -m "." --submodules "test.js" . --named-exports
):
export { default as testJs } from './test.js';
Which will not work :/
If indexr
, however, created the following file:
export * from './test.js';
everything would work perfectly. Is it possible to add an extra flag to just export everything (star export as shown above)?
When you run indexr it will will write files according to the input you have given it. It should really check to see if the file is an autogenerated file or not before writing and if not it should generate the file.
Hi there,
It would be useful if you could specify a different formatter than camelCase for the exported module name (export { default as moduleName } from '/path/to/module.name'
).
I am working on a React app, and want my exports in PascalCase to make them look consistent with other components.
Ideally this could be 'configurable' but it's kind of hard to have a javascript function as a config value. I am thinking a mvp could be a flag for camelCase vs PascalCase?
The camelCase repo lists this in their related list for a PascalCase formatter.
Not 100% sure if this is the right way to go as it depends on the features of the product as we move forward .
I would like this comment to act as a spec for version 2.
If you have any comments or suggestions please add them below and I will incorporate them into this comment.
So if any one is out there and has an opinion I am not comfortable with the default index file that Indexr exports. Currently it is index.r.js
. If anyone has preferences or thinks things should be done differently perhaps you can chime in here.
This probably needs to be done outside of mocha as we need to import the code we have created. Not sure exactly how best to make this happen but should be able to kludge something together.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.