mondrian-entries
Advanced tools
Comparing version 1.1.4 to 1.2.0
@@ -1,3 +0,5 @@ | ||
export declare const inputDir: string; | ||
export declare const outputDir: string; | ||
export declare const xmlDir: string; | ||
export declare const entriesDir: string; | ||
export declare const edsNotesDir: string; | ||
export declare const origNotesDir: string; | ||
export declare const xmlFiles: string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.inputDir = `${process.cwd()}/__xml__`; | ||
exports.outputDir = `${process.cwd()}/__entries__`; | ||
exports.xmlDir = `${process.cwd()}/__xml__`; | ||
exports.entriesDir = `${process.cwd()}/__entries__`; | ||
exports.edsNotesDir = `${process.cwd()}/__notes__/eds`; | ||
exports.origNotesDir = `${process.cwd()}/__notes__/orig`; | ||
exports.xmlFiles = [ | ||
@@ -6,0 +8,0 @@ '1917_NieuweBeeldingInSchilderkunst_STIJL.xml', |
@@ -38,3 +38,3 @@ "use strict"; | ||
const { svnUser, svnServer, svnPath } = config; | ||
const command = `svn export svn+ssh://${svnUser}@${svnServer}${svnPath}${svnFilePath} ${constants_1.inputDir}`; | ||
const command = `svn export svn+ssh://${svnUser}@${svnServer}${svnPath}${svnFilePath} ${constants_1.xmlDir}`; | ||
child_process_1.exec(command, (error, stdout, stderr) => { | ||
@@ -44,3 +44,3 @@ if (error) { | ||
} | ||
fs.removeSync(`${constants_1.inputDir}/.svn`); | ||
fs.removeSync(`${constants_1.xmlDir}/.svn`); | ||
resolve(); | ||
@@ -59,7 +59,7 @@ }); | ||
} | ||
fs.emptyDirSync(constants_1.inputDir); | ||
fs.emptyDirSync(constants_1.xmlDir); | ||
const files = constants_1.xmlFiles.map((f) => `editie/geschriften/${f}`); | ||
yield Promise.all(files.map(exportXmlFile(config))) | ||
.catch((e) => { | ||
fs.removeSync(constants_1.inputDir); | ||
fs.removeSync(constants_1.xmlDir); | ||
console.log(e.red); | ||
@@ -66,0 +66,0 @@ process.exit(); |
@@ -0,2 +1,6 @@ | ||
export interface IXmlData { | ||
content: string; | ||
path: string; | ||
} | ||
declare var _default: () => Promise<void>; | ||
export default _default; |
@@ -11,39 +11,44 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = require("fs-extra"); | ||
const colors = require('colors'); | ||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const hi_xml2html_1 = require("hi-xml2html"); | ||
const MondrianComponents = require("mondrian-components"); | ||
const lb_1 = require("./tags/lb"); | ||
const body_1 = require("./tags/body"); | ||
const constants_1 = require("../constants"); | ||
const postProcess = (state) => { | ||
const tags = [...state.usedTags].join(', '); | ||
const output = state.output | ||
.replace(/\n/g, '') | ||
.replace(/\s+/g, ' ') | ||
.replace(/> </g, '><'); | ||
return `import * as React from 'react'; import { ${tags} } from '${state.componentsPath}'; export default (props) => (${output});`; | ||
}; | ||
const handle_xml_1 = require("./handle-xml"); | ||
const extract_facsimiles_1 = require("./extract-facsimiles"); | ||
exports.default = () => __awaiter(this, void 0, void 0, function* () { | ||
let usedTags = new Set(); | ||
const xmlPaths = constants_1.xmlFiles.map((f) => `${constants_1.inputDir}/${f}`); | ||
for (const xmlPath of xmlPaths) { | ||
const xml = fs.readFileSync(xmlPath, 'utf8'); | ||
const jsxState = yield hi_xml2html_1.default(xml, { | ||
tagClass: 'jsx', | ||
componentsPath: 'mondrian-components', | ||
startFromTag: 'body', | ||
tags: { | ||
body: body_1.default, | ||
lb: lb_1.default, | ||
} | ||
}); | ||
const outputPath = xmlPath | ||
.replace(constants_1.inputDir, constants_1.outputDir) | ||
.replace('.xml', '.tsx'); | ||
fs.ensureDirSync(path.dirname(outputPath)); | ||
fs.writeFileSync(outputPath, postProcess(jsxState), 'utf8'); | ||
usedTags = new Set([...usedTags, ...jsxState.usedTags]); | ||
} | ||
const xmlPaths = constants_1.xmlFiles.map((f) => `${constants_1.xmlDir}/${f}`); | ||
const xmlData = xmlPaths.map((xmlPath) => ({ | ||
content: fs.readFileSync(xmlPath, 'utf8'), | ||
path: xmlPath, | ||
})); | ||
const facsimiles = yield extract_facsimiles_1.default(xmlData); | ||
const usedTagsInText = yield handle_xml_1.default(xmlData, constants_1.entriesDir, { | ||
ignore: [{ | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'edsNotes', | ||
}, { | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'origNotes', | ||
}], | ||
state: { | ||
facsimiles, | ||
} | ||
}); | ||
const usedTagsInEditorNotes = yield handle_xml_1.default(xmlData, constants_1.edsNotesDir, { | ||
parent: { | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'edsNotes', | ||
}, | ||
}); | ||
const usedTagsInOrigNotes = yield handle_xml_1.default(xmlData, constants_1.origNotesDir, { | ||
parent: { | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'origNotes', | ||
}, | ||
}); | ||
const usedTags = usedTagsInText.concat(usedTagsInEditorNotes, usedTagsInOrigNotes); | ||
const definedTags = Object.keys(MondrianComponents); | ||
@@ -50,0 +55,0 @@ const undefinedTags = [...usedTags].filter((t) => definedTags.indexOf(t) === -1); |
import { JsxTag } from 'hi-xml2html'; | ||
export declare const falsifyIsSelfClosing: (data: any) => any; | ||
export default class Lb extends JsxTag { | ||
@@ -3,0 +4,0 @@ constructor(data: any, state: any); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const hi_xml2html_1 = require("hi-xml2html"); | ||
const falsifyIsSelfClosing = (data) => (Object.assign({}, data, { isSelfClosing: false })); | ||
exports.falsifyIsSelfClosing = (data) => (Object.assign({}, data, { isSelfClosing: false })); | ||
class Lb extends hi_xml2html_1.JsxTag { | ||
constructor(data, state) { | ||
super(falsifyIsSelfClosing(data), state); | ||
if (!state.hasOwnProperty('linenumber')) | ||
state.linenumber = 0; | ||
state.linenumber = state.linenumber + 1; | ||
super(exports.falsifyIsSelfClosing(data), state); | ||
if (!state.custom.hasOwnProperty('linenumber')) | ||
state.custom.linenumber = 0; | ||
state.custom.linenumber = state.custom.linenumber + 1; | ||
state.usedTags.add('No'); | ||
} | ||
openAfter() { | ||
return `<No className="no" active={props.lineNumber === '${this.state.linenumber}'}>${this.state.linenumber}</No>`; | ||
return `<No className="no" active={props.lineNumber === '${this.state.custom.linenumber}'}>${this.state.custom.linenumber}</No>`; | ||
} | ||
@@ -16,0 +16,0 @@ } |
@@ -26,3 +26,3 @@ "use strict"; | ||
exports.default = () => __awaiter(this, void 0, void 0, function* () { | ||
const xmlPaths = constants_1.xmlFiles.map((f) => `${constants_1.inputDir}/${f}`); | ||
const xmlPaths = constants_1.xmlFiles.map((f) => `${constants_1.xmlDir}/${f}`); | ||
let list = []; | ||
@@ -32,6 +32,11 @@ for (const xmlPath of xmlPaths) { | ||
const emptyState = yield hi_xml2html_1.default(xml, { | ||
startFromTag: 'body', | ||
tagClass: 'empty', | ||
tags: { lb: lb_1.default }, | ||
tagsToSkip: ['c'], | ||
parent: { | ||
name: 'body', | ||
}, | ||
outputType: 'empty', | ||
getComponent: (node) => { | ||
if (node.name === 'lb') | ||
return lb_1.default; | ||
}, | ||
ignore: [{ name: 'c' }], | ||
}); | ||
@@ -38,0 +43,0 @@ list = list.concat(postProcess(xmlPath, emptyState)); |
@@ -19,5 +19,5 @@ "use strict"; | ||
const main = () => __awaiter(this, void 0, void 0, function* () { | ||
if (!development || !fs.existsSync(constants_1.inputDir)) | ||
if (!development || !fs.existsSync(constants_1.xmlDir)) | ||
yield fetch_1.default(); | ||
fs.emptyDirSync(constants_1.outputDir); | ||
fs.emptyDirSync(constants_1.entriesDir); | ||
process.stdout.write('* Generate JSX from XML. '.cyan); | ||
@@ -30,5 +30,5 @@ yield generate_jsx_1.default(); | ||
if (!development) | ||
fs.removeSync(constants_1.inputDir); | ||
fs.removeSync(constants_1.xmlDir); | ||
console.log('\nA L L D O N E ! ! !\n'.rainbow.bold); | ||
}); | ||
main(); |
@@ -0,1 +1,6 @@ | ||
### v1.2.0 (2017/4/28 16:51) | ||
* Refactor and add notes | ||
* Merge | ||
* Use getComponent func instead of tags map to increase flexibility when passing external components | ||
### v1.1.4 (2017/4/20 14:7) | ||
@@ -2,0 +7,0 @@ * Log undefined tags |
{ | ||
"name": "mondrian-entries", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "Generate .tsx and Solr input from TEI-XML", | ||
@@ -21,4 +21,4 @@ "repository": "https://github.com/HuygensING/mondrian-entries", | ||
"glob": "^7.1.1", | ||
"hi-xml2html": "^1.2.1", | ||
"mondrian-components": "^1.2.3", | ||
"hi-xml2html": "^2.0.0", | ||
"mondrian-components": "^1.3.0", | ||
"sax": "^1.2.2" | ||
@@ -25,0 +25,0 @@ }, |
@@ -1,3 +0,5 @@ | ||
export const inputDir = `${process.cwd()}/__xml__`; | ||
export const outputDir = `${process.cwd()}/__entries__`; | ||
export const xmlDir = `${process.cwd()}/__xml__`; | ||
export const entriesDir = `${process.cwd()}/__entries__`; | ||
export const edsNotesDir = `${process.cwd()}/__notes__/eds`; | ||
export const origNotesDir = `${process.cwd()}/__notes__/orig`; | ||
export const xmlFiles = [ | ||
@@ -4,0 +6,0 @@ '1917_NieuweBeeldingInSchilderkunst_STIJL.xml', |
@@ -7,3 +7,3 @@ /* | ||
import * as fs from 'fs-extra'; | ||
import { xmlFiles, inputDir } from '../constants'; | ||
import { xmlFiles, xmlDir } from '../constants'; | ||
import * as readline from 'readline'; | ||
@@ -40,3 +40,3 @@ | ||
const { svnUser, svnServer, svnPath } = config; | ||
const command = `svn export svn+ssh://${svnUser}@${svnServer}${svnPath}${svnFilePath} ${inputDir}`; | ||
const command = `svn export svn+ssh://${svnUser}@${svnServer}${svnPath}${svnFilePath} ${xmlDir}`; | ||
exec(command, (error, stdout, stderr) => { | ||
@@ -47,3 +47,3 @@ if (error) { | ||
fs.removeSync(`${inputDir}/.svn`); | ||
fs.removeSync(`${xmlDir}/.svn`); | ||
resolve(); | ||
@@ -63,9 +63,9 @@ }) | ||
// Make sure the inputDir exists | ||
fs.emptyDirSync(inputDir); | ||
// Make sure the xmlDir exists | ||
fs.emptyDirSync(xmlDir); | ||
const files = xmlFiles.map((f) => `editie/geschriften/${f}`); | ||
await Promise.all(files.map(exportXmlFile(config))) | ||
.catch((e) => { | ||
// Remove the inputDir, because transfer has errored | ||
fs.removeSync(inputDir); | ||
// Remove the xmlDir, because transfer has errored | ||
fs.removeSync(xmlDir); | ||
console.log(e.red); | ||
@@ -72,0 +72,0 @@ process.exit(); |
@@ -0,41 +1,59 @@ | ||
import * as fs from "fs-extra"; | ||
const colors = require('colors'); | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import xml2html from 'hi-xml2html'; | ||
import * as MondrianComponents from 'mondrian-components'; | ||
import Lb from './tags/lb'; | ||
import Body from './tags/body'; | ||
import {xmlFiles, inputDir, outputDir} from "../constants"; | ||
import {xmlFiles, xmlDir, entriesDir, edsNotesDir, origNotesDir} from "../constants"; | ||
import handleXml from './handle-xml'; | ||
import extractFacsimiles from './extract-facsimiles'; | ||
const postProcess = (state): string => { | ||
const tags = [...state.usedTags].join(', '); | ||
const output = state.output | ||
.replace(/\n/g, '') | ||
.replace(/\s+/g, ' ') | ||
.replace(/> </g, '><'); | ||
export interface IXmlData { | ||
content: string; | ||
path: string; | ||
} | ||
return `import * as React from 'react'; import { ${tags} } from '${state.componentsPath}'; export default (props) => (${output});`; | ||
}; | ||
export default async () => { | ||
const xmlPaths: string[] = xmlFiles.map((f) => `${xmlDir}/${f}`); | ||
const xmlData: IXmlData[] = xmlPaths.map((xmlPath) => ({ | ||
content: fs.readFileSync(xmlPath, 'utf8'), | ||
path: xmlPath, | ||
})); | ||
export default async () => { | ||
let usedTags = new Set(); | ||
const xmlPaths = xmlFiles.map((f) => `${inputDir}/${f}`); | ||
for (const xmlPath of xmlPaths) { | ||
const xml: string = fs.readFileSync(xmlPath, 'utf8'); | ||
const jsxState = await xml2html(xml, { | ||
tagClass: 'jsx', | ||
componentsPath: 'mondrian-components', | ||
startFromTag: 'body', | ||
tags: { | ||
body: Body, | ||
lb: Lb, | ||
} | ||
}); | ||
const outputPath = xmlPath | ||
.replace(inputDir, outputDir) | ||
.replace('.xml', '.tsx'); | ||
fs.ensureDirSync(path.dirname(outputPath)); | ||
fs.writeFileSync(outputPath, postProcess(jsxState), 'utf8') | ||
usedTags = new Set([...usedTags, ...jsxState.usedTags]); | ||
} | ||
// Extract facsimiles | ||
const facsimiles = await extractFacsimiles(xmlData); | ||
// Parse text (writes a tsx file per entry) | ||
const usedTagsInText = await handleXml(xmlData, entriesDir, { | ||
ignore: [{ | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'edsNotes', | ||
}, { | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'origNotes', | ||
}], | ||
state: { | ||
facsimiles, | ||
} | ||
}); | ||
// Parse editor notes (writes a tsx file per entry) | ||
const usedTagsInEditorNotes = await handleXml(xmlData, edsNotesDir, { | ||
parent: { | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'edsNotes', | ||
}, | ||
}); | ||
// Parse orig notes (writes a tsx file per entry) | ||
const usedTagsInOrigNotes = await handleXml(xmlData, origNotesDir, { | ||
parent: { | ||
attribute: 'type', | ||
name: 'div', | ||
value: 'origNotes', | ||
}, | ||
}); | ||
// Log undefined tags | ||
const usedTags = usedTagsInText.concat(usedTagsInEditorNotes, usedTagsInOrigNotes); | ||
const definedTags = Object.keys(MondrianComponents); | ||
@@ -42,0 +60,0 @@ const undefinedTags = [...usedTags].filter((t) => definedTags.indexOf(t) === -1); |
@@ -1,4 +0,4 @@ | ||
import { JsxTag } from 'hi-xml2html'; | ||
import {JsxTag} from 'hi-xml2html'; | ||
const falsifyIsSelfClosing = (data) => ({ | ||
export const falsifyIsSelfClosing = (data) => ({ | ||
...data, | ||
@@ -11,4 +11,4 @@ ...{ isSelfClosing: false }, | ||
super(falsifyIsSelfClosing(data), state); | ||
if (!state.hasOwnProperty('linenumber')) state.linenumber = 0; | ||
state.linenumber = state.linenumber + 1; | ||
if (!state.custom.hasOwnProperty('linenumber')) state.custom.linenumber = 0; | ||
state.custom.linenumber = state.custom.linenumber + 1; | ||
state.usedTags.add('No'); | ||
@@ -18,4 +18,4 @@ } | ||
openAfter() { | ||
return `<No className="no" active={props.lineNumber === '${this.state.linenumber}'}>${this.state.linenumber}</No>`; | ||
return `<No className="no" active={props.lineNumber === '${this.state.custom.linenumber}'}>${this.state.custom.linenumber}</No>`; | ||
} | ||
}; |
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import xml2html from 'hi-xml2html'; | ||
import {xmlFiles, inputDir} from "../constants"; | ||
import {xmlFiles, xmlDir} from "../constants"; | ||
import Lb from "./tags/lb"; | ||
@@ -20,3 +20,3 @@ | ||
export default async () => { | ||
const xmlPaths = xmlFiles.map((f) => `${inputDir}/${f}`); | ||
const xmlPaths = xmlFiles.map((f) => `${xmlDir}/${f}`); | ||
let list = []; | ||
@@ -27,6 +27,10 @@ | ||
const emptyState = await xml2html(xml, { | ||
startFromTag: 'body', | ||
tagClass: 'empty', | ||
tags: { lb: Lb }, | ||
tagsToSkip: ['c'], | ||
parent: { | ||
name: 'body', | ||
}, | ||
outputType: 'empty', | ||
getComponent: (node) => { | ||
if (node.name === 'lb') return Lb; | ||
}, | ||
ignore: [{ name: 'c' }], | ||
}); | ||
@@ -33,0 +37,0 @@ |
@@ -5,3 +5,3 @@ import * as fs from 'fs-extra'; | ||
import generateSolrInput from './generate-solr-input'; | ||
import {inputDir, outputDir} from './constants'; | ||
import {xmlDir, entriesDir} from './constants'; | ||
const colors = require('colors'); | ||
@@ -11,10 +11,9 @@ | ||
const main = async () => { | ||
// Fetch entries and XML files when not developing | ||
// or when the inputDir does not exist | ||
if (!development || !fs.existsSync(inputDir)) await fetch(); | ||
// or when the xmlDir does not exist | ||
if (!development || !fs.existsSync(xmlDir)) await fetch(); | ||
// Empty output dir(s) | ||
fs.emptyDirSync(outputDir); | ||
fs.emptyDirSync(entriesDir); | ||
@@ -29,4 +28,4 @@ process.stdout.write('* Generate JSX from XML. '.cyan); | ||
// Remove the inputDir if not developing | ||
if (!development) fs.removeSync(inputDir); | ||
// Remove the xmlDir if not developing | ||
if (!development) fs.removeSync(xmlDir); | ||
@@ -33,0 +32,0 @@ console.log('\nA L L D O N E ! ! !\n'.rainbow.bold); |
150205
62
940
8
+ Addedhi-xml2html@2.1.0(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
- Removedhi-xml2html@1.2.1(transitive)
Updatedhi-xml2html@^2.0.0
Updatedmondrian-components@^1.3.0