moved to es6 module system
This commit is contained in:
@ -4,8 +4,8 @@
|
||||
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
|
||||
"main": "build/build.js",
|
||||
"scripts": {
|
||||
"pretest": "tsc ts/tests/*Test.ts --module commonjs --outDir ./build/tests",
|
||||
"test": "mocha ./build/tests/*.js"
|
||||
"pretest": "tsc ts/tests/*Test.ts --module commonjs --outDir ./build/tests;",
|
||||
"test": "mocha ./build/tests/**/*Test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -19,6 +19,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"archiver": "^0.21.0",
|
||||
"lodash": "^4.6.1",
|
||||
"xml": "^1.0.1"
|
||||
},
|
||||
"author": "Dolan Miu",
|
||||
|
8
scripts/test-prepare.js
Normal file
8
scripts/test-prepare.js
Normal file
@ -0,0 +1,8 @@
|
||||
var fs = require('fs');
|
||||
|
||||
var data = fs.readFileSync('build/tests/tests/docxTest.js'); //read existing contents into data
|
||||
var fd = fs.openSync('build/tests/tests/docxTest.js', 'w+');
|
||||
var buffer = new Buffer('var docx = require("../docx/docx");');
|
||||
fs.writeSync(fd, buffer, 0, buffer.length); //write new data
|
||||
fs.writeSync(fd, data, 0, data.length); //append old data
|
||||
fs.close(fd);
|
3
ts/docx/body.ts
Normal file
3
ts/docx/body.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export class Body {
|
||||
|
||||
}
|
11
ts/docx/document.ts
Normal file
11
ts/docx/document.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export class Document {
|
||||
private body: string;
|
||||
|
||||
constructor() {
|
||||
this.body = "ggg";
|
||||
}
|
||||
|
||||
test() {
|
||||
return "hello";
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
module docx {
|
||||
|
||||
export class Docx {
|
||||
|
||||
}
|
||||
}
|
2
ts/docx/index.ts
Normal file
2
ts/docx/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export {Document} from "./document";
|
||||
export {Paragraph} from "./paragraph";
|
@ -1,5 +1,7 @@
|
||||
module docx {
|
||||
export class Paragraph {
|
||||
|
||||
export class Paragraph {
|
||||
private p: Array<string>;
|
||||
|
||||
constructor() {
|
||||
this.p = ['stuff']
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
module docx {
|
||||
export class Row {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
module docx {
|
||||
export class TapStop {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
module docx {
|
||||
export class Table {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
module docx {
|
||||
export class Text {
|
||||
|
||||
}
|
||||
}
|
25
ts/export/formatter.ts
Normal file
25
ts/export/formatter.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import * as _ from "lodash";
|
||||
|
||||
export class Formatter {
|
||||
|
||||
format(input: any) {
|
||||
var stringified = JSON.stringify(input);
|
||||
var newJson = JSON.parse(stringified);
|
||||
this.deepTraverseJson(newJson, (parent, value, key) => {
|
||||
parent.blah = parent[key];
|
||||
|
||||
});
|
||||
|
||||
return newJson;
|
||||
}
|
||||
|
||||
private deepTraverseJson(json, lambda: (json: any, value: any, key: string) => void) {
|
||||
_.forOwn(json, function(value, key) {
|
||||
if (_.isObject(value)) {
|
||||
this.deepTraverseJson(value, lambda);
|
||||
return;
|
||||
}
|
||||
lambda(json, value, key);
|
||||
});
|
||||
};
|
||||
}
|
1
ts/index.ts
Normal file
1
ts/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./docx";
|
@ -1,7 +1,8 @@
|
||||
/// <reference path="../docx/docx.ts" />
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
import * as docx from "../docx";
|
||||
|
||||
describe('Calculator', () => {
|
||||
var document : docx.Docx;
|
||||
var document : docx.Document;
|
||||
|
||||
/*beforeEach(function () {
|
||||
subject = new Calculator();
|
||||
@ -16,6 +17,10 @@ describe('Calculator', () => {
|
||||
});
|
||||
});*/
|
||||
describe('#test', () => {
|
||||
console.log(new docx.Docx);
|
||||
var document = new docx.Document();
|
||||
var paragraph = new docx.Paragraph();
|
||||
//var body = new docx.Body();
|
||||
console.log(JSON.stringify(paragraph));
|
||||
console.log(document.test());
|
||||
});
|
||||
});
|
19
ts/tests/formatterTest.ts
Normal file
19
ts/tests/formatterTest.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/lodash/lodash.d.ts" />
|
||||
|
||||
import {Formatter} from "../export/Formatter";
|
||||
|
||||
describe('Formatter', () => {
|
||||
var formatter: Formatter;
|
||||
|
||||
beforeEach(() => {
|
||||
formatter = new Formatter();
|
||||
});
|
||||
|
||||
describe('#format()', () => {
|
||||
it("should work", () => {
|
||||
var newJson = formatter.format('{"p":["stuff"]}');
|
||||
console.log(newJson);
|
||||
});
|
||||
});
|
||||
});
|
@ -4,9 +4,11 @@
|
||||
"sourceMap": true,
|
||||
"removeComments": true,
|
||||
"preserveConstEnums": true,
|
||||
"outFile": "../build/build.js",
|
||||
//"outFile": "../build/build.js",
|
||||
"outDir": "../build",
|
||||
"sourceRoot": "./",
|
||||
"rootDir": "./"
|
||||
"rootDir": "./",
|
||||
"module": "commonjs"
|
||||
},
|
||||
"exclude": [
|
||||
"tests"
|
||||
|
@ -7,6 +7,9 @@
|
||||
"installed": {
|
||||
"mocha/mocha.d.ts": {
|
||||
"commit": "299b5caa22876ef27dc8e9a5b7fd7bf93457b6f4"
|
||||
},
|
||||
"lodash/lodash.d.ts": {
|
||||
"commit": "299b5caa22876ef27dc8e9a5b7fd7bf93457b6f4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19172
ts/typings/lodash/lodash.d.ts
vendored
Normal file
19172
ts/typings/lodash/lodash.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
ts/typings/tsd.d.ts
vendored
1
ts/typings/tsd.d.ts
vendored
@ -1,2 +1,3 @@
|
||||
|
||||
/// <reference path="mocha/mocha.d.ts" />
|
||||
/// <reference path="lodash/lodash.d.ts" />
|
||||
|
Reference in New Issue
Block a user