build:ts success

This commit is contained in:
rinsuki
2018-06-17 19:09:24 +09:00
parent f19075c50a
commit 871f886702
8 changed files with 72 additions and 44 deletions

View File

@ -3,18 +3,18 @@
*/
import * as fontawesome from '@fortawesome/fontawesome';
import * as regular from '@fortawesome/fontawesome-free-regular';
import * as solid from '@fortawesome/fontawesome-free-solid';
import * as brands from '@fortawesome/fontawesome-free-brands';
import regular from '@fortawesome/fontawesome-free-regular';
import solid from '@fortawesome/fontawesome-free-solid';
import brands from '@fortawesome/fontawesome-free-brands';
fontawesome.library.add(regular, solid, brands);
export const pattern = /%fa:(.+?)%/g;
export const replacement = (match, key) => {
export const replacement = (match: string, key: string) => {
const args = key.split(' ');
let prefix = 'fas';
const classes = [];
const classes: string[] = [];
let transform = '';
let name;
@ -34,12 +34,12 @@ export const replacement = (match, key) => {
}
});
const icon = fontawesome.icon({ prefix, iconName: name }, {
classes: classes
const icon = fontawesome.icon({ prefix, iconName: name } as fontawesome.IconLookup, {
classes: classes,
transform: fontawesome.parse.transform(transform)
});
if (icon) {
icon.transform = fontawesome.parse.transform(transform);
return `<i data-fa class="${name}">${icon.html[0]}</i>`;
} else {
console.warn(`'${name}' not found in fa`);

View File

@ -2,7 +2,7 @@
* Replace i18n texts
*/
import locale from '../../locales';
import locale, { isAvailableLanguage, LocaleObject, LocaleObjectChildren } from '../../locales';
export default class Replacer {
private lang: string;
@ -16,19 +16,19 @@ export default class Replacer {
this.replacement = this.replacement.bind(this);
}
private get(path: string, key: string) {
const texts = locale[this.lang];
if (texts == null) {
private get(path: string, key: string): string {
if (!isAvailableLanguage(this.lang)) {
console.warn(`lang '${this.lang}' is not supported`);
return key; // Fallback
}
let text = texts;
const texts = locale[this.lang];
let text: LocaleObjectChildren = texts;
if (path) {
if (text.hasOwnProperty(path)) {
text = text[path];
text = text[path] as LocaleObject;
} else {
console.warn(`path '${path}' not found in '${this.lang}'`);
return key; // Fallback
@ -38,7 +38,7 @@ export default class Replacer {
// Check the key existance
const error = key.split('.').some(k => {
if (text.hasOwnProperty(k)) {
text = text[k];
text = (text as LocaleObject)[k];
return false;
} else {
return true;
@ -48,12 +48,15 @@ export default class Replacer {
if (error) {
console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`);
return key; // Fallback
} else if (typeof text !== "string") {
console.warn(`key '${key}' is not string in '${path}' of '${this.lang}'`);
return key; // Fallback
} else {
return text;
}
}
public replacement(match, key) {
public replacement(match: string, key: string) {
let path = null;
if (key.indexOf('|') != -1) {

View File

@ -19,9 +19,10 @@ import generateVars from '../vars';
const langs = Object.keys(locales);
const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
const kebab = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
const parseParam = param => {
// WIP type
const parseParam = (param: any) => {
const id = param.type.match(/^id\((.+?)\)|^id/);
const entity = param.type.match(/^entity\((.+?)\)/);
const isObject = /^object/.test(param.type);
@ -57,7 +58,7 @@ const parseParam = param => {
return param;
};
const sortParams = params => {
const sortParams = (params: Array<{name: string}>) => {
params.sort((a, b) => {
if (a.name < b.name)
return -1;
@ -68,14 +69,15 @@ const sortParams = params => {
return params;
};
const extractDefs = params => {
let defs = [];
// WIP type
const extractDefs = (params: any[]) => {
let defs: any[] = [];
params.forEach(param => {
if (param.def) {
defs.push({
name: param.defName,
params: sortParams(param.def.map(p => parseParam(p)))
params: sortParams(param.def.map((p: any) => parseParam(p)))
});
const childDefs = extractDefs(param.def);
@ -109,8 +111,10 @@ gulp.task('doc:api:endpoints', async () => {
path: ep.endpoint
},
desc: ep.desc,
// @ts-ignore
params: sortParams(ep.params.map(p => parseParam(p))),
paramDefs: extractDefs(ep.params),
// @ts-ignore
res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null,
resDefs: ep.res ? extractDefs(ep.res) : null,
};
@ -155,7 +159,8 @@ gulp.task('doc:api:entities', async () => {
const vars = {
name: entity.name,
desc: entity.desc,
props: sortParams(entity.props.map(p => parseParam(p))),
// WIP type
props: sortParams(entity.props.map((p: any) => parseParam(p))),
propDefs: extractDefs(entity.props),
};
langs.forEach(lang => {

View File

@ -8,8 +8,8 @@ import * as glob from 'glob';
import * as gulp from 'gulp';
import * as pug from 'pug';
import * as mkdirp from 'mkdirp';
import stylus = require('gulp-stylus');
import cssnano = require('gulp-cssnano');
const stylus = require('gulp-stylus');
const cssnano = require('gulp-cssnano');
import I18nReplacer from '../../build/i18n';
import fa from '../../build/fa';

View File

@ -38,7 +38,7 @@ export default async function(): Promise<{ [key: string]: any }> {
vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1];
});
vars['kebab'] = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
vars['kebab'] = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
vars['config'] = config;