Skip to content

Commit

Permalink
Merge pull request #35 from AlCalzone/auto-git
Browse files Browse the repository at this point in the history
Initialize the git repo automatically
  • Loading branch information
AlCalzone authored Dec 16, 2018
2 parents fea113b + 9dbb528 commit 363a214
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## __WORK_IN_PROGRESS__
* (AlCalzone) Initialize the git repo automatically (fixes #13)
* (AlCalzone) When using TypeScript, perform an initial build run (fixes #27)
* (AlCalzone) When formatting files, clear lines with only whitespace (fixes #30)
* (AlCalzone) Enable resolveJsonModule for JS files (fixes #26)
Expand Down
20 changes: 19 additions & 1 deletion build/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const tools_1 = require("./lib/tools");
const rootDir = path.resolve(yargs.argv.target || process.cwd());
/** Asks a series of questions on the CLI */
async function ask() {
let answers = {};
let answers = { cli: true };
for (const q of questions_1.questionsAndText) {
// Headlines
if (typeof q === "string") {
Expand Down Expand Up @@ -63,6 +63,8 @@ function logProgress(message) {
const installDependencies = !yargs.argv.noInstall || !!yargs.argv.install;
/** Whether an initial build should be performed */
let buildTypeScript;
/** Whether the initial commit should be performed automatically */
let gitCommit;
/** CLI-specific functionality for creating the adapter directory */
async function setupProject_CLI(answers, files) {
const rootDirName = path.basename(rootDir);
Expand All @@ -78,6 +80,19 @@ async function setupProject_CLI(answers, files) {
await tools_1.executeCommand(tools_1.isWindows ? "npm.cmd" : "npm", ["run", "build"], { cwd: targetDir, stdout: "ignore" });
}
}
if (gitCommit) {
logProgress("Initializing git repo");
// As described here: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
const gitCommandArgs = [
["init"],
["add", "."],
["commit", "-m", `"Initial commit"`],
["remote", "add", "origin", `https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}`],
];
for (const args of gitCommandArgs) {
await tools_1.executeCommand("git", args, { cwd: targetDir, stdout: "ignore", stderr: "ignore" });
}
}
console.log();
console.log(ansi_colors_1.blueBright("All done! Have fun programming! ") + ansi_colors_1.red("♥"));
}
Expand All @@ -89,6 +104,9 @@ async function setupProject_CLI(answers, files) {
if (buildTypeScript)
maxSteps++;
}
gitCommit = answers.gitCommit === "yes";
if (gitCommit)
maxSteps++;
logProgress("Generating files");
const files = await createAdapter_1.createFiles(answers);
await setupProject_CLI(answers, files);
Expand Down
8 changes: 8 additions & 0 deletions build/lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ exports.questionsAndText = [
message: "What's your email address?",
action: actionsAndTransformers_1.checkEmail,
},
{
condition: { name: "cli", value: true },
type: "select",
name: "gitCommit",
message: "Initialize the GitHub repo automatically?",
initial: "no",
choices: ["yes", "no"],
},
{
type: "select",
name: "license",
Expand Down
21 changes: 20 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const rootDir = path.resolve(yargs.argv.target || process.cwd());

/** Asks a series of questions on the CLI */
async function ask() {
let answers: Record<string, any> = {};
let answers: Record<string, any> = {cli: true};
for (const q of questionsAndText) {
// Headlines
if (typeof q === "string") {
Expand Down Expand Up @@ -65,6 +65,8 @@ function logProgress(message: string) {
const installDependencies = !yargs.argv.noInstall || !!yargs.argv.install;
/** Whether an initial build should be performed */
let buildTypeScript: boolean;
/** Whether the initial commit should be performed automatically */
let gitCommit: boolean;

/** CLI-specific functionality for creating the adapter directory */
async function setupProject_CLI(answers: Answers, files: File[]) {
Expand All @@ -84,6 +86,21 @@ async function setupProject_CLI(answers: Answers, files: File[]) {
await executeCommand(isWindows ? "npm.cmd" : "npm", ["run", "build"], { cwd: targetDir, stdout: "ignore" });
}
}

if (gitCommit) {
logProgress("Initializing git repo");
// As described here: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
const gitCommandArgs = [
["init"],
["add", "."],
["commit", "-m", `"Initial commit"`],
["remote", "add", "origin", `https://github.com/${answers.authorGithub}/ioBroker.${answers.adapterName}`],
];
for (const args of gitCommandArgs) {
await executeCommand("git", args, { cwd: targetDir, stdout: "ignore", stderr: "ignore" });
}
}

console.log();
console.log(blueBright("All done! Have fun programming! ") + red("♥"));
}
Expand All @@ -96,6 +113,8 @@ async function setupProject_CLI(answers: Answers, files: File[]) {
buildTypeScript = answers.language === "TypeScript";
if (buildTypeScript) maxSteps++;
}
gitCommit = answers.gitCommit === "yes";
if (gitCommit) maxSteps++;

logProgress("Generating files");
const files = await createFiles(answers);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ export const questionsAndText: (Question | string)[] = [
message: "What's your email address?",
action: checkEmail,
},
{
condition: { name: "cli", value: true },
type: "select",
name: "gitCommit",
message: "Initialize the GitHub repo automatically?",
initial: "no",
choices: ["yes", "no"],
},
{
type: "select",
name: "license",
Expand Down Expand Up @@ -209,6 +217,7 @@ export interface Answers {
adminReact?: string;
indentation?: string;
quotes?: "single" | "double";
gitCommit?: "yes" | "no";
}

export function checkAnswers(answers: Partial<Answers>): void {
Expand Down

0 comments on commit 363a214

Please sign in to comment.