Skip to content

Commit 65f4fa3

Browse files
camdagr8Cam Tullos
and
Cam Tullos
authored
Updated icons command to be ESM (#213)
Co-authored-by: Cam Tullos <[email protected]>
1 parent 542cb7c commit 65f4fa3

File tree

4 files changed

+47
-34
lines changed

4 files changed

+47
-34
lines changed

.core/.cli/commands/reactium/icons/actions.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
const path = require('path');
2-
const chalk = require('chalk');
3-
const fs = require('fs-extra');
4-
const _ = require('underscore');
5-
const op = require('object-path');
6-
const prettier = require('prettier').format;
7-
const handlebars = require('handlebars').compile;
8-
const cc = require('camelcase');
9-
10-
module.exports = spinner => {
1+
import chalk from 'chalk';
2+
import fs from 'fs-extra';
3+
import hb from 'handlebars';
4+
import cc from 'camelcase';
5+
import op from 'object-path';
6+
import path from 'node:path';
7+
8+
// import { fileURLToPath } from 'node:url';
9+
// const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
11+
import dirname from '../dirname.mjs';
12+
const __dirname = dirname(import.meta.url);
13+
14+
const handlebars = hb.compile;
15+
16+
export default spinner => {
1117
const message = text => {
1218
if (spinner) {
1319
spinner.text = text;
@@ -17,15 +23,15 @@ module.exports = spinner => {
1723
let svgs = {};
1824

1925
return {
20-
scan: ({ action, params, props }) => {
26+
scan: async ({ action, params }) => {
2127
const { source } = params;
2228

2329
message(
2430
`Scanning icon file ${chalk.cyan(path.basename(source))}...`,
2531
);
2632

2733
const filePath = path.normalize(source);
28-
const icons = require(filePath).icons;
34+
const { icons } = await import(filePath);
2935

3036
svgs = icons.reduce((obj, item) => {
3137
const id = cc(op.get(item, 'properties.name'), {
@@ -39,7 +45,7 @@ module.exports = spinner => {
3945
return Promise.resolve({ action, status: 200 });
4046
},
4147

42-
create: ({ action, params, props }) => {
48+
create: ({ action, params }) => {
4349
const { destination, name } = params;
4450
const dir = path.normalize(path.join(destination, 'svg'));
4551

@@ -64,7 +70,7 @@ module.exports = spinner => {
6470
return Promise.resolve({ action, status: 200 });
6571
},
6672

67-
index: ({ action, params, props }) => {
73+
index: ({ action, params }) => {
6874
const { destination, name } = params;
6975
const dir = path.normalize(path.join(destination, name));
7076

.core/.cli/commands/reactium/icons/generator.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const ora = require('ora');
2-
const ActionSequence = require('action-sequence');
1+
import ora from 'ora';
2+
import ACTIONS from './actions.js';
3+
import ActionSequence from 'action-sequence';
34

4-
module.exports = ({ action, params, props }) => {
5+
export default async ({ params, props }) => {
56
const spinner = ora({
67
spinner: 'dots',
78
color: 'cyan',
89
});
910

1011
spinner.start();
1112

12-
const actions = require('./actions')(spinner);
13+
const actions = ACTIONS(spinner);
1314

1415
return ActionSequence({
1516
actions,

.core/.cli/commands/reactium/icons/index.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
* -----------------------------------------------------------------------------
55
*/
66

7-
const path = require('path');
8-
const chalk = require('chalk');
9-
const _ = require('underscore');
10-
const op = require('object-path');
11-
const prettier = require('prettier');
12-
const camelcase = require('camelcase');
13-
const generator = require('./generator');
14-
const { error, message } = arcli;
7+
import generator from './generator.js';
8+
import { fileURLToPath } from 'node:url';
9+
10+
const { _, fs, chalk, op, camelcase, message, path, prettier } = arcli;
11+
12+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
13+
14+
const pkg = JSON.parse(
15+
fs.readFileSync(path.normalize(`${__dirname}/package.json`)),
16+
);
1517

1618
const formatDestination = (val, props) => {
1719
const { cwd } = props;
@@ -37,7 +39,7 @@ const formatDestination = (val, props) => {
3739

3840
const NAME = 'icons';
3941

40-
const DESC = 'Reactium: Import icons from an Icomoon selection file.';
42+
const DESC = pkg.description;
4143

4244
const CANCELED = 'Action canceled!';
4345

@@ -154,8 +156,6 @@ const PREFLIGHT = ({ params }) => {
154156
};
155157

156158
const SCHEMA = () => {
157-
//const { cwd, prompt } = props;
158-
159159
return {
160160
properties: {
161161
name: {
@@ -180,7 +180,7 @@ const SCHEMA = () => {
180180

181181
const ACTION = ({ opt, props }) => {
182182
let params;
183-
const { cwd, prompt } = props;
183+
const { prompt } = props;
184184
const schema = SCHEMA({ props });
185185
const ovr = FLAGS_TO_PARAMS({ opt });
186186

@@ -232,7 +232,4 @@ const COMMAND = ({ program, props }) =>
232232
.option('-n, --name [name]', 'Name of the icon package.')
233233
.on('--help', () => HELP(props));
234234

235-
module.exports = {
236-
COMMAND,
237-
NAME,
238-
};
235+
export { COMMAND, NAME };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "module",
3+
"name": "icon-generator",
4+
"version": "0.0.1",
5+
"description": "Reactium: Import icons from an Icomoon selection file.",
6+
"main": "index.js",
7+
"author": "Reactium LLC",
8+
"license": "MIT"
9+
}

0 commit comments

Comments
 (0)