Skip to content

Commit

Permalink
feat(init): Adjusted setup and passing initial prompts with inquirer v8.
Browse files Browse the repository at this point in the history
  • Loading branch information
himerus committed Oct 12, 2022
1 parent 9ed9303 commit 674117a
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 67 deletions.
21 changes: 20 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,24 @@
"extends": [
"oclif",
"oclif-typescript"
]
],
"rules": {
"object-curly-spacing": "off",
"semi": "off",
"@typescript-eslint/semi": "warn",
"quotes": "off",
"@typescript-eslint/quotes": [
"error",
"double",
{
"allowTemplateLiterals": true
}
],
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
]
},
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/tmp
node_modules
oclif.manifest.json
.history
12 changes: 6 additions & 6 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')
const oclif = require("@oclif/core");

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')
const path = require("path");
const project = path.join(__dirname, "..", "tsconfig.json");

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'
process.env.NODE_ENV = "development";

require('ts-node').register({project})
require("ts-node").register({ project });

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
oclif.run().then(oclif.flush).catch(oclif.Errors.handle);
29 changes: 22 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name": "iswap",
"version": "0.0.0",
"name": "@inlinejs/iswap",
"version": "0.0.1",
"description": "Outline to Inline Web Component Conversion Tool",
"author": "Jake Strawn @himerus",
"author": {
"name": "Jake Strawn",
"url": "https://github.com/himerus"
},
"bin": {
"convert": "./bin/run"
},
"homepage": "https://github.com/inlinejs/iswap",
"license": "MIT",
"main": "dist/index.js",
"repository": "inlinejs/iswap",
"main": "index.ts",
"repository": {
"type": "git",
"url": "https://github.com/ininejs/iswap.git"
},
"files": [
"/bin",
"/dist",
Expand All @@ -24,12 +30,16 @@
"devDependencies": {
"@oclif/test": "^2.2.2",
"@types/chai": "^4",
"@types/fs-extra": "^9.0.13",
"@types/inquirer": "^8.2.1",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.64",
"chai": "^4",
"eslint": "^7.32.0",
"eslint-config-oclif": "^4",
"eslint-config-oclif-typescript": "^1.0.3",
"fs-extra": "^10.1.0",
"inquirer": "^8.2.4",
"mocha": "^9",
"oclif": "^3",
"shx": "^0.3.3",
Expand Down Expand Up @@ -59,14 +69,19 @@
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md"
"version": "oclif readme && git add README.md",
"publish": "npm publish"
},
"engines": {
"node": ">=12.0.0"
},
"bugs": "https://github.com/inlinejs/iswap/issues",
"keywords": [
"oclif"
"oclif",
"outline",
"inline",
"inlinejs",
"web components"
],
"types": "dist/index.d.ts"
}
21 changes: 21 additions & 0 deletions src/commands/convert/convert-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import chalk = require("chalk");
import { execSync } from "node:child_process";

type Prompts = {
src: string;
dest: string;
impression: string;
};
/**
* Creates story from custom element json file
*
* @param {string} prompts - prompts: Object of the values from the prompt questions;
* @returns NULL
*/
export const convertComponent = (prompts: Prompts): void => {
try {
execSync(`echo "Converting ${prompts.src} to ${prompts.dest}..."`);
} catch (error) {
throw console.error(`${chalk.red("error")}: ${error}`);
}
};
64 changes: 64 additions & 0 deletions src/commands/convert/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Command } from "@oclif/core";
// import inquirer from "inquirer";
import * as inquirer from "inquirer";
import { convertComponent } from "./convert-component";
export default class Convert extends Command {
static description = "Converts an Outline component to InlineJS.";
static examples = ["<%= config.bin %> <%= command.id %>"];

public async run(): Promise<void> {
const sourceComponent = await inquirer.prompt([
{
name: "source",
message: "What is the name of the original component? Ex: outline-card",
type: "input",
validate: function (input: string) {
if (input && typeof input === "string") {
return true;
}

return false;
},
},
]);

const destinationComponent = await inquirer.prompt([
{
name: "destination",
message: "What is the name of the original component? Ex: inline-card",
type: "input",
validate: function (input: string) {
if (input && typeof input === "string") {
return true;
}

return false;
},
},
]);

const impression = await inquirer.prompt([
{
name: "impression",
message: "How does this tool make you feel.",
type: "list",
choices: [{ name: "good" }, { name: "great" }, { name: "angry" }],
validate: function (input: string) {
if (input && typeof input === "string") {
return true;
}

return false;
},
},
]);

// const {args, flags} = await this.parse(Init)
const prompts = {
src: sourceComponent.name,
dest: destinationComponent.name,
impression: impression.name,
};
convertComponent(prompts);
}
}
24 changes: 16 additions & 8 deletions src/commands/hello/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import {Command, Flags} from '@oclif/core'
import { Command, Flags } from "@oclif/core";

export default class Hello extends Command {
static description = 'Say hello'
static description = "Say hello";

static examples = [
`$ oex hello friend --from oclif
hello friend from oclif! (./src/commands/hello/index.ts)
`,
]
];

static flags = {
from: Flags.string({char: 'f', description: 'Who is saying hello', required: true}),
}
from: Flags.string({
char: "f",
description: "Who is saying hello",
required: true,
}),
};

static args = [{name: 'person', description: 'Person to say hello to', required: true}]
static args = [
{ name: "person", description: "Person to say hello to", required: true },
];

async run(): Promise<void> {
const {args, flags} = await this.parse(Hello)
const { args, flags } = await this.parse(Hello);

this.log(`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`)
this.log(
`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`
);
}
}
12 changes: 6 additions & 6 deletions src/commands/hello/world.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {Command} from '@oclif/core'
import { Command } from "@oclif/core";

export default class World extends Command {
static description = 'Say hello world'
static description = "Say hello world";

static examples = [
`<%= config.bin %> <%= command.id %>
hello world! (./src/commands/hello/world.ts)
`,
]
];

static flags = {}
static flags = {};

static args = []
static args = [];

async run(): Promise<void> {
this.log('hello world! (./src/commands/hello/world.ts)')
this.log("hello world! (./src/commands/hello/world.ts)");
}
}
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"outDir": "dist",
"rootDir": "src",
"strict": true,
"target": "es2019"
"target": "esnext"
},
"include": [
"src/**/*"
]
"include": ["src/**/*"]
}
Loading

0 comments on commit 674117a

Please sign in to comment.