Skip to content

Commit a076fec

Browse files
committed
1.0.1
1 parent 3631de4 commit a076fec

17 files changed

Lines changed: 304 additions & 24 deletions

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
55
Provides [Hexo] `init`, `new`, `generate`, `server`, `deploy`, `publish`, `clean` commands in the VSCode Editor.
66

7-
**Warning** : This version is a work in progress and things might still change a bit.
8-
97
## Install
108

11-
to do ...
9+
1. Within Visual Studio Code, open the command palette (Ctrl-Shift-P / Cmd-Shift-P)
10+
2. Select *Extensions:Install Extensions* or run *ext install* and search for 'hexo'
1211

1312
## Usage
1413

@@ -18,11 +17,17 @@ to do ...
1817

1918
## Commands
2019

21-
Press `cmd-shift-P` to bring up the list of commands, and type:
20+
Press `Ctrl-Shift-P` / `Cmd-Shift-P` to bring up the list of commands, and type:
2221

2322
```bash
24-
- hexo init # Init a new blog
25-
- hexo new # Create a new post
23+
- hexo init # Initializes a website
24+
- hexo new # Creates a new article
25+
- hexo generate # Generates static files
26+
- hexo publish # Publishes a draft
27+
- hexo server # Starts a local server
28+
- hexo stop # stop a local server(Ctrl-C)
29+
- hexo deploy # Deploys your website
30+
- hexo clean # Cleans the cache file (db.json) and generated files (public)
2631
```
2732

2833
[Hexo]: http://hexo.io/

hexo-logo.png

6.72 KB
Loading

package.json

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "vscode-hexo",
33
"displayName": "vscode-hexo",
44
"description": "VSCode extension to manage hexo commands",
5-
"version": "0.0.1",
5+
"version": "1.0.1",
66
"publisher": "codeyu",
7+
"icon": "hexo-logo.png",
78
"engines": {
89
"vscode": "^1.0.0"
910
},
@@ -12,7 +13,13 @@
1213
],
1314
"activationEvents": [
1415
"onCommand:hexo-script.init",
15-
"onCommand:hexo-script.new"
16+
"onCommand:hexo-script.new",
17+
"onCommand:hexo-script.generate",
18+
"onCommand:hexo-script.server",
19+
"onCommand:hexo-script.stop",
20+
"onCommand:hexo-script.deploy",
21+
"onCommand:hexo-script.publish",
22+
"onCommand:hexo-script.clean"
1623
],
1724
"main": "./out/src/extension",
1825
"contributes": {
@@ -26,6 +33,36 @@
2633
"command": "hexo-script.new",
2734
"title": "hexo new",
2835
"category": "hexo"
36+
},
37+
{
38+
"command": "hexo-script.generate",
39+
"title": "hexo generate",
40+
"category": "hexo"
41+
},
42+
{
43+
"command": "hexo-script.server",
44+
"title": "hexo server",
45+
"category": "hexo"
46+
},
47+
{
48+
"command": "hexo-script.stop",
49+
"title": "stop hexo server",
50+
"category": "hexo"
51+
},
52+
{
53+
"command": "hexo-script.deploy",
54+
"title": "hexo deploy",
55+
"category": "hexo"
56+
},
57+
{
58+
"command": "hexo-script.publish",
59+
"title": "hexo publish",
60+
"category": "hexo"
61+
},
62+
{
63+
"command": "hexo-script.clean",
64+
"title": "hexo clean",
65+
"category": "hexo"
2966
}
3067
]
3168
},

src/clean.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { workspace as Workspace, window as Window } from 'vscode';
2+
3+
import { packageExists } from './utils';
4+
import * as Messages from './messages';
5+
import { runCommand } from './run-command';
6+
7+
8+
export default function () {
9+
if (!Workspace.rootPath) {
10+
Messages.noDirectoryOpenError();
11+
return;
12+
}
13+
runCommand(['clean']);
14+
};

src/deploy.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as Fs from 'fs';
2+
import * as Path from 'path';
3+
import { workspace as Workspace, window as Window } from 'vscode';
4+
5+
import * as Messages from './messages';
6+
import { packageExists } from './utils';
7+
import { runCommand } from './run-command';
8+
export default function () {
9+
10+
if (!Workspace.rootPath) {
11+
Messages.noProjectOpenError();
12+
return;
13+
}
14+
15+
Window.showInputBox({
16+
prompt: 'Input Option',
17+
placeHolder: '-g'
18+
})
19+
.then((value) => {
20+
if (!value) {
21+
runCommand(['deploy'])
22+
}
23+
else{
24+
const options = value.split(' ');
25+
26+
const hasDeployOption = options.find((value) => {
27+
28+
return value === '-g' ||
29+
value === '--generate'
30+
});
31+
32+
const args = ['deploy', ...options];
33+
if (hasDeployOption) {
34+
runCommand(args);
35+
}
36+
else{
37+
Messages.invalidOptionError();
38+
return;
39+
}
40+
}
41+
42+
});
43+
};

src/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { runCommand } from './run-command';
88

99
import hexoInit from './init';
1010
import hexoNew from './new';
11+
import hexoGenerate from './generate';
12+
import {hexoServer,hexoStopServer} from './server';
13+
import hexoDeploy from './deploy';
14+
import hexoPublish from './publish';
15+
import hexoClean from './clean';
1116
// this method is called when your extension is activated
1217
// your extension is activated the very first time the command is executed
1318
export const activate = function (context: ExtensionContext) {
@@ -21,7 +26,13 @@ export const activate = function (context: ExtensionContext) {
2126
// The commandId parameter must match the command field in package.json
2227
const disposables = [
2328
Commands.registerCommand('hexo-script.init', hexoInit),
24-
Commands.registerCommand('hexo-script.new', hexoNew),
29+
Commands.registerCommand('hexo-script.new', hexoNew),
30+
Commands.registerCommand('hexo-script.generate', hexoGenerate),
31+
Commands.registerCommand('hexo-script.server', hexoServer),
32+
Commands.registerCommand('hexo-script.stop', hexoStopServer),
33+
Commands.registerCommand('hexo-script.deploy', hexoDeploy),
34+
Commands.registerCommand('hexo-script.publish', hexoPublish),
35+
Commands.registerCommand('hexo-script.clean', hexoClean)
2536
];
2637

2738
context.subscriptions.push(...disposables, outputChannel);

src/generate.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as Fs from 'fs';
2+
import * as Path from 'path';
3+
import { workspace as Workspace, window as Window } from 'vscode';
4+
5+
import * as Messages from './messages';
6+
import { packageExists } from './utils';
7+
import { runCommand } from './run-command';
8+
export default function () {
9+
10+
if (!Workspace.rootPath) {
11+
Messages.noProjectOpenError();
12+
return;
13+
}
14+
15+
Window.showInputBox({
16+
prompt: 'Input Option',
17+
placeHolder: '-d, -w,'
18+
})
19+
.then((value) => {
20+
if (!value) {
21+
runCommand(['generate'])
22+
}
23+
else{
24+
const options = value.split(' ');
25+
26+
const hasGenerateOption = options.find((value) => {
27+
28+
return value === '-d' ||
29+
value === '-w' ||
30+
value === '--deploy' ||
31+
value === '--watch'
32+
});
33+
34+
const args = ['generate', ...options];
35+
if (hasGenerateOption) {
36+
runCommand(args);
37+
}
38+
else{
39+
Messages.invalidOptionError();
40+
return;
41+
}
42+
}
43+
44+
});
45+
};

src/init.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import { workspace as Workspace, window as Window } from 'vscode';
33
import { packageExists } from './utils';
44
import * as Messages from './messages';
55
import { runCommand } from './run-command';
6-
6+
import { outputChannel } from './output';
77

88
export default function () {
99
if (!Workspace.rootPath) {
1010
Messages.noDirectoryOpenError();
1111
return;
1212
}
13+
if (packageExists()) {
14+
Messages.alreadyExistsError();
15+
return;
16+
}
1317
Window.showInputBox({
1418
prompt: 'Initializes a website',
15-
placeHolder: 'If no folder is provided, Hexo will set up the website in the current directory'
19+
placeHolder: '[folder]'
1620
})
1721
.then((value) => {
1822

src/messages.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function noPackageError () {
99

1010
export function alreadyExistsError () {
1111

12-
Window.showErrorMessage('\'package.json\' already exists');
12+
Window.showErrorMessage('\'hexo site\' already exists');
1313
};
1414

1515

@@ -50,7 +50,7 @@ export function cannotWriteError () {
5050

5151
export function createdInfo () {
5252

53-
Window.showInformationMessage('\'package.json\' created successfuly');
53+
Window.showInformationMessage('\'hexo site\' created successfuly');
5454
};
5555

5656

@@ -63,4 +63,9 @@ export function noValueError () {
6363
export function invalidTagError () {
6464

6565
Window.showErrorMessage('Tag is invalid');
66+
};
67+
68+
export function invalidOptionError () {
69+
70+
Window.showErrorMessage('Option is invalid');
6671
};

src/new.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function () {
1818

1919
Window.showInputBox({
2020
prompt: 'Input Layout',
21-
placeHolder: 'post is the default layout'
21+
placeHolder: 'post, page, draft'
2222
})
2323
.then((value) => {
2424

@@ -28,14 +28,15 @@ export default function () {
2828

2929
return Window.showInputBox({
3030
prompt: 'Input title',
31-
placeHolder: '',
32-
value: 'Hello World'
31+
placeHolder: ''
3332
});
3433
})
3534
.then((value) => {
36-
if (value) {
37-
options.Title = value;
35+
if (!value) {
36+
Messages.noValueError();
37+
return;
3838
}
39-
runCommand(['new', options.Layout,options.Title])
39+
options.Title = value;
40+
runCommand(['new', options.Layout, options.Title])
4041
});
4142
};

0 commit comments

Comments
 (0)