Skip to content

Commit

Permalink
Merge pull request #60 from CSBiology/npm_package_ci
Browse files Browse the repository at this point in the history
Npm package ci
  • Loading branch information
omaus committed Aug 3, 2023
2 parents 489f6b7 + a96bcd0 commit ec1b7c9
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,4 @@ tmp/
/tests/JS/fable
/tests/JS/FsSpreadsheet.Exceljs
/tests/FsSpreadsheet.Exceljs.Tests/js
/dist
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### 3.2.2+caf21db (Released 2023-8-1)

### 3.2.1+caf21db (Released 2023-8-1)
* Additions:
* [[#cb35186](https://github.com/CSBiology/FsSpreadsheet/commit/cb3518609e9fe42e05789441906dc148a4b8d53e)] Update and clean up RELEASE_NOTES.md
* [[#489f6b7](https://github.com/CSBiology/FsSpreadsheet/commit/489f6b77789cca13840382d5c2dd03dc973b65df)] Add logo to Exceljs project file
* [[#caf21db](https://github.com/CSBiology/FsSpreadsheet/commit/caf21db25490908a61381fd229fdaf5cc9a66ab2)] INcrease package.json version together with fake task.

### 3.2.0+e47262b (Released 2023-7-31)
* Additions:
* [[#2b9c7fa](https://github.com/CSBiology/FsSpreadsheet/commit/2b9c7fa2c3fccfb6a5956b2e244a557fda4e0793)] Add some tests for exceljs
Expand Down
11 changes: 11 additions & 0 deletions build/ReleaseNotesTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ let createAssemblyVersion = BuildTask.create "createvfs" [] {

// https://github.com/Freymaurer/Fake.Extensions.Release#releaseupdate
let updateReleaseNotes = BuildTask.createFn "ReleaseNotes" [] (fun config ->
ReleaseNotes.ensure()
ReleaseNotes.update(ProjectInfo.gitOwner, ProjectInfo.project, config)

let semVer =
Fake.Core.ReleaseNotes.load "RELEASE_NOTES.md"
|> fun x -> x.SemVer.AsString

// Update Version in src/Nfdi4Plants.Fornax.Template/package.json
let p = "package.json"
let t = System.IO.File.ReadAllText p
let tNew = System.Text.RegularExpressions.Regex.Replace(t, """\"version\": \".*\",""", sprintf "\"version\": \"%s\"," semVer )
System.IO.File.WriteAllText(p, tNew)
)


Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "fsspreadsheet",
"version": "1.3.0",
"description": "Spreadsheet creation and manipulation in FSharp",
"version": "3.2.2+caf21db",
"description": "Minimal spreadsheet creation and manipulation using exceljs io.",
"type": "module",
"main": "dist/Xlsx.js",
"files": [ "dist", "package.json" ],
"scripts": {
"clean-test": "cd tests/FsSpreadsheet.Tests/js & dotnet fable clean --extension .js --yes",
"pretest": "npm run clean-test && dotnet fable tests/FsSpreadsheet.Tests -o tests/FsSpreadsheet.Tests/js",
Expand All @@ -12,13 +14,16 @@
"testexceljs": "mocha tests/FsSpreadsheet.Exceljs.Tests/js",
"clean-testjs": "cd tests/JS/FsSpreadsheet.Exceljs & dotnet fable clean --extension .fs.js --yes",
"pretestjs": "npm run clean-testjs && dotnet fable src/FsSpreadsheet.Exceljs -o tests/JS/FsSpreadsheet.Exceljs --extension .fs.js",
"testjs": "mocha tests/JS"
"testjs": "mocha tests/JS --timeout 20000",
"prebundle": "mkdir dist & dotnet fable clean --extension .js --yes -o dist",
"bundle": "dotnet fable src/FsSpreadsheet.Exceljs -o dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CSBiology/FsSpreadsheet.git"
},
"author": "",
"author": "Kevin Frey",
"contributors": [ "Heinrich Lukas Weil", "Oliver Maus", "Kevin Schneider", "Timo Mühlhaus" ],
"license": "MIT",
"bugs": {
"url": "https://github.com/CSBiology/FsSpreadsheet/issues"
Expand All @@ -28,6 +33,6 @@
"mocha": "^10.2.0"
},
"dependencies": {
"exceljs": "^4.3.0"
"@nfdi4plants/exceljs": "0.1.0"
}
}
16 changes: 8 additions & 8 deletions src/FsSpreadsheet.Exceljs/FsExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ type FsWorkbook with
static member fromXlsxFile(path:string) : Promise<FsWorkbook> =
Xlsx.fromXlsxFile(path)

static member fromXlsxStream(stream:System.IO.Stream) : Async<FsWorkbook> =
static member fromXlsxStream(stream:System.IO.Stream) : Promise<FsWorkbook> =
Xlsx.fromXlsxStream stream

static member fromBytes(bytes: byte []) : Async<FsWorkbook> =
static member fromBytes(bytes: byte []) : Promise<FsWorkbook> =
Xlsx.fromBytes bytes

static member toFile(path: string) (wb:FsWorkbook) : Async<unit> =
static member toFile(path: string) (wb:FsWorkbook) : Promise<unit> =
Xlsx.toFile path wb

static member toStream(stream: System.IO.Stream) (wb:FsWorkbook) : Async<unit> =
static member toStream(stream: System.IO.Stream) (wb:FsWorkbook) : Promise<unit> =
Xlsx.toStream stream wb

static member toBytes(wb:FsWorkbook) : Async<byte []> =
static member toBytes(wb:FsWorkbook) : Promise<byte []> =
Xlsx.toBytes wb

member this.ToFile(path: string) : Async<unit> =
member this.ToFile(path: string) : Promise<unit> =
FsWorkbook.toFile path this

member this.ToStream(stream: System.IO.Stream) : Async<unit> =
member this.ToStream(stream: System.IO.Stream) : Promise<unit> =
FsWorkbook.toStream stream this

member this.ToBytes() : Async<byte []> =
member this.ToBytes() : Promise<byte []> =
FsWorkbook.toBytes this
4 changes: 2 additions & 2 deletions src/FsSpreadsheet.Exceljs/FsSpreadsheet.Exceljs.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fable.Exceljs" Version="1.3.6" />
<PackageReference Include="Fable.Exceljs" Version="1.6.0" />
<PackageReference Include="Fable.Promise" Version="3.2.0" />
</ItemGroup>

Expand All @@ -45,7 +45,7 @@

<PropertyGroup>
<NpmDependencies>
<NpmPackage Name="exceljs" Version="gte 4.3.0 lt 5.0.0" ResolutionStrategy="Max" />
<NpmPackage Name="@nfdi4plants/exceljs" Version="gte 0.1.0 lt 1.0.0" ResolutionStrategy="Max" />
</NpmDependencies>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/FsSpreadsheet.Exceljs/Workbook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
module JsWorkbook =
open FsSpreadsheet
open Fable.ExcelJs
open Fable.Core

[<Emit("console.log($0)")>]
let private log (obj:obj) = jsNative

let toFsWorkbook (jswb: Workbook) =
let fswb = new FsWorkbook()
for jsws in jswb.worksheets do
Expand Down
18 changes: 9 additions & 9 deletions src/FsSpreadsheet.Exceljs/Xlsx.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ type Xlsx =
static member fromXlsxFile (path:string) : Promise<FsWorkbook> =
promise {
let wb = ExcelJs.Excel.Workbook()
do! wb.xlsx.readFile(path) |> Async.StartAsPromise
do! wb.xlsx.readFile(path)
let fswb = JsWorkbook.toFsWorkbook wb
return fswb
}

static member fromXlsxStream (stream:System.IO.Stream) : Async<FsWorkbook> =
async {
static member fromXlsxStream (stream:System.IO.Stream) : Promise<FsWorkbook> =
promise {
let wb = ExcelJs.Excel.Workbook()
do! wb.xlsx.read stream
return JsWorkbook.toFsWorkbook wb
}

static member fromBytes (bytes: byte []) : Async<FsWorkbook> =
async {
static member fromBytes (bytes: byte []) : Promise<FsWorkbook> =
promise {
let wb = ExcelJs.Excel.Workbook()
let uint8 = Fable.Core.JS.Constructors.Uint8Array.Create bytes
do! wb.xlsx.load(uint8.buffer)
return JsWorkbook.toFsWorkbook wb
}

static member toFile (path: string) (wb:FsWorkbook) : Async<unit> =
static member toFile (path: string) (wb:FsWorkbook) : Promise<unit> =
let jswb = JsWorkbook.toJsWorkbook wb
jswb.xlsx.writeFile(path)

static member toStream (stream: System.IO.Stream) (wb:FsWorkbook) : Async<unit> =
static member toStream (stream: System.IO.Stream) (wb:FsWorkbook) : Promise<unit> =
let jswb = JsWorkbook.toJsWorkbook wb
jswb.xlsx.write(stream)

static member toBytes (wb:FsWorkbook) : Async<byte []> =
async {
static member toBytes (wb:FsWorkbook) : Promise<byte []> =
promise {
let jswb = JsWorkbook.toJsWorkbook wb
let buffer = jswb.xlsx.writeBuffer()
return !!buffer
Expand Down
12 changes: 12 additions & 0 deletions tests/FsSpreadsheet.Exceljs.Tests/Workbook.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,20 @@ let tests_toJsWorkbook = testList "toJsWorkbook" [
Expect.equal (table.ColumnCount()) 3 "column count"
]

open Fable.Core

let tests_xlsx = testList "xlsx" [
testList "read" [
testAsync "isa.assay.xlsx" {
let! fswb = Xlsx.fromXlsxFile("./tests/JS/TestFiles/isa.assay.xlsx") |> Async.AwaitPromise
Expect.equal (fswb.GetWorksheets().Count) 5 "Count"
}
]
]

let main = testList "JsWorkbook<->FsWorkbook" [
tests_toFsWorkbook
tests_toJsWorkbook
tests_xlsx
]

60 changes: 37 additions & 23 deletions tests/JS/Exceljs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { equal } from 'assert';
import { Xlsx } from './FsSpreadsheet.Exceljs/Xlsx.fs.js';
import { Excel } from './FsSpreadsheet.Exceljs/fable_modules/Fable.Exceljs.1.3.6/ExcelJs.fs.js';
import { FsWorkbook } from "./FsSpreadsheet.Exceljs/FsSpreadsheet/FsWorkbook.fs.js";
import { FsRangeAddress_$ctor_Z721C83C5, FsRangeAddress__get_Range } from "./FsSpreadsheet.Exceljs/FsSpreadsheet/Ranges/FsRangeAddress.fs.js";
import { FsTable } from "./FsSpreadsheet.Exceljs/FsSpreadsheet/Tables/FsTable.fs.js";
Expand All @@ -9,11 +8,8 @@ import { toJsWorkbook, toFsWorkbook } from "./FsSpreadsheet.Exceljs/Workbook.fs.
describe('FsSpreadsheet.Exceljs', function () {
describe('read', function () {
it('values', async () => {
//const wb = await Xlsx.fromXlsxFile(path)
const path = "tests/JS/TestFiles/ReadTable.xlsx"; // path always from package.json
const wb = new Excel.Workbook();
await wb.xlsx.readFile(path)
const fswb = toFsWorkbook(wb)
const fswb = await Xlsx.fromXlsxFile(path)
let worksheets = fswb.GetWorksheets()
equal(worksheets.length, 1)
let ws = worksheets[0]
Expand All @@ -32,11 +28,8 @@ describe('FsSpreadsheet.Exceljs', function () {
equal(ws.GetCellAt(7, 6).Value, "row20")
});
it('table', async () => {
//const wb = await Xlsx.fromXlsxFile(path)
const path = "tests/JS/TestFiles/ReadTable.xlsx";
const wb = new Excel.Workbook();
await wb.xlsx.readFile(path)
const fswb = toFsWorkbook(wb)
const fswb = await Xlsx.fromXlsxFile(path)
let worksheets = fswb.GetWorksheets()
equal(worksheets.length, 1)
let ws = worksheets[0]
Expand All @@ -46,11 +39,43 @@ describe('FsSpreadsheet.Exceljs', function () {
let table = ws.Tables[0]
equal(table.Name, "Table1")
});
it('isa.investigation.xlsx', async () => {
const path = "tests/JS/TestFiles/isa.investigation.xlsx";
const fswb = await Xlsx.fromXlsxFile(path)
let worksheets = fswb.GetWorksheets()
equal(worksheets.length, 1)
let ws = worksheets[0]
equal(ws.Name, "isa_investigation")
});
it('isa_assay_keineTables', async () => {
const path = "tests/JS/TestFiles/isa_assay_keineTables.xlsx";
const fswb = await Xlsx.fromXlsxFile(path)
let worksheets = fswb.GetWorksheets()
equal(worksheets.length, 1)
});
// TypeError: Cannot read properties of undefined (reading 'company')
//it('ClosedXml.Table', async () => {
// const path = "tests/JS/TestFiles/ClosedXml.Table.xlsx";
// const fswb = await Xlsx.fromXlsxFile(path)
// let worksheets = fswb.GetWorksheets()
// equal(worksheets.length, 1)
//});
it('fsspreadsheet.minimalTable', async () => {
const path = "tests/JS/TestFiles/fsspreadsheet.minimalTable.xlsx";
const fswb = await Xlsx.fromXlsxFile(path)
let worksheets = fswb.GetWorksheets()
equal(worksheets.length, 1)
});
it('isa.study.xlsx', async () => {
const path = "tests/JS/TestFiles/isa.study.xlsx";
const fswb = await Xlsx.fromXlsxFile(path)
let worksheets = fswb.GetWorksheets()
equal(worksheets.length, 5)
});
})
describe('write', function () {
it('roundabout', async () => {
const path = "tests/JS/TestFiles/WriteTable.xlsx"
const path2 = "tests/JS/TestFiles/WriteTable2.xlsx"
const fswb = new FsWorkbook();
const fsws = fswb.InitWorksheet("My Awesome Worksheet");
fsws.Row(1).Item(2).SetValueAs("My Column 1");
Expand All @@ -65,11 +90,8 @@ describe('FsSpreadsheet.Exceljs', function () {
const table = new FsTable("MyNewTable", FsRangeAddress_$ctor_Z721C83C5("B1:D3"));
fsws.AddTable(table);
fsws.RescanRows()
const jswb = toJsWorkbook(fswb)
await jswb.xlsx.writeFile(path);
let readjswb = new Excel.Workbook();
await readjswb.xlsx.readFile(path)
let readfswb = toFsWorkbook(readjswb)
await Xlsx.toFile(path, fswb)
const readfswb = await Xlsx.fromXlsxFile(path)
equal(readfswb.GetWorksheets().length, fswb.GetWorksheets().length)
equal(readfswb.GetWorksheets()[0].Name, "My Awesome Worksheet")
equal(readfswb.GetWorksheets()[0].Name, fswb.GetWorksheets()[0].Name)
Expand All @@ -79,14 +101,6 @@ describe('FsSpreadsheet.Exceljs', function () {
equal(readfswb.GetWorksheets()[0].GetCellAt(2,2).ValueAsFloat(), 2)
equal(readfswb.GetWorksheets()[0].GetCellAt(2,3).Value, "row2")
equal(readfswb.GetWorksheets()[0].GetCellAt(2,4).ValueAsBool(), true)
const readwritejswb = toJsWorkbook(readfswb)
await readwritejswb.xlsx.writeFile(path2);
})
// it('combined function', async () => {
// const path = "tests/JS/TestFiles/ReadTable.xlsx";
// console.log("start")
// const wb = await Xlsx.fromXlsxFile(path)
// console.log(wb)
// });
});
});
Binary file added tests/JS/TestFiles/ClosedXml.Table.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions tests/JS/TestFiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Never open these test files and save them with libre office or microsoft excel. They will automatically standardize the files to their favored format, making them all uniform and working with both OpenXml and Exceljs.
Binary file modified tests/JS/TestFiles/WriteTable.xlsx
Binary file not shown.
Binary file removed tests/JS/TestFiles/WriteTable2.xlsx
Binary file not shown.
Binary file not shown.
Binary file added tests/JS/TestFiles/isa.assay.xlsx
Binary file not shown.
Binary file added tests/JS/TestFiles/isa.investigation.xlsx
Binary file not shown.
Binary file added tests/JS/TestFiles/isa.study.xlsx
Binary file not shown.
Binary file added tests/JS/TestFiles/isa_assay_keineTables.xlsx
Binary file not shown.

0 comments on commit ec1b7c9

Please sign in to comment.