Skip to content

Commit

Permalink
Use minimist for field-scripts & create-fm.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Aug 29, 2023
1 parent e06e435 commit 6e1ac25
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/create-field-module/bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

/* eslint-disable no-console */

import minimist from 'minimist';
import create from './index.js';

async function run() {
const args = process.argv.slice(2);
try {
const targetDir = args[0];
const argv = minimist(process.argv.slice(2));
const { _: [targetDir] } = argv;
await create(targetDir);
} catch (error) {
console.error(error);
Expand Down
1 change: 1 addition & 0 deletions packages/create-field-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "Jamie Gaehring <gaehj457@gmail.com> (https://jgaehring.com)",
"license": "GPL-3.0-or-later",
"dependencies": {
"minimist": "^1.2.8",
"prompts": "^2.4.2"
},
"repository": {
Expand Down
22 changes: 6 additions & 16 deletions packages/field-scripts/bin/field-scripts.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#!/usr/bin/env node

/* eslint-disable no-console */
import path from 'path';

const parseOptions = (args = []) => {
const [head, ...tail] = args;
if (!head || tail.length === 0) return {};
if (head === '--config' && typeof tail[0] === 'string') {
const config = path.resolve(process.cwd(), tail[0]);
return { config };
}
return parseOptions(tail);
};
import minimist from 'minimist';

const printResults = ({
info, install, lib,
Expand All @@ -21,23 +13,21 @@ lib: ${lib.location}
`.trim());

async function run() {
const args = process.argv.slice(2);
const [script, ...rest] = args;
if (script === 'build-module') {
const args = minimist(process.argv.slice(2));
const { _: [command], ...options } = args;
if (command === 'build-module') {
const { default: build } = await import('../build-module/index.js');
try {
const options = parseOptions(rest);
const results = await build(options);
printResults(results);
} catch (error) {
console.error(error);
process.exit(1);
}
}
if (script === 'develop-module') {
if (command === 'develop-module') {
const { default: develop } = await import('../develop-module/index.js');
try {
const options = parseOptions(rest);
await develop(options);
} catch (error) {
console.error(error);
Expand Down
1 change: 1 addition & 0 deletions packages/field-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@vitejs/plugin-vue": "^4.2.3",
"field-kit-utils": "2.0.0-alpha.1",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"ramda": "^0.28.0",
"vite": "^4.3.9"
},
Expand Down

0 comments on commit 6e1ac25

Please sign in to comment.