asciidoctor / asciidoctor-cli.js

The Command Line Interface (CLI) for Asciidoctor.js
https://asciidoctor.org
MIT License
15 stars 9 forks source link

Allow to require a library with -r/--require option #15

Closed ggrossetie closed 6 years ago

ggrossetie commented 7 years ago

Since library can export a function, we should maybe use a syntax to define explicitly how the library should be loaded. Eg:

asciidoctorjs -r asciidoctor-reveal.js
require('asciidoctor-reveal.js');
asciidoctorjs -r asciidoctor-reveal.js#()
require('asciidoctor-reveal.js')();
asciidoctorjs -r asciidoctor-reveal.js#init()
require('asciidoctor-reveal.js').init();

This syntax could be useful but it has some limitations and it will be hard to cover all the cases (define initialization options, call a nested export objects/functions, use a multi-step initialization...)

Instead a user could create a file to initialize all the required libraries:

.lib-init.js

require('asciidoctor-reveal.js');
require ('asciidoctor-template.js')();
asciidoctorjs -r ./lib-init.js
mojavelinux commented 6 years ago

I don't think we should do anything different than what Node does. I think it's up to the library creator to provide a script that can respond to a direct require call.

I added this support in Antora, so you can use that as a reference. See https://gitlab.com/antora/antora/blob/4f84db7edca0f859ee443d2f2dd74887ee97975c/packages/cli/lib/cli.js#L26-40

ggrossetie commented 6 years ago

I don't think we should do anything different than what Node does. I think it's up to the library creator to provide a script that can respond to a direct require call.

I agree, keep it simple.

I added this support in Antora, so you can use that as a reference.

Thanks for sharing, that's exactly what we need 😄