Skip to content

Updated icons command to be ESM #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions .core/.cli/commands/reactium/icons/actions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const path = require('path');
const chalk = require('chalk');
const fs = require('fs-extra');
const _ = require('underscore');
const op = require('object-path');
const prettier = require('prettier').format;
const handlebars = require('handlebars').compile;
const cc = require('camelcase');

module.exports = spinner => {
import chalk from 'chalk';
import fs from 'fs-extra';
import hb from 'handlebars';
import cc from 'camelcase';
import op from 'object-path';
import path from 'node:path';

// import { fileURLToPath } from 'node:url';
// const __dirname = path.dirname(fileURLToPath(import.meta.url));

import dirname from '../dirname.mjs';
const __dirname = dirname(import.meta.url);

const handlebars = hb.compile;

export default spinner => {
const message = text => {
if (spinner) {
spinner.text = text;
Expand All @@ -17,15 +23,15 @@ module.exports = spinner => {
let svgs = {};

return {
scan: ({ action, params, props }) => {
scan: async ({ action, params }) => {
const { source } = params;

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

const filePath = path.normalize(source);
const icons = require(filePath).icons;
const { icons } = await import(filePath);

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

create: ({ action, params, props }) => {
create: ({ action, params }) => {
const { destination, name } = params;
const dir = path.normalize(path.join(destination, 'svg'));

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

index: ({ action, params, props }) => {
index: ({ action, params }) => {
const { destination, name } = params;
const dir = path.normalize(path.join(destination, name));

Expand Down
9 changes: 5 additions & 4 deletions .core/.cli/commands/reactium/icons/generator.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const ora = require('ora');
const ActionSequence = require('action-sequence');
import ora from 'ora';
import ACTIONS from './actions.js';
import ActionSequence from 'action-sequence';

module.exports = ({ action, params, props }) => {
export default async ({ params, props }) => {
const spinner = ora({
spinner: 'dots',
color: 'cyan',
});

spinner.start();

const actions = require('./actions')(spinner);
const actions = ACTIONS(spinner);

return ActionSequence({
actions,
Expand Down
29 changes: 13 additions & 16 deletions .core/.cli/commands/reactium/icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
* -----------------------------------------------------------------------------
*/

const path = require('path');
const chalk = require('chalk');
const _ = require('underscore');
const op = require('object-path');
const prettier = require('prettier');
const camelcase = require('camelcase');
const generator = require('./generator');
const { error, message } = arcli;
import generator from './generator.js';
import { fileURLToPath } from 'node:url';

const { _, fs, chalk, op, camelcase, message, path, prettier } = arcli;

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const pkg = JSON.parse(
fs.readFileSync(path.normalize(`${__dirname}/package.json`)),
);

const formatDestination = (val, props) => {
const { cwd } = props;
Expand All @@ -37,7 +39,7 @@ const formatDestination = (val, props) => {

const NAME = 'icons';

const DESC = 'Reactium: Import icons from an Icomoon selection file.';
const DESC = pkg.description;

const CANCELED = 'Action canceled!';

Expand Down Expand Up @@ -154,8 +156,6 @@ const PREFLIGHT = ({ params }) => {
};

const SCHEMA = () => {
//const { cwd, prompt } = props;

return {
properties: {
name: {
Expand All @@ -180,7 +180,7 @@ const SCHEMA = () => {

const ACTION = ({ opt, props }) => {
let params;
const { cwd, prompt } = props;
const { prompt } = props;
const schema = SCHEMA({ props });
const ovr = FLAGS_TO_PARAMS({ opt });

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

module.exports = {
COMMAND,
NAME,
};
export { COMMAND, NAME };
9 changes: 9 additions & 0 deletions .core/.cli/commands/reactium/icons/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "module",
"name": "icon-generator",
"version": "0.0.1",
"description": "Reactium: Import icons from an Icomoon selection file.",
"main": "index.js",
"author": "Reactium LLC",
"license": "MIT"
}