mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 17:35:12 +00:00
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';
|
import * as ts from 'gulp-typescript';
|
||||||
const sourcemaps = require('gulp-sourcemaps');
|
const sourcemaps = require('gulp-sourcemaps');
|
||||||
import tslint from 'gulp-tslint';
|
import tslint from 'gulp-tslint';
|
||||||
import cssnano = require('gulp-cssnano');
|
const cssnano = require('gulp-cssnano');
|
||||||
import * as uglifyComposer from 'gulp-uglify/composer';
|
import * as uglifyComposer from 'gulp-uglify/composer';
|
||||||
import pug = require('gulp-pug');
|
import pug = require('gulp-pug');
|
||||||
import * as rimraf from 'rimraf';
|
import * as rimraf from 'rimraf';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import imagemin = require('gulp-imagemin');
|
const imagemin = require('gulp-imagemin');
|
||||||
import * as rename from 'gulp-rename';
|
import * as rename from 'gulp-rename';
|
||||||
import * as mocha from 'gulp-mocha';
|
import * as mocha from 'gulp-mocha';
|
||||||
import * as replace from 'gulp-replace';
|
import * as replace from 'gulp-replace';
|
||||||
|
|
|
@ -5,12 +5,16 @@
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as yaml from 'js-yaml';
|
import * as yaml from 'js-yaml';
|
||||||
|
|
||||||
const loadLang = lang => yaml.safeLoad(
|
export type LangKey = 'de' | 'en' | 'fr' | 'ja' | 'pl';
|
||||||
fs.readFileSync(`./locales/${lang}.yml`, 'utf-8'));
|
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 native = loadLang('ja');
|
||||||
|
|
||||||
const langs = {
|
const langs: {[key in LangKey]: LocaleObject} = {
|
||||||
'de': loadLang('de'),
|
'de': loadLang('de'),
|
||||||
'en': loadLang('en'),
|
'en': loadLang('en'),
|
||||||
'fr': loadLang('fr'),
|
'fr': loadLang('fr'),
|
||||||
|
@ -23,4 +27,8 @@ Object.entries(langs).map(([, locale]) => {
|
||||||
locale = Object.assign({}, native, locale);
|
locale = Object.assign({}, native, locale);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function isAvailableLanguage(lang: string): lang is LangKey {
|
||||||
|
return lang in langs;
|
||||||
|
}
|
||||||
|
|
||||||
export default langs;
|
export default langs;
|
||||||
|
|
|
@ -3,18 +3,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fontawesome from '@fortawesome/fontawesome';
|
import * as fontawesome from '@fortawesome/fontawesome';
|
||||||
import * as regular from '@fortawesome/fontawesome-free-regular';
|
import regular from '@fortawesome/fontawesome-free-regular';
|
||||||
import * as solid from '@fortawesome/fontawesome-free-solid';
|
import solid from '@fortawesome/fontawesome-free-solid';
|
||||||
import * as brands from '@fortawesome/fontawesome-free-brands';
|
import brands from '@fortawesome/fontawesome-free-brands';
|
||||||
|
|
||||||
fontawesome.library.add(regular, solid, brands);
|
fontawesome.library.add(regular, solid, brands);
|
||||||
|
|
||||||
export const pattern = /%fa:(.+?)%/g;
|
export const pattern = /%fa:(.+?)%/g;
|
||||||
|
|
||||||
export const replacement = (match, key) => {
|
export const replacement = (match: string, key: string) => {
|
||||||
const args = key.split(' ');
|
const args = key.split(' ');
|
||||||
let prefix = 'fas';
|
let prefix = 'fas';
|
||||||
const classes = [];
|
const classes: string[] = [];
|
||||||
let transform = '';
|
let transform = '';
|
||||||
let name;
|
let name;
|
||||||
|
|
||||||
|
@ -34,12 +34,12 @@ export const replacement = (match, key) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const icon = fontawesome.icon({ prefix, iconName: name }, {
|
const icon = fontawesome.icon({ prefix, iconName: name } as fontawesome.IconLookup, {
|
||||||
classes: classes
|
classes: classes,
|
||||||
|
transform: fontawesome.parse.transform(transform)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (icon) {
|
if (icon) {
|
||||||
icon.transform = fontawesome.parse.transform(transform);
|
|
||||||
return `<i data-fa class="${name}">${icon.html[0]}</i>`;
|
return `<i data-fa class="${name}">${icon.html[0]}</i>`;
|
||||||
} else {
|
} else {
|
||||||
console.warn(`'${name}' not found in fa`);
|
console.warn(`'${name}' not found in fa`);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Replace i18n texts
|
* Replace i18n texts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import locale from '../../locales';
|
import locale, { isAvailableLanguage, LocaleObject, LocaleObjectChildren } from '../../locales';
|
||||||
|
|
||||||
export default class Replacer {
|
export default class Replacer {
|
||||||
private lang: string;
|
private lang: string;
|
||||||
|
@ -16,19 +16,19 @@ export default class Replacer {
|
||||||
this.replacement = this.replacement.bind(this);
|
this.replacement = this.replacement.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private get(path: string, key: string) {
|
private get(path: string, key: string): string {
|
||||||
const texts = locale[this.lang];
|
if (!isAvailableLanguage(this.lang)) {
|
||||||
|
|
||||||
if (texts == null) {
|
|
||||||
console.warn(`lang '${this.lang}' is not supported`);
|
console.warn(`lang '${this.lang}' is not supported`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = texts;
|
const texts = locale[this.lang];
|
||||||
|
|
||||||
|
let text: LocaleObjectChildren = texts;
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
if (text.hasOwnProperty(path)) {
|
if (text.hasOwnProperty(path)) {
|
||||||
text = text[path];
|
text = text[path] as LocaleObject;
|
||||||
} else {
|
} else {
|
||||||
console.warn(`path '${path}' not found in '${this.lang}'`);
|
console.warn(`path '${path}' not found in '${this.lang}'`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
|
@ -38,7 +38,7 @@ export default class Replacer {
|
||||||
// Check the key existance
|
// Check the key existance
|
||||||
const error = key.split('.').some(k => {
|
const error = key.split('.').some(k => {
|
||||||
if (text.hasOwnProperty(k)) {
|
if (text.hasOwnProperty(k)) {
|
||||||
text = text[k];
|
text = (text as LocaleObject)[k];
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -48,12 +48,15 @@ export default class Replacer {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`);
|
console.warn(`key '${key}' not found in '${path}' of '${this.lang}'`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
|
} else if (typeof text !== "string") {
|
||||||
|
console.warn(`key '${key}' is not string in '${path}' of '${this.lang}'`);
|
||||||
|
return key; // Fallback
|
||||||
} else {
|
} else {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public replacement(match, key) {
|
public replacement(match: string, key: string) {
|
||||||
let path = null;
|
let path = null;
|
||||||
|
|
||||||
if (key.indexOf('|') != -1) {
|
if (key.indexOf('|') != -1) {
|
||||||
|
|
|
@ -19,9 +19,10 @@ import generateVars from '../vars';
|
||||||
|
|
||||||
const langs = Object.keys(locales);
|
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 id = param.type.match(/^id\((.+?)\)|^id/);
|
||||||
const entity = param.type.match(/^entity\((.+?)\)/);
|
const entity = param.type.match(/^entity\((.+?)\)/);
|
||||||
const isObject = /^object/.test(param.type);
|
const isObject = /^object/.test(param.type);
|
||||||
|
@ -57,7 +58,7 @@ const parseParam = param => {
|
||||||
return param;
|
return param;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortParams = params => {
|
const sortParams = (params: Array<{name: string}>) => {
|
||||||
params.sort((a, b) => {
|
params.sort((a, b) => {
|
||||||
if (a.name < b.name)
|
if (a.name < b.name)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -68,14 +69,15 @@ const sortParams = params => {
|
||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractDefs = params => {
|
// WIP type
|
||||||
let defs = [];
|
const extractDefs = (params: any[]) => {
|
||||||
|
let defs: any[] = [];
|
||||||
|
|
||||||
params.forEach(param => {
|
params.forEach(param => {
|
||||||
if (param.def) {
|
if (param.def) {
|
||||||
defs.push({
|
defs.push({
|
||||||
name: param.defName,
|
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);
|
const childDefs = extractDefs(param.def);
|
||||||
|
@ -109,8 +111,10 @@ gulp.task('doc:api:endpoints', async () => {
|
||||||
path: ep.endpoint
|
path: ep.endpoint
|
||||||
},
|
},
|
||||||
desc: ep.desc,
|
desc: ep.desc,
|
||||||
|
// @ts-ignore
|
||||||
params: sortParams(ep.params.map(p => parseParam(p))),
|
params: sortParams(ep.params.map(p => parseParam(p))),
|
||||||
paramDefs: extractDefs(ep.params),
|
paramDefs: extractDefs(ep.params),
|
||||||
|
// @ts-ignore
|
||||||
res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null,
|
res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null,
|
||||||
resDefs: ep.res ? extractDefs(ep.res) : null,
|
resDefs: ep.res ? extractDefs(ep.res) : null,
|
||||||
};
|
};
|
||||||
|
@ -155,7 +159,8 @@ gulp.task('doc:api:entities', async () => {
|
||||||
const vars = {
|
const vars = {
|
||||||
name: entity.name,
|
name: entity.name,
|
||||||
desc: entity.desc,
|
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),
|
propDefs: extractDefs(entity.props),
|
||||||
};
|
};
|
||||||
langs.forEach(lang => {
|
langs.forEach(lang => {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import * as glob from 'glob';
|
||||||
import * as gulp from 'gulp';
|
import * as gulp from 'gulp';
|
||||||
import * as pug from 'pug';
|
import * as pug from 'pug';
|
||||||
import * as mkdirp from 'mkdirp';
|
import * as mkdirp from 'mkdirp';
|
||||||
import stylus = require('gulp-stylus');
|
const stylus = require('gulp-stylus');
|
||||||
import cssnano = require('gulp-cssnano');
|
const cssnano = require('gulp-cssnano');
|
||||||
|
|
||||||
import I18nReplacer from '../../build/i18n';
|
import I18nReplacer from '../../build/i18n';
|
||||||
import fa from '../../build/fa';
|
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['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;
|
vars['config'] = config;
|
||||||
|
|
||||||
|
|
36
yarn.lock
36
yarn.lock
|
@ -2,21 +2,33 @@
|
||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
"@fortawesome/fontawesome-free-brands@5.0.2":
|
"@fortawesome/fontawesome-common-types@^0.1.7":
|
||||||
version "5.0.2"
|
version "0.1.7"
|
||||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-brands/-/fontawesome-free-brands-5.0.2.tgz#a1cc602eec40a379a3dd8a44c78b31110dd3d3d3"
|
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.1.7.tgz#4336c4b06d0b5608ff1215464b66fcf9f4795284"
|
||||||
|
|
||||||
"@fortawesome/fontawesome-free-regular@5.0.2":
|
"@fortawesome/fontawesome-free-brands@5.0.13":
|
||||||
version "5.0.2"
|
version "5.0.13"
|
||||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-regular/-/fontawesome-free-regular-5.0.2.tgz#429af86bed14689f87648e6322983c65c782c017"
|
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":
|
"@fortawesome/fontawesome-free-regular@5.0.13":
|
||||||
version "5.0.2"
|
version "5.0.13"
|
||||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free-solid/-/fontawesome-free-solid-5.0.2.tgz#090ce2c59dd5ec76983f3da8a43e1ab0321b42d5"
|
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":
|
"@fortawesome/fontawesome-free-solid@5.0.13":
|
||||||
version "1.0.1"
|
version "5.0.13"
|
||||||
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome/-/fontawesome-1.0.1.tgz#8ac60e1e7b437889baf9c9d6e3a61ef3b637170d"
|
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":
|
"@gulp-sourcemaps/identity-map@1.X":
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
|
|
Loading…
Reference in a new issue