Skip to content

Convert/typescript #3

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 5 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix create ts
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed May 30, 2020
commit 70ce3f4cc571b2f51d5909f9bb336fe487b2ebc2
18 changes: 12 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import arg from "arg";
import * as inquirer from "inquirer";
import simpleGit from "simple-git/promise";
import * as fs from "fs";
import * as T from "../typings/tutorial";
import build, { BuildOptions } from "./build";
import create from "./create";

// import not working
const arg = require("arg");

type Q = inquirer.Question<any> & { choices?: string[] };

type ParsedArgs = {
Expand Down Expand Up @@ -49,18 +51,21 @@ function parseArgumentsIntoOptions(rawArgs: string[]): ParsedArgs {
argv: rawArgs.slice(2),
}
);
console.log(args);
return {
command: args["_"][0],
git: args["--git"],
dir: args["--dir"],
codeBranch: args["--code"],
setupBranch: args["--setup"],
output: args["--output"],
output: args["--output"] || "./config.json",
help: args["--help"] || false,
};
}

async function promptForMissingOptions(options: ParsedArgs): Promise<Options> {
export async function promptForMissingOptions(
options: ParsedArgs
): Promise<Options> {
const questions: Q[] = [];

// if no git remote addres is provided, assume current folder
Expand Down Expand Up @@ -147,7 +152,7 @@ async function promptForMissingOptions(options: ParsedArgs): Promise<Options> {
};
}

export async function cli(args: string[]) {
export async function cli(args: string[]): Promise<void> {
let parsedArgs: ParsedArgs = parseArgumentsIntoOptions(args);

// If help called just print the help text and exit
Expand All @@ -174,11 +179,12 @@ export async function cli(args: string[]) {
console.log(JSON.stringify(tutorial, null, 2));
}
}
return;
break;

case "create":
console.log("here");
create(process.cwd());
return;
break;
}
}
}
14 changes: 3 additions & 11 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import * as ncp from "ncp";
import * as path from "path";
import { promisify } from "util";
import * as os from "os";

const copy = promisify(ncp);

const copyFiles = async (filePath: string) => {
const copyFiles = async (filePath: string): Promise<void> => {
try {
let filePath = new URL(import.meta.url).pathname;

if (os.platform() === "win32") {
// removes the leading drive letter from the path
filePath = filePath.substr(3);
}

const templateDirectory = path.resolve(filePath, "..", "templates");

const pathToSrc = path.join(__dirname, "..", "src");
const templateDirectory = path.resolve(pathToSrc, "templates");
const targetDirectory = process.cwd();

await copy(templateDirectory, targetDirectory, {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "esnext",
"module": "commonjs",
"target": "es2018",
"outDir": "build",
"lib": ["es2018", "dom"],
Expand All @@ -22,5 +22,5 @@
"removeComments": true,
"skipLibCheck": true
},
"exclude": ["node_modules", ".vscode", "bin", "build", "test"]
"exclude": [".vscode", "bin", "build", "test"]
}