build:ts success
This commit is contained in:
parent
f19075c50a
commit
871f886702
8 changed files with 72 additions and 44 deletions
|
@ -8,12 +8,12 @@ import * as gutil from 'gulp-util';
|
|||
import * as ts from 'gulp-typescript';
|
||||
const sourcemaps = require('gulp-sourcemaps');
|
||||
import tslint from 'gulp-tslint';
|
||||
import cssnano = require('gulp-cssnano');
|
||||
const cssnano = require('gulp-cssnano');
|
||||
import * as uglifyComposer from 'gulp-uglify/composer';
|
||||
import pug = require('gulp-pug');
|
||||
import * as rimraf from 'rimraf';
|
||||
import chalk from 'chalk';
|
||||
import imagemin = require('gulp-imagemin');
|
||||
const imagemin = require('gulp-imagemin');
|
||||
import * as rename from 'gulp-rename';
|
||||
import * as mocha from 'gulp-mocha';
|
||||
import * as replace from 'gulp-replace';
|
||||
|
|
|
@ -5,12 +5,16 @@
|
|||
import * as fs from 'fs';
|
||||
import * as yaml from 'js-yaml';
|
||||
|
||||
const loadLang = lang => yaml.safeLoad(
|
||||
fs.readFileSync(`./locales/${lang}.yml`, 'utf-8'));
|
||||
export type LangKey = 'de' | 'en' | 'fr' | 'ja' | 'pl';
|
||||
export type LocaleObjectChildren = LocaleObject | string | undefined;
|
||||
export type LocaleObject = {[key: string]: LocaleObjectChildren };
|
||||
|
||||
const loadLang = (lang: LangKey) => yaml.safeLoad(
|
||||
fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')) as LocaleObject;
|
||||
|
||||
const native = loadLang('ja');
|
||||
|
||||
const langs = {
|
||||
const langs: {[key in LangKey]: LocaleObject} = {
|
||||
'de': loadLang('de'),
|
||||
'en': loadLang('en'),
|
||||
'fr': loadLang('fr'),
|
||||
|
@ -23,4 +27,8 @@ Object.entries(langs).map(([, locale]) => {
|
|||
locale = Object.assign({}, native, locale);
|
||||
});
|
||||
|
||||
export function isAvailableLanguage(lang: string): lang is LangKey {
|
||||
return lang in langs;
|
||||
}
|
||||
|
||||
export default langs;
|
||||
|
|
|
@ -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`);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
36
yarn.lock
36
yarn.lock
|
@ -2,21 +2,33 @@
|
|||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@fortawesome/fontawesome-free-brands@5.0.2":
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-brands/-/fontawesome-free-brands-5.0.2.tgz#a1cc602eec40a379a3dd8a44c78b31110dd3d3d3"
|
||||
"@fortawesome/fontawesome-common-types@^0.1.7":
|
||||
version "0.1.7"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.1.7.tgz#4336c4b06d0b5608ff1215464b66fcf9f4795284"
|
||||
|
||||
"@fortawesome/fontawesome-free-regular@5.0.2":
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-regular/-/fontawesome-free-regular-5.0.2.tgz#429af86bed14689f87648e6322983c65c782c017"
|
||||
"@fortawesome/fontawesome-free-brands@5.0.13":
|
||||
version "5.0.13"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-brands/-/fontawesome-free-brands-5.0.13.tgz#4d15ff4e1e862d5e4a4df3654f8e8acbd47e9c09"
|
||||
dependencies:
|
||||
"@fortawesome/fontawesome-common-types" "^0.1.7"
|
||||
|
||||
"@fortawesome/fontawesome-free-solid@5.0.2":
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-solid/-/fontawesome-free-solid-5.0.2.tgz#090ce2c59dd5ec76983f3da8a43e1ab0321b42d5"
|
||||
"@fortawesome/fontawesome-free-regular@5.0.13":
|
||||
version "5.0.13"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-regular/-/fontawesome-free-regular-5.0.13.tgz#eb78c30184e3f456a423a1dcfa0f682f7b50de4a"
|
||||
dependencies:
|
||||
"@fortawesome/fontawesome-common-types" "^0.1.7"
|
||||
|
||||
"@fortawesome/fontawesome@1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome/-/fontawesome-1.0.1.tgz#8ac60e1e7b437889baf9c9d6e3a61ef3b637170d"
|
||||
"@fortawesome/fontawesome-free-solid@5.0.13":
|
||||
version "5.0.13"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-solid/-/fontawesome-free-solid-5.0.13.tgz#24b61aaf471a9d34a5364b052d64a516285ba894"
|
||||
dependencies:
|
||||
"@fortawesome/fontawesome-common-types" "^0.1.7"
|
||||
|
||||
"@fortawesome/fontawesome@1.1.8":
|
||||
version "1.1.8"
|
||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome/-/fontawesome-1.1.8.tgz#75fe66a60f95508160bb16bd781ad7d89b280f5b"
|
||||
dependencies:
|
||||
"@fortawesome/fontawesome-common-types" "^0.1.7"
|
||||
|
||||
"@gulp-sourcemaps/identity-map@1.X":
|
||||
version "1.0.1"
|
||||
|
|
Loading…
Reference in a new issue