Commit 2d798ebe authored by Ludan Stoecklé's avatar Ludan Stoecklé

1.3.2

parent fcf90807
{
"name": "english-determiners",
"version": "2.3.1",
"version": "2.3.2",
"description": "English determiners",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "french-adjectives",
"version": "2.3.1",
"version": "2.3.2",
"description": "Agreement of adjectives in French",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -45,7 +45,7 @@
},
"dependencies": {
"debug": "^4.1.1",
"french-h-muet-aspire": "2.3.1"
"french-h-muet-aspire": "2.3.2"
},
"keywords": [
"french",
......
{
"name": "french-determiners",
"version": "2.3.1",
"version": "2.3.2",
"description": "French determiners",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "french-h-muet-aspire",
"version": "2.3.1",
"version": "2.3.2",
"description": "List of French words that are \"aspiré\" (vs. \"muet\")\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[Dstarting with a h that is \"aspiré\" vs \"muet\"",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "french-ordinals",
"version": "2.3.1",
"version": "2.3.2",
"description": "Ordinal numbers in French: 12 => douzième",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "french-verbs",
"version": "2.3.1",
"version": "2.3.2",
"description": "French verbs: conjugation, based on the Lefff contents, and list of transitive and intransitive verbs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -50,7 +50,7 @@
},
"dependencies": {
"debug": "^4.1.1",
"french-h-muet-aspire": "2.3.1"
"french-h-muet-aspire": "2.3.2"
},
"devDependencies": {
"copyfiles": "^2.1.0",
......
{
"name": "french-words-gender",
"version": "2.3.1",
"version": "2.3.2",
"description": "Gender of French words, based on the Lefff",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "german-adjectives",
"version": "2.3.1",
"version": "2.3.2",
"description": "German adjectives, based on german-pos-dict",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "german-determiners",
"version": "2.3.1",
"version": "2.3.2",
"description": "German determiners",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "german-dict-helper",
"version": "2.3.1",
"version": "2.3.2",
"description": "Helper functions on an included database derived from german-pos-dict",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "german-ordinals",
"version": "2.3.1",
"version": "2.3.2",
"description": "Ordinal numbers in German: 12 => zwölfte",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "german-verbs",
"version": "2.3.1",
"version": "2.3.2",
"description": "German verbs, based on german-pos-dict",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "german-words",
"version": "2.3.1",
"version": "2.3.2",
"description": "Gender and case of German words, based on german-pos-dict",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
......@@ -24,6 +24,20 @@ npm install gulp-freenlpg
* `dest` (string, mandatory): the filename that will contain the output
* `options` (mandatory): the parameters that will be given to `renderFile`; typically put `language` and most often some data.
`packageTemplateJson` packages (and optionnaly compiles) templates into a single object, generally for JSON serialization. One single `PackagedTemplateParams` param:
* `templateId`: string; will be just kept as is (not used during the packaging process)
* `entryTemplate`: string; the main template; do not put the full path
* `folderWithTemplates`: string; the folder containing all the templates (including the `entryTemplate`)
* `compileInfo`: mandatory as at some point compilation will occur
** `activate`: boolean; if set, the template will be compiled, and included in the output
** `compileDebug`: boolean; activate Pug debug
** `language`: language
* `autotest`: all fields will just be copied as is in the output (not used during packaging)
** `activate`: boolean
** `input`: object that is a valid input to render the template
** `expected`: string[]; strings that should be in the rendered template
```javascript
var gulpFreenlpg = require('gulp-rosaenlg');
......
import { Languages } from './index';
export interface PackagedTemplateParams {
templateId: string;
entryTemplate: string;
folderWithTemplates: string;
compileInfo: CompileInfo;
autotest?: Autotest;
}
interface CompileInfo {
activate: boolean;
compileDebug: boolean;
language: Languages;
}
interface Autotest {
activate: boolean;
input: any;
expected: string[];
}
interface TemplatesMap {
[key: string]: string;
}
export interface PackagedTemplate {
templateId: string;
entryTemplate: string;
templates: TemplatesMap;
compileInfo: CompileInfo;
compiled?: string;
autotest?: Autotest;
}
import fs = require('fs');
import path = require('path');
import stream = require('stream');
import rosaenlgPug = require('rosaenlg');
import browserify = require('browserify');
import minify = require('minify-stream');
export type Languages = 'en_US' | 'fr_FR' | 'de_DE' | string;
import { PackagedTemplateParams, PackagedTemplate } from './PackagedTemplate';
/*
interface RosaeNlgOptions {
language: Languages;
//[key: string]: any;
}
*/
export type Languages = 'en_US' | 'fr_FR' | 'de_DE' | string;
export function renderTemplateInFile(template: string, dest: string, options: any): void {
if (!template) {
......@@ -95,3 +91,60 @@ export function compileTemplates(
return b.bundle().pipe(outputStream);
}
}
function getFilesInDir(dir: string, filelist: string[]): string[] {
const files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(path.join(dir, file)).isDirectory()) {
filelist = getFilesInDir(path.join(dir, file), filelist);
} else {
if (path.extname(file) == '.pug') {
filelist.push(path.join(dir, file));
}
}
});
return filelist;
}
export function packageTemplateJson(params: PackagedTemplateParams): PackagedTemplate {
const res: PackagedTemplate = {
templateId: params.templateId,
entryTemplate: params.entryTemplate,
compileInfo: params.compileInfo,
templates: {},
};
// autotest data if present
if (params.autotest) {
res.autotest = params.autotest;
}
// get templates content
const files = getFilesInDir(params.folderWithTemplates, null);
if (files == null || files.length == 0) {
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `no files found in ${params.folderWithTemplates}`;
throw err;
}
for (let i = 0; i < files.length; i++) {
const file = files[i];
const finalFileName = file
.replace(new RegExp('\\' + path.sep, 'g'), '/') // change to linux paths
.replace(params.folderWithTemplates + '/', ''); // and remove root
res.templates[finalFileName] = fs.readFileSync(file, 'utf-8');
}
// compile if asked
if (params.compileInfo && params.compileInfo.activate) {
const compiled = rosaenlgPug.compileFileClient(path.join(params.folderWithTemplates, params.entryTemplate), {
language: params.compileInfo.language,
compileDebug: params.compileInfo.compileDebug,
embedResources: true,
});
res.compiled = compiled;
}
return res;
}
{
"name": "gulp-rosaenlg",
"version": "2.3.1",
"version": "2.3.2",
"description": "RosaeNLG client side packaging helper",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -60,6 +60,6 @@
"browserify": "^16.2.3",
"debug": "^4.1.1",
"minify-stream": "^1.2.0",
"rosaenlg": "1.3.1"
"rosaenlg": "1.3.2"
}
}
include inc/included
p
| bla
| #[+includedMixin()]
......@@ -63,4 +63,77 @@ describe('gulp-rosaenlg', function() {
});
});
});
describe('#packageTemplateJson', function() {
describe('nominal', function() {
it(`basic`, function() {
const packagedObj = lib.packageTemplateJson({
templateId: 'test_inc',
entryTemplate: 'test.pug',
folderWithTemplates: 'test/includes',
compileInfo: {
activate: false,
compileDebug: false,
language: 'en_US',
},
autotest: {
activate: true,
input: {
language: 'en_US',
},
expected: ['Bla', 'included'],
},
});
// console.log(JSON.stringify(packagedObj));
assert.equal(packagedObj.templateId, 'test_inc');
assert.equal(packagedObj.entryTemplate, 'test.pug');
assert.equal(Object.keys(packagedObj.templates).length, 2);
assert.equal(packagedObj.autotest.input.language, 'en_US');
assert(packagedObj.templates['test.pug'].indexOf('bla') > -1);
assert(packagedObj.templates['inc/included.pug'].indexOf('included') > -1);
});
it(`with comp`, function() {
const packagedObj = lib.packageTemplateJson({
templateId: 'test_inc',
entryTemplate: 'test.pug',
folderWithTemplates: 'test/includes',
compileInfo: {
activate: true,
compileDebug: false,
language: 'en_US',
},
});
// console.log(JSON.stringify(packagedObj));
assert(packagedObj.compiled != null);
assert(packagedObj.compiled.indexOf('bla') > -1);
assert(packagedObj.compiled.indexOf('pug_html') > -1);
});
});
describe('edge', function() {
it(`empty path`, function() {
assert.throws(
() =>
lib.packageTemplateJson({
templateId: 'test_inc',
entryTemplate: 'test.pug',
folderWithTemplates: 'test/includes/emptyDir',
}),
/no files found/,
);
});
it(`invalid path`, function() {
assert.throws(
() =>
lib.packageTemplateJson({
templateId: 'test_inc',
entryTemplate: 'test.pug',
folderWithTemplates: 'bla',
}),
/no such file or directory/,
);
});
});
});
});
{
"name": "italian-adjectives",
"version": "2.3.1",
"version": "2.3.2",
"description": "Italian adjectives, based on morph-it",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -58,6 +58,6 @@
"license": "MIT",
"dependencies": {
"debug": "^4.1.1",
"rosaenlg-filter": "2.3.1"
"rosaenlg-filter": "2.3.2"
}
}
{
"name": "italian-determiners",
"version": "2.3.1",
"version": "2.3.2",
"description": "Italian determiners",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "italian-ordinals-cardinals",
"version": "2.3.1",
"version": "2.3.2",
"description": "Ordinal and cardinal numbers in Italian",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "italian-verbs",
"version": "2.3.1",
"version": "2.3.2",
"description": "Italian verbs, based on morph-it",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "italian-words",
"version": "2.3.1",
"version": "2.3.2",
"description": "Gender and plural of Italian words, based on morph-it",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "lefff-helper",
"version": "2.3.1",
"version": "2.3.2",
"description": "Helper functions on an included database derived from Lefff",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "morph-it-helper",
"version": "2.3.1",
"version": "2.3.2",
"description": "Helper functions on an included database derived from morph-it (Free Morphological Lexicon for the Italian Language)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......
{
"name": "rosaenlg-filter",
"version": "2.3.1",
"version": "2.3.2",
"description": "Filtering feature of RosaeNLG",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -43,7 +43,7 @@
"better-title-case": "^1.0.1",
"compromise": "^11.14.3",
"debug": "^4.1.1",
"french-h-muet-aspire": "2.3.1",
"french-h-muet-aspire": "2.3.2",
"titlecase-french": "^1.0.1"
},
"keywords": [
......
{
"name": "rosaenlg-pug-code-gen",
"version": "3.3.1",
"version": "3.3.2",
"description": "Default code-generator for pug. It generates HTML via a JavaScript template function. - RosaeNLG fork",
"scripts": {
"build": "tsc && cp lib/index.js dist/",
......@@ -53,13 +53,13 @@
"constantinople": "^3.1.2",
"debug": "^4.1.1",
"doctypes": "^1.1.0",
"french-verbs": "2.3.1",
"german-adjectives": "2.3.1",
"german-verbs": "2.3.1",
"german-words": "2.3.1",
"italian-adjectives": "2.3.1",
"italian-verbs": "2.3.1",
"italian-words": "2.3.1",
"french-verbs": "2.3.2",
"german-adjectives": "2.3.2",
"german-verbs": "2.3.2",
"german-words": "2.3.2",
"italian-adjectives": "2.3.2",
"italian-verbs": "2.3.2",
"italian-words": "2.3.2",
"js-stringify": "^1.0.1",
"pug-attrs": "^2.0.3",
"pug-error": "^1.3.2",
......
{
"name": "rosaenlg-pug-filters",
"version": "4.3.1",
"version": "4.3.2",
"description": "Code for processing filters in pug templates - RosaeNLG fork",
"scripts": {},
"keywords": [
......@@ -12,7 +12,7 @@
"jstransformer": "1.0.0",
"pug-error": "^1.3.2",
"resolve": "^1.1.6",
"rosaenlg-pug-walk": "2.2.1",
"rosaenlg-pug-walk": "2.2.2",
"snyk": "^1.232.0"
},
"devDependencies": {
......@@ -21,9 +21,9 @@
"jstransformer-less": "^2.3.0",
"jstransformer-markdown-it": "^2.1.0",
"jstransformer-stylus": "^1.0.0",
"rosaenlg-pug-lexer": "5.2.1",
"rosaenlg-pug-load": "3.2.1",
"rosaenlg-pug-parser": "6.2.1"
"rosaenlg-pug-lexer": "5.2.2",
"rosaenlg-pug-load": "3.2.2",
"rosaenlg-pug-parser": "6.2.2"
},
"repository": {
"type": "git",
......
{
"name": "rosaenlg-pug-lexer",
"version": "5.2.1",
"version": "5.2.2",
"description": "The pug lexer (takes a string and converts it to an array of tokens) - RosaeNLG fork",
"keywords": [
"pug"
......
{
"name": "rosaenlg-pug-linker",
"version": "4.2.1",
"version": "4.2.2",
"description": "Link multiple pug ASTs together using include/extends - RosaeNLG fork",
"keywords": [
"pug"
......@@ -8,12 +8,12 @@
"scripts": {},
"dependencies": {
"pug-error": "^1.3.2",
"rosaenlg-pug-walk": "2.2.1"
"rosaenlg-pug-walk": "2.2.2"
},
"devDependencies": {
"rosaenlg-pug-lexer": "5.2.1",
"rosaenlg-pug-load": "3.2.1",
"rosaenlg-pug-parser": "6.2.1"
"rosaenlg-pug-lexer": "5.2.2",
"rosaenlg-pug-load": "3.2.2",
"rosaenlg-pug-parser": "6.2.2"
},
"repository": {
"type": "git",
......
{
"name": "rosaenlg-pug-load",
"version": "3.2.1",
"version": "3.2.2",
"description": "The Pug loader is responsible for loading the depenendencies of a given Pug file. - RosaeNLG fork",
"keywords": [
"pug"
......@@ -8,11 +8,11 @@
"scripts": {},
"dependencies": {
"object-assign": "^4.1.0",
"rosaenlg-pug-walk": "2.2.1"
"rosaenlg-pug-walk": "2.2.2"
},
"devDependencies": {
"rosaenlg-pug-lexer": "5.2.1",
"rosaenlg-pug-parser":