Commit 97176ee0 authored by Ludan Stoecklé's avatar Ludan Stoecklé

browser comp was broken + lint

parent ce11f931
......@@ -17,5 +17,5 @@ module.exports = {
"@typescript-eslint/no-var-requires": "off"
}
}
]
],
};
.DS_Store
.idea
.vscode
testing
node_modules
lib-cov
......
......@@ -35,5 +35,5 @@ publish_npm:
- npm whoami
- lerna publish from-package --yes
only:
- master
- /^v[0-9]+\.[0-9]+\.[0-9]+$/
when: manual
{
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{"language": "typescript", "autoFix": true },
{"language": "typescriptreact", "autoFix": true }
],
}
\ No newline at end of file
......@@ -12,8 +12,7 @@
"jstransformer": "1.0.0",
"pug-error": "^1.3.2",
"resolve": "^1.1.6",
"rosaenlg-pug-walk": "2.0.0",
"uglify-js": "^3.6.0"
"rosaenlg-pug-walk": "2.0.0"
},
"devDependencies": {
"get-repo": "^1.0.0",
......@@ -22,7 +21,6 @@
"jstransformer-less": "^2.1.0",
"jstransformer-markdown-it": "^2.1.0",
"jstransformer-stylus": "^1.0.0",
"jstransformer-uglify-js": "^1.1.1",
"rosaenlg-pug-lexer": "5.0.0",
"rosaenlg-pug-load": "3.0.0",
"rosaenlg-pug-parser": "6.0.0"
......
name: rosaenlg
version: '1.0.0'
version: '1.0.1'
title: RosaeNLG
nav:
- modules/ROOT/nav.adoc
......
......@@ -8,6 +8,12 @@ https://keepachangelog.com/en/0.3.0/
=== Changed
////
== [1.0.1] - 2019-09-12
=== Fixed
* Browser compilation was broken. Fix + added automated tests.
== [1.0.0] - 2019-09-10
=== Added
......
......@@ -47,24 +47,21 @@ In your project: *do not* run `npm install` as it will download each RosaeNLG pa
_this doc is just for me_
* check non regression on another project
* check `changelog.adoc`
* update target version in `antora.yml`
* merge with master
* local environment: `lerna version --no-push --exact patch` (or `minor` etc. instead of patch)
* make a `vXX.XX.XX` branch (to be seen by the doc project)
* push with tags: `git push --follow-tags`
* also push branch: `git push origin vXX.XX.XX`
* Gitlab CI should build
* npm publish: trigger manually on gitlab once build & tests are ok
* doc publication process (which could obviously be improved):
** in the `antora-ui` project:
*** lookup for `rosaeNlgVersion` and change the version
*** also change `rosaenlg` version in `package.json`
*** push, let gitlab CI do the job
* RosaeNLG:
** check non regression on another project
** check `changelog.adoc`
** update target version in `antora.yml`
** merge with master
** local environment: `lerna version --no-push --no-git-tag-version --exact patch` (or `minor` etc. instead of patch)
** make a `vXX.XX.XX` branch (to be seen by the doc project + to publish)
** push: `git push origin master`
** also push branch: `git push origin vXX.XX.XX`
** Gitlab CI should build
** npm publish: trigger manually on gitlab once build & tests are ok
* Doc:
** trigger the `antora-ui` project CI on gitlab
** trigger the `antora-playbook` CI on gitlab
*** and trigger manually the publication
* remove old branches on Gitlab
Packages are on npm: https://www.npmjs.com/package/rosaenlg
......@@ -21,15 +21,15 @@ RosaeNLG provides browser ready "tinyified" packages per language in `dist/brows
[options="header"]
|=======================================================
| Language | Compilation | Rendering | Size (approx.)
| `en_US` | no | yes | 792 Kb
| `en_US` | no | yes | 780 Kb
| `fr_FR` | no | yes | 601 Kb
| `de_DE` | no | yes | 567 Kb
| `it_IT` | no | yes | 553 Kb
| `OTHER` | no | yes | 504 Kb
| `en_US` | yes | yes | 1.8 Mb
| `fr_FR` | yes | yes | 8.7 Mb
| `de_DE` | yes | yes | 54.8 Mb
| `it_IT` | yes | yes | 10.4 Mb
| `de_DE` | yes | yes | 55 Mb
| `it_IT` | yes | yes | 10.5 Mb
| `OTHER` | yes | yes | 1.5 Mb
|=======================================================
......
const browserify = require('browserify');
const fs = require('fs');
const version = require('../package.json').version;
const alwaysIgnore = ['@rosaenlg/german-dict-helper', '@rosaenlg/lefff-helper', '@rosaenlg/morph-it-helper'];
const alwaysIgnore = [
'german-dict-helper',
'lefff-helper',
'morph-it-helper',
'rosaenlg-yseop',
'uglify-js', // looks like the new versions do not work in a browser? and used only by pug transformers
'jstransformer-uglify-js',
];
// language specific libs
const langSpecificLibs = {
......@@ -11,23 +18,23 @@ const langSpecificLibs = {
de_DE: [
'stopwords-de',
'snowball-stemmer.jsx/dest/german-stemmer.common.js',
'@rosaenlg/german-adjectives',
'@rosaenlg/german-determiners',
'@rosaenlg/german-ordinals',
'@rosaenlg/german-verbs',
'@rosaenlg/german-words',
'german-adjectives',
'german-determiners',
'german-ordinals',
'german-verbs',
'german-words',
'write-int',
],
// eslint-disable-next-line @typescript-eslint/camelcase
fr_FR: [
'stopwords-fr',
'snowball-stemmer.jsx/dest/french-stemmer.common.js',
'@rosaenlg/french-adjectives',
'@rosaenlg/french-determiners',
'@rosaenlg/french-h-muet-aspire',
'@rosaenlg/french-ordinals',
'@rosaenlg/french-verbs',
'@rosaenlg/french-words-gender',
'french-adjectives',
'french-determiners',
'french-h-muet-aspire',
'french-ordinals',
'french-verbs',
'french-words-gender',
'pluralize-fr',
'titlecase-french',
'written-number',
......@@ -36,17 +43,17 @@ const langSpecificLibs = {
it_IT: [
'stopwords-it',
'snowball-stemmer.jsx/dest/italian-stemmer.common.js',
'@rosaenlg/italian-adjectives',
'@rosaenlg/italian-determiners',
'@rosaenlg/italian-ordinals-cardinals',
'@rosaenlg/italian-verbs',
'@rosaenlg/italian-words',
'italian-adjectives',
'italian-determiners',
'italian-ordinals-cardinals',
'italian-verbs',
'italian-words',
],
OTHER: [],
};
function getIgnoreList(lang) {
var res = [];
const res = [];
res.push(...alwaysIgnore);
......@@ -61,10 +68,10 @@ function getIgnoreList(lang) {
function generate(lang, compile) {
let compSuffix = compile ? '_comp' : '';
let writeStream = fs.createWriteStream(`dist/browser/rosaenlg_tiny_${lang}_${version}${compSuffix}.js`);
const compSuffix = compile ? '_comp' : '';
const writeStream = fs.createWriteStream(`dist/browser/rosaenlg_tiny_${lang}_${version}${compSuffix}.js`);
var b = browserify({
const b = browserify({
standalone: `rosaenlg_${lang}`,
transform: ['brfs'],
});
......
......@@ -38,7 +38,7 @@ export class AdjectiveManager {
public agreeAdj(adjective: string, subject: any, params: any): void {
this.spy.appendDoubleSpace();
let agreedAdj = this.getAgreeAdj(adjective, subject, params);
const agreedAdj = this.getAgreeAdj(adjective, subject, params);
this.spy.appendPugHtml(agreedAdj);
if (this.language === 'it_IT' && agreedAdj.endsWith("'")) {
......@@ -55,20 +55,14 @@ export class AdjectiveManager {
} else {
// debug(`getAgreeAdj ${adjective} ${JSON.stringify(subject)} ${JSON.stringify(params)}`);
let gender: Genders = this.genderNumberManager.getRefGender(subject, params);
let number: Numbers = this.genderNumberManager.getRefNumber(subject, params) || 'S';
const gender: Genders = this.genderNumberManager.getRefGender(subject, params);
const number: Numbers = this.genderNumberManager.getRefNumber(subject, params) || 'S';
// debug('agreeAdj:' + ' gender=' + gender + ' number=' + number + ' / ' + adjective + ' / ' + JSON.stringify(subject).substring(0, 20) );
switch (this.language) {
case 'fr_FR':
return agreeFrenchAdj(
adjective,
gender as GendersMF,
number,
subject,
params && params.adjPos === 'BEFORE',
);
return agreeFrenchAdj(adjective, gender as GendersMF, number, subject, params && params.adjPos === 'BEFORE');
case 'de_DE':
return agreeGermanAdjective(
adjective,
......
......@@ -55,19 +55,19 @@ export class AsmManager {
if (!asm || !asm.mode || ['single_sentence', 'sentences', 'paragraphs'].indexOf(asm.mode) > -1) {
// ok
} else {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `asm mode is not valid: ${asm.mode}`;
throw err;
}
let targetMixin: string = mixinFct ? mixinFct : 'value';
const targetMixin: string = mixinFct ? mixinFct : 'value';
// debug('aaaa' + targetMixin);
let nonEmptyElts: any[] = [];
const nonEmptyElts: any[] = [];
// 0..length sequence
let eltsToTest = Array.from(Array(elts.length).keys());
const eltsToTest = Array.from(Array(elts.length).keys());
// we have to mix BEFORE testing
if (asm && asm.mix) {
......@@ -78,7 +78,7 @@ export class AsmManager {
this.saveRollbackManager.saveSituation('isEmpty');
for (let i = 0; i < eltsToTest.length; i++) {
let elt = elts[eltsToTest[i]];
const elt = elts[eltsToTest[i]];
if (!this.mixinIsEmpty(targetMixin, elt, params)) {
nonEmptyElts.push(elt);
}
......@@ -96,20 +96,20 @@ export class AsmManager {
//console.log('START ASSEMBLE');
// 0..length sequence
let eltsToList = Array.from(Array(size).keys());
const eltsToList = Array.from(Array(size).keys());
this.foreach(eltsToList, which, asm, params);
}
private mixinIsEmpty(mixinFct: string, param1: any, params: any): boolean {
let htmlBefore: string = this.spy.getPugHtml();
const htmlBefore: string = this.spy.getPugHtml();
this.spy.getPugMixins()[mixinFct](param1, params);
// test
// debug('before: ' + htmlBefore);
// debug('after: ' + this.spy.getPugHtml());
let isEmpty: boolean = htmlBefore === this.spy.getPugHtml() ? true : false;
const isEmpty: boolean = htmlBefore === this.spy.getPugHtml() ? true : false;
return isEmpty;
}
......@@ -191,7 +191,7 @@ export class AsmManager {
}
}
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `invalid begin_with_general: ${JSON.stringify(param)}`;
throw err;
......@@ -252,7 +252,7 @@ export class AsmManager {
private listStuffSentences(which: string, nonEmpty: any[], asm: Asm, params: any): void {
// debug(nonEmpty);
let size = nonEmpty.length;
const size = nonEmpty.length;
if (!params) {
params = {};
......@@ -307,7 +307,7 @@ export class AsmManager {
//-end
if (index === size - 1) {
if (asm.end != null && this.isDot(asm.end)) {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `when assembles is paragraph, the end is ignored when it is a dot.`;
throw err;
......@@ -335,7 +335,7 @@ export class AsmManager {
}
private listStuffSingleSentence(which: string, nonEmpty: any[], asm: Asm, params: any): void {
let size: number = nonEmpty.length;
const size: number = nonEmpty.length;
if (!params) params = {};
// make it available in params
......@@ -390,17 +390,20 @@ export class AsmManager {
public getDefaultLastSeparator() {
const defaultLastSep = {
'fr_FR': 'et',
'de_DE': 'und',
'en_US': 'and',
'it_IT': 'e'
// eslint-disable-next-line @typescript-eslint/camelcase
fr_FR: 'et',
// eslint-disable-next-line @typescript-eslint/camelcase
de_DE: 'und',
// eslint-disable-next-line @typescript-eslint/camelcase
en_US: 'and',
// eslint-disable-next-line @typescript-eslint/camelcase
it_IT: 'e',
};
if (Object.keys(defaultLastSep).indexOf(this.language)===-1) {
let err = new Error();
if (Object.keys(defaultLastSep).indexOf(this.language) === -1) {
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `no default last separator for ${this.language} language`;
throw err;
} else {
return defaultLastSep[this.language];
}
......
......@@ -52,7 +52,7 @@ export class ChoosebestManager {
},
): void {
if (this.spy.isEvaluatingChoosebest()) {
var err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `choosebest cannot be imbricated`;
throw err;
......@@ -84,7 +84,7 @@ export class ChoosebestManager {
}
function getFromParamsAndStoreDebug(paramName: string): any {
let res: any = params && params[paramName] ? params[paramName] : null;
const res: any = params && params[paramName] ? params[paramName] : null;
if (debugOn && res) {
params.debugRes[paramName] = res;
}
......@@ -95,11 +95,11 @@ export class ChoosebestManager {
const stopWordsOverride: string[] = getFromParamsAndStoreDebug('stop_words_override');
const identicals: string[][] = getFromParamsAndStoreDebug('identicals');
let newContentStart: number = this.spy.getPugHtml().length;
const newContentStart: number = this.spy.getPugHtml().length;
// SIMULATE
let scores: number[] = [];
const scores: number[] = [];
let alternatives: string[];
let debugInfos: DebugHolder[];
......@@ -108,14 +108,14 @@ export class ChoosebestManager {
debugInfos = [];
}
for (var i = 0; i < maxTest; i++) {
for (let i = 0; i < maxTest; i++) {
// SAVE
this.saveRollbackManager.saveSituation('choosebest');
this.randomManager.incrRnd(i);
this.spy.getPugMixins()[which](params);
let generated: string = this.spy.getPugHtml().substring(newContentStart);
const generated: string = this.spy.getPugHtml().substring(newContentStart);
// ROLLBACK
this.saveRollbackManager.rollback();
......@@ -124,7 +124,7 @@ export class ChoosebestManager {
alternatives.push(generated);
}
let debugInfo = {
const debugInfo = {
filteredAlt: null,
identicals: null,
identicalsMap: null,
......@@ -132,7 +132,7 @@ export class ChoosebestManager {
score: null,
};
let score = scoreAlternative(
const score = scoreAlternative(
this.language,
generated,
stopWordsAdd,
......@@ -160,7 +160,7 @@ export class ChoosebestManager {
}
// CHOOSE BEST
let best = scores.indexOf(Math.min(...scores));
const best = scores.indexOf(Math.min(...scores));
if (debugOn) {
params.debugRes.bestScore = scores[best];
......@@ -169,7 +169,7 @@ export class ChoosebestManager {
}
if (debugOn) {
let worst = scores.indexOf(Math.max(...scores));
const worst = scores.indexOf(Math.max(...scores));
params.debugRes.worstScore = scores[worst];
params.debugRes.worstText = alternatives[worst];
params.debugRes.worstDebug = debugInfos[worst];
......
......@@ -46,7 +46,7 @@ export function getDet(
params.dist,
); // || S will be tested when possessives added
default:
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `determiners not available in ${this.language}`;
throw err;
......
......@@ -64,7 +64,7 @@ export class GenderNumberManager {
public setRefGenderNumber(obj: any, gender: Genders, number: Numbers): void {
if (this.isEmptyObj(obj)) {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = 'setRefGenderNumber obj should not be empty';
throw err;
......@@ -84,7 +84,7 @@ export class GenderNumberManager {
//console.log(`setRefGenderNumber ${obj} ${genderOrWord}`);
if (this.isEmptyObj(obj)) {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = 'setRefGender obj should not be empty';
throw err;
......@@ -104,7 +104,7 @@ export class GenderNumberManager {
switch (this.language) {
case 'fr_FR':
if (explicitGender != 'M' && explicitGender != 'F') {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `gender must be M or F in French, here is ${explicitGender}`;
throw err;
......@@ -114,7 +114,7 @@ export class GenderNumberManager {
case 'de_DE':
/* istanbul ignore if */
if (explicitGender != 'M' && explicitGender != 'F' && explicitGender != 'N') {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `gender must be M or F or N in German, here is ${explicitGender}`;
throw err;
......@@ -124,7 +124,7 @@ export class GenderNumberManager {
case 'it_IT':
/* istanbul ignore if */
if (explicitGender != 'M' && explicitGender != 'F') {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `gender must be M or F in Italian, here is ${explicitGender}`;
throw err;
......@@ -134,7 +134,7 @@ export class GenderNumberManager {
case 'en_US':
/* istanbul ignore if */
if (explicitGender != 'M' && explicitGender != 'F' && explicitGender != 'N') {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `gender must be M or F or N in English, here is ${explicitGender}`;
throw err;
......@@ -150,20 +150,20 @@ export class GenderNumberManager {
switch (this.language) {
case 'fr_FR':
let genderFromFrDict: GendersMF = getGenderFrenchWord(genderOrWord, this.embeddedWords);
const genderFromFrDict: GendersMF = getGenderFrenchWord(genderOrWord, this.embeddedWords);
this.refGenderMap.set(obj, genderFromFrDict);
return;
case 'de_DE':
let genderFromDeDict: Genders = getGenderGermanWord(genderOrWord, this.embeddedWords);
const genderFromDeDict: Genders = getGenderGermanWord(genderOrWord, this.embeddedWords);
this.refGenderMap.set(obj, genderFromDeDict);
return;
case 'it_IT':
let genderFromItDict: Genders = getGenderItalianWord(genderOrWord, this.embeddedWords);
const genderFromItDict: Genders = getGenderItalianWord(genderOrWord, this.embeddedWords);
this.refGenderMap.set(obj, genderFromItDict);
return;
case 'en_US':
default:
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `there is gender dict for ${this.language}, set gender directly`;
throw err;
......@@ -171,7 +171,7 @@ export class GenderNumberManager {
} else {
// called with null for instance
// do nothing
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `setRefGender called on ${JSON.stringify(obj)} with invalid genderOrWord ${genderOrWord}`;
throw err;
......@@ -183,7 +183,7 @@ export class GenderNumberManager {
public getRefGender(obj: any, params: WithGender): Genders {
// debug('getRefGender called on: ' + JSON.stringify(obj));
let inMainMap: Genders = this.refGenderMap.get(obj);
const inMainMap: Genders = this.refGenderMap.get(obj);
if (inMainMap) {
return inMainMap;
} else if (typeof obj === 'string') {
......@@ -213,7 +213,7 @@ export class GenderNumberManager {
public getAnonymous(gender: Genders, number: Numbers): Anon {
// debug("getAnonymous");
let obj: Anon = { isAnonymous: true };
const obj: Anon = { isAnonymous: true };
this.setRefGenderNumber(obj, gender, number);
return obj;
}
......@@ -245,13 +245,13 @@ export class GenderNumberManager {
public setRefNumber(obj: any, number: Numbers): void {
if (this.isEmptyObj(obj)) {
let err = new Error();
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = 'setRefNumber obj should not be empty';
throw err;
}
if (number != 'S' && number != 'P') {
let err = new Error();