Unable to setup multiple custom formats using CLI
morewry opened this issue · comments
I will be setting up at least three custom formats for a set of tokens and ran into what appears to be a limitation in the CLI.
Comma Separated 1
First, trying comma separated values like used for multiple formats,
Input
theo ./tokens.json --setup ./build/elementFormat.js,./build/previewFormat.js --format map.scss,module.js,ce.js,preview.html --dest $(pwd)
Output
Error: Cannot find module '/Users/morewry/project/build/elementFormat.js,./build/previewFormat.js'
Comma Separated 2
Second, adding a space,
Input
theo ./tokens.json --setup ./build/elementFormat.js, ./build/previewFormat.js --format map.scss,module.js,ce.js,preview.html --dest $(pwd)
Output
Error: Cannot find module '/Users/morewry/project/build/elementFormat.js,'
Space Only
Input
theo ./tokens.json --setup ./build/ceFormat.js ./build/previewFormat.js --format map.scss,module.js,ce.js,preview.html --dest $(pwd)
Output
💩 Oops, something went wrong: Error: Format "preview.html" is not registered
Multiple Options
Input
theo ./tokens.json --setup ./build/elementFormat.js --setup ./build/previewFormat.js --format map.scss,module.js,ce.js,preview.html --dest $(pwd)
Output
TypeError: Path must be a string. Received [ './build/elementFormat.js', './build/previewFormat.js' ]
Looks to me like this isn't a part of the CLI implementation so far based on:
It takes in optimist's parsing of setup:
Line 12 in c450de1
Then tries to require it as a module:
Lines 8 to 12 in c450de1
Tests show only a single custom format:
theo/bin/__tests__/theo.spec.js
Lines 55 to 61 in c450de1
I'd be happy to pull request this if you can tell me what approach you'd like to support. I'd lean toward Comma Separated 1 because it is the same as the syntax for multiple formats, but it'd be trivial to support both that and Multiple Options.
I think the recommended approach would be to register all transforms in the same file. If you want to split then up in different files, you can just require them from the setup file.
Yeah, I definitely don't want their registration source code in the same file. Some of the formats will be broken out into their own npm packages later, so that'd have a very limited shelf life.
If I'm understanding you correctly, you're saying that to register and use multiple custom formats, we should create a setup file specifically to aggregate the formats, e.g.
const elementFormat = require('./build/elementFormat');
const previewFormat = require('./build/previewFormat');
module.exports = function (theo) {
elementFormat(theo);
previewFormat(theo);
};
So the setup file is more of a configuration, rather than a definition of a specific format or transform.
Yeah, that was the original idea.