Skip to content

Commit c51e27c

Browse files
author
Kaneko Yuto
committed
Changed command explanations carefully
1 parent 2d6e4ab commit c51e27c

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ npx qiita init
6969

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

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

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

8685
```console
87-
Enter your token: トークンを入力しEnterキーを押す
86+
発行したトークンを入力: トークンを入力しEnterキーを押す
8887
Hi ユーザー名!
8988
```
9089

src/commands/init.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import fs from "node:fs";
22
import path from "node:path";
33
import { config } from "../lib/config";
44

5-
export const init = async () => {
6-
const rootDir = process.cwd();
7-
const workflowsDirectoryPath = path.join(rootDir, ".github/workflows");
8-
const publishWorkflowFilePath = path.join(
9-
workflowsDirectoryPath,
10-
"publish.yml"
11-
);
12-
const publishWorkflowFileContent = `# Please set 'QIITA_TOKEN' secret to your repository
5+
const publishWorkflowFileContent = `# Please set 'QIITA_TOKEN' secret to your repository
136
name: Publish articles
147
158
on:
@@ -39,15 +32,25 @@ jobs:
3932
qiita-token: \${{ secrets.QIITA_TOKEN }}
4033
`;
4134

35+
const rootDir = process.cwd();
36+
const workflowsDirectoryPath = path.join(rootDir, ".github/workflows");
37+
const publishWorkflowFilePath = path.join(
38+
workflowsDirectoryPath,
39+
"publish.yml"
40+
);
41+
42+
const gitignoreFilePath = path.join(rootDir, ".gitignore");
43+
const gitignoreFileContent = `.remote
44+
node_modules
45+
`;
46+
47+
export const init = async () => {
48+
console.log("設定ファイルを生成します。\n");
49+
4250
if (!fs.existsSync(workflowsDirectoryPath)) {
4351
fs.mkdirSync(workflowsDirectoryPath, { recursive: true });
4452
}
4553
writeFile(publishWorkflowFilePath, publishWorkflowFileContent);
46-
47-
const gitignoreFilePath = path.join(rootDir, ".gitignore");
48-
const gitignoreFileContent = `.remote
49-
node_modules
50-
`;
5154
writeFile(gitignoreFilePath, gitignoreFileContent);
5255

5356
const userConfigFilePath = config.getUserConfigFilePath();
@@ -61,15 +64,32 @@ node_modules
6164
2
6265
);
6366
writeFile(userConfigFilePath, userConfigFileContent);
67+
68+
await printNextSteps();
6469
};
6570

6671
const writeFile = (path: string, content: string) => {
72+
console.log(` Creating ${path}`);
6773
if (!fs.existsSync(path)) {
6874
fs.writeFile(path, content, { encoding: "utf8" }, (err) => {
6975
if (err) throw err;
70-
console.log(`Create ${path}`);
7176
});
77+
console.log(` Created!\n`);
7278
} else {
73-
console.log(`${path} is already exist`);
79+
console.log(` Already exists.\n`);
7480
}
7581
};
82+
83+
const printNextSteps = async () => {
84+
const chalk = (await import("chalk")).default;
85+
console.log(`Success! ✨
86+
87+
次のステップ:
88+
89+
1. トークンを作成してログインをしてください。
90+
${chalk.bold("npx qiita login")}
91+
92+
2. 記事のプレビューができるようになります。
93+
${chalk.bold("npx qiita preview")}
94+
`);
95+
};

src/commands/login.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ export const login = async (argv: string[]) => {
1313
output: process.stdout,
1414
});
1515

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

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

27-
console.log(`Hi ${currentUser.id}!`);
34+
console.log(`Hi ${currentUser.id}!\n`);
35+
36+
await printAvailableCommands();
37+
};
38+
39+
const printAvailableCommands = async () => {
40+
const chalk = (await import("chalk")).default;
41+
console.log(`ログインが完了しました 🎉
42+
以下のコマンドを使って執筆を始めましょう!
43+
44+
🚀 コンテンツをブラウザでプレビューする
45+
${chalk.bold("npx qiita preview")}
46+
47+
🚀 新しい記事を追加する
48+
${chalk.bold("npx qiita new (記事のファイルのベース名)")}
49+
50+
🚀 記事を投稿、更新する
51+
${chalk.bold("npx qiita publish (記事のファイルのベース名)")}
52+
53+
💁 コマンドのヘルプを確認する
54+
${chalk.bold("npx qiita help")}
55+
`);
2856
};

0 commit comments

Comments
 (0)