@@ -7,20 +7,28 @@ import { titleInputBoxCreator } from '../quickpicks/titleInputBoxCreator';
77import { visibilityQuickPickCreator } from '../quickpicks/visibilityQuickPickCreator' ;
88import { createMultiStepInput } from '../utils/createMultiStepInput' ;
99
10- const getFilenameFromPath = ( filename : string ) => {
11- const splitPath = filename . split ( '/' ) ;
12- [ filename ] = splitPath [ splitPath . length - 1 ] . split ( '.' ) ;
13-
14- return filename ;
10+ /**
11+ * パスからファイル名を取得
12+ * @param path 相対/絶対パス
13+ * @return ファイル名
14+ */
15+ const getFilenameFromPath = ( path : string ) => {
16+ const splitPath = path . split ( '/' ) ;
17+ return splitPath [ splitPath . length - 1 ] . split ( '.' ) [ 0 ] ;
1518} ;
1619
17- export function compose ( arg : object & { path : string } ) {
20+ /**
21+ * 投稿を公開するためのQuickPickとInputBoxを表示
22+ * @param arg コマンドから渡される引数
23+ */
24+ export function compose ( arg : object & { path : string } ) : void {
1825 const fileName = getFilenameFromPath ( arg . path ) ;
1926
2027 const titleInputBox = titleInputBoxCreator ( fileName ) ;
21- const tagsQuickPick = tagQuickPickCreator ( [ ] ) ;
28+ const tagsQuickPick = tagQuickPickCreator ( ) ;
2229 const visibilityQuickPick = visibilityQuickPickCreator ( ) ;
2330
31+ // Qiita.createItemのオプション
2432 const options : CreateItemOptions = {
2533 title : '' ,
2634 tags : [ ] ,
@@ -30,21 +38,25 @@ export function compose (arg: object & { path: string }) {
3038 gist : configuration . gistOnCreateItem ,
3139 } ;
3240
41+ // ドキュメントから本文を取得してbodyに代入
3342 workspace . openTextDocument ( arg . path ) . then ( ( document ) => {
3443 options . body = document . getText ( ) ;
3544 } ) ;
3645
46+ // titleInputBoxからタイトルを代入
3747 titleInputBox . onDidAccept ( ( ) => {
3848 options . title = titleInputBox . value ;
3949 } ) ;
4050
51+ // tagQuickPickからタグを代入
4152 tagsQuickPick . onDidAccept ( ( ) => {
4253 options . tags = tagsQuickPick . selectedItems . map ( ( item ) => ( {
4354 name : item . label ,
4455 versions : [ ] ,
4556 } ) ) ;
4657 } ) ;
4758
59+ // visibilityQuickPick終了時に公開状態を代入してQiita.createItemを呼び出し
4860 visibilityQuickPick . onDidAccept ( async ( ) => {
4961 options . private = visibilityQuickPick . selectedItems [ 0 ] . label === '限定公開' ;
5062 const openInBrowswer = 'ブラウザで確認' ;
@@ -62,11 +74,9 @@ export function compose (arg: object & { path: string }) {
6274 }
6375 } ) ;
6476
65- const multiStepInput = createMultiStepInput ( [
77+ createMultiStepInput ( [
6678 titleInputBox ,
6779 tagsQuickPick ,
6880 visibilityQuickPick ,
69- ] ) ;
70-
71- multiStepInput ( ) ;
81+ ] ) ( ) ;
7282}
0 commit comments