Skip to content

Commit

Permalink
refactoring: write in more TypeScript way
Browse files Browse the repository at this point in the history
bump up version to 0.3.0
  • Loading branch information
rhysd committed Jul 22, 2015
1 parent 54226a5 commit 5df4214
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 25 deletions.
8 changes: 1 addition & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ include FileUtils

BIN_DIR = './node_modules/.bin'.freeze

def cp_paths(paths, dest)
paths.each do |p|
cp_r p, dest
end
end

def cmd_exists?(cmd)
File.exists?(cmd) && File.executable?(cmd)
end
Expand Down Expand Up @@ -71,7 +65,7 @@ task :asar => %i(build) do
end

task :run => %i(dep asar) do
system "#{BIN_DIR}/electron app.asar README.md"
sh "#{BIN_DIR}/electron app.asar README.md"
end

task :clean do
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Shiba",
"version": "0.2.4",
"version": "0.3.0",
"authors": [
"rhysd <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shiba",
"productName": "Shiba",
"version": "0.2.4",
"version": "0.3.0",
"description": "Live markdown previewer with linter",
"main": "./build/src/browser/mainu.js",
"bin": {
Expand Down
14 changes: 11 additions & 3 deletions src/browser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import path = require('path');
import fs = require('fs');
import app = require('app');

export function load(): any/*TODO*/ {
export interface Config {
linter: string;
file_ext: string[];
width: number;
height: number;
shortcuts: Object;
lint_options?: any;
}

export function load(): Config {
if (this.user_config) {
return this.user_config;
}
Expand All @@ -29,13 +38,12 @@ export function load(): any/*TODO*/ {
'M': 'PageBottom',
'Home': 'PageTop',
'End': 'PageBottom',
'Shift+J': 'PageBottom',
'Control+P': 'ChangePath',
'Control+L': 'Lint'
}
};

function mergeConfig(c1, c2) {
function mergeConfig(c1: Config, c2: Config) {
for (const k in c2) {
const v2 = c2[k];

Expand Down
4 changes: 2 additions & 2 deletions src/browser/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path');

const EMOJI = new Set([
const EMOJI = new Set<string>([
'+1',
'-1',
'100',
Expand Down Expand Up @@ -887,7 +887,7 @@ const EMOJI = new Set([

const REGEX_EMOJI = /:(\w+):/g;

export function replaceAll(str) {
export function replaceAll(str: string): string {
let replacer = function(match, name) {
if (EMOJI.has(name)) {
return `<img src="../images/emoji/${name}.png" title="${match}" height="16px"></img>`;
Expand Down
4 changes: 2 additions & 2 deletions src/browser/initial_path.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs = require('fs');
import path = require('path');

export = function() {
function defaultPath() {
export = function(): string {
function defaultPath(): string {
const cwd = process.cwd();
if (process.platform === 'darwin' && cwd === '/') {
const doc_dir = path.join(process.env.HOME, 'Documents');
Expand Down
6 changes: 3 additions & 3 deletions src/browser/keyshortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class KeyShortCuts {
this.shortcuts = {};

// Note: Generating below function in 'for' loop make jshint angry
let quit_app = function() { browser_window.close(); };
let toggle_devtools = function() { browser_window.toggleDevTools(); };
const key_receiver_for = function(s: string) {
let quit_app = () => browser_window.close();
let toggle_devtools = () => browser_window.toggleDevTools();
const key_receiver_for = function(s: string): () => void {
return function() {
sender.send('keyinput', s);
};
Expand Down
11 changes: 8 additions & 3 deletions src/browser/linter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
interface Message {
header: string;
body: string;
}

class Linter {
lint: any;
lint: (filename: string, content: string, callback: (msgs: Message[]) => void) => void;
lint_url: string;
mdl: any;
mdast: any;
Expand Down Expand Up @@ -40,7 +45,7 @@ class Linter {
const is_space = /\s+/;
const messages = result.toString()
.split("\n")
.map(function(msg){
.map(function(msg: string): Message {
const m = msg.match(is_space);
if (!m) {
return {header: '', body: msg};
Expand All @@ -64,7 +69,7 @@ class Linter {
}

callback(
file.messages.map(function(m){
file.messages.map(function(m): Message {
// Note:
// Should I include m.ruleId to check the detail of message?
// I don't include it now because message gets too long.
Expand Down
2 changes: 1 addition & 1 deletion src/browser/mainu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path = require('path');
import ipc = require('ipc');
import BrowserWindow = require('browser-window');
import menu = require('./menu');
const config = require('./config').load();
import KeyShortcuts = require('./keyshortcuts');
const config = require('./config').load();

require('crash-reporter').start();

Expand Down
2 changes: 1 addition & 1 deletion src/browser/menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Menu = require('menu');
import open = require('open');

export function build(main_window) {
export function build(main_window: GitHubElectron.BrowserWindow) {
const template = [
{
label: 'Shiba',
Expand Down
2 changes: 1 addition & 1 deletion src/browser/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ marked.setOptions({
});

class Watcher {
config: any/*TODO*/;
config: config.Config;
linter: Linter;
file_watcher: fs.FSWatcher;

Expand Down

0 comments on commit 5df4214

Please sign in to comment.