Skip to content

Changed command explanations carefully #35

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
Jul 20, 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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ npx qiita init

以下の流れでトークンを発行してください。

- https://qiita.com/settings/applications へログインした状態でアクセスします。
- `設定 > アプリーケーション > 個人用アクセストークン` からトークンを発行します。
- [https://qiita.com/settings/tokens/new](https://qiita.com/settings/tokens/new?read_qiita=1&write_qiita=1&description=qiita-cli) へログインした状態でアクセスします。
- トークンの権限には「read_qiita」と「write_qiita」を設定します。

発行したトークンは`Qiita CLIのログイン`、`GitHubで記事を管理する`で利用します。
Expand All @@ -84,7 +83,7 @@ npx qiita login
```

```console
Enter your token: トークンを入力しEnterキーを押す
発行したトークンを入力: トークンを入力しEnterキーを押す
Hi ユーザー名!
```

Expand Down
50 changes: 35 additions & 15 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import fs from "node:fs";
import path from "node:path";
import { config } from "../lib/config";

export const init = async () => {
const rootDir = process.cwd();
const workflowsDirectoryPath = path.join(rootDir, ".github/workflows");
const publishWorkflowFilePath = path.join(
workflowsDirectoryPath,
"publish.yml"
);
const publishWorkflowFileContent = `# Please set 'QIITA_TOKEN' secret to your repository
const publishWorkflowFileContent = `# Please set 'QIITA_TOKEN' secret to your repository
name: Publish articles

on:
Expand Down Expand Up @@ -39,15 +32,25 @@ jobs:
qiita-token: \${{ secrets.QIITA_TOKEN }}
`;

const rootDir = process.cwd();
const workflowsDirectoryPath = path.join(rootDir, ".github/workflows");
const publishWorkflowFilePath = path.join(
workflowsDirectoryPath,
"publish.yml"
);

const gitignoreFilePath = path.join(rootDir, ".gitignore");
const gitignoreFileContent = `.remote
node_modules
`;

export const init = async () => {
console.log("設定ファイルを生成します。\n");

if (!fs.existsSync(workflowsDirectoryPath)) {
fs.mkdirSync(workflowsDirectoryPath, { recursive: true });
}
writeFile(publishWorkflowFilePath, publishWorkflowFileContent);

const gitignoreFilePath = path.join(rootDir, ".gitignore");
const gitignoreFileContent = `.remote
node_modules
`;
writeFile(gitignoreFilePath, gitignoreFileContent);

const userConfigFilePath = config.getUserConfigFilePath();
Expand All @@ -61,15 +64,32 @@ node_modules
2
);
writeFile(userConfigFilePath, userConfigFileContent);

await printNextSteps();
};

const writeFile = (path: string, content: string) => {
console.log(` Creating ${path}`);
if (!fs.existsSync(path)) {
fs.writeFile(path, content, { encoding: "utf8" }, (err) => {
if (err) throw err;
console.log(`Create ${path}`);
});
console.log(` Created!\n`);
} else {
console.log(`${path} is already exist`);
console.log(` Already exists.\n`);
}
};

const printNextSteps = async () => {
const chalk = (await import("chalk")).default;
console.log(`Success! ✨

次のステップ:

1. トークンを作成してログインをしてください。
${chalk.bold("npx qiita login")}

2. 記事のプレビューができるようになります。
${chalk.bold("npx qiita preview")}
`);
};
32 changes: 30 additions & 2 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ export const login = async (argv: string[]) => {
output: process.stdout,
});

const token = await rl.question("Enter your token: ");
const chalk = (await import("chalk")).default;
console.log(`
以下のURLにアクセスしてトークンを発行してください。(「read_qiita」と「write_qiita」にチェックを入れてください)
${chalk.bold(
"https://qiita.com/settings/tokens/new?read_qiita=1&write_qiita=1&description=qiita-cli"
)}
`);
const token = await rl.question("発行したトークンを入力: ");
rl.close();

const qiitaApi = await getQiitaApiInstance({ token });
Expand All @@ -24,5 +31,26 @@ export const login = async (argv: string[]) => {
accessToken: token,
});

console.log(`Hi ${currentUser.id}!`);
console.log(`Hi ${currentUser.id}!\n`);

await printAvailableCommands();
};

const printAvailableCommands = async () => {
const chalk = (await import("chalk")).default;
console.log(`ログインが完了しました 🎉
以下のコマンドを使って執筆を始めましょう!

🚀 コンテンツをブラウザでプレビューする
${chalk.bold("npx qiita preview")}

🚀 新しい記事を追加する
${chalk.bold("npx qiita new (記事のファイルのベース名)")}

🚀 記事を投稿、更新する
${chalk.bold("npx qiita publish (記事のファイルのベース名)")}

💁 コマンドのヘルプを確認する
${chalk.bold("npx qiita help")}
`);
};