diff --git a/Cargo.lock b/Cargo.lock index 6be079e9..a503c5fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,7 +131,7 @@ dependencies = [ [[package]] name = "buildtools" -version = "0.1.0" +version = "0.7.0" dependencies = [ "gents", "logisheets_controller", @@ -737,7 +737,7 @@ dependencies = [ [[package]] name = "logisheets" -version = "0.6.0" +version = "0.7.0" dependencies = [ "glob", "logiscript", @@ -747,7 +747,7 @@ dependencies = [ [[package]] name = "logisheets_astchecker" -version = "0.6.0" +version = "0.7.0" dependencies = [ "logisheets_base", "logisheets_parser", @@ -755,7 +755,7 @@ dependencies = [ [[package]] name = "logisheets_base" -version = "0.6.0" +version = "0.7.0" dependencies = [ "chrono", "futures", @@ -769,7 +769,7 @@ dependencies = [ [[package]] name = "logisheets_controller" -version = "0.6.0" +version = "0.7.0" dependencies = [ "chrono", "colorsys", @@ -787,7 +787,7 @@ dependencies = [ "num", "num-bigint", "num-traits", - "quick-xml 0.28.2", + "quick-xml 0.31.0", "rand", "regex", "serde", @@ -800,7 +800,7 @@ dependencies = [ [[package]] name = "logisheets_formatter" -version = "0.1.0" +version = "0.7.0" dependencies = [ "lazy_static", "regex", @@ -808,7 +808,7 @@ dependencies = [ [[package]] name = "logisheets_lexer" -version = "0.6.0" +version = "0.7.0" dependencies = [ "pest", "pest_derive", @@ -817,7 +817,7 @@ dependencies = [ [[package]] name = "logisheets_parser" -version = "0.6.0" +version = "0.7.0" dependencies = [ "chrono", "lazy_static", @@ -858,7 +858,7 @@ dependencies = [ [[package]] name = "logisheets_wasm_server" -version = "0.3.0" +version = "0.7.0" dependencies = [ "console_error_panic_hook", "getrandom", @@ -877,7 +877,7 @@ dependencies = [ [[package]] name = "logisheets_workbook" -version = "0.6.0" +version = "0.7.0" dependencies = [ "gents", "gents_derives", @@ -894,7 +894,7 @@ dependencies = [ [[package]] name = "logisheets_workbook_derives" -version = "0.4.0" +version = "0.7.0" dependencies = [ "paste", "proc-macro2", @@ -1154,16 +1154,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quick-xml" -version = "0.28.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce5e73202a820a31f8a0ee32ada5e21029c81fd9e3ebf668a40832e4219d9d1" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "quick-xml" version = "0.31.0" @@ -1944,7 +1934,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" [[package]] name = "xmldiff" -version = "0.3.0" +version = "0.7.0" dependencies = [ "quick-xml 0.31.0", ] diff --git a/Cargo.toml b/Cargo.toml index 2edb4610..3da2e808 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,27 @@ [package] name = "logisheets" -version = "0.6.0" +version.workspace = true description = "A web spreadsheets application written in Rust and Typescript" keywords = ["excel", "spreadsheets", "ooxml", "logisheets", "xlsx"] readme = "README.md" repository = "https://github.com/logisky/LogiSheets" -license = "MIT" +license.workspace = true include = [ "crates/workbook/**/*", "crates/controller/**/*", "src/lib.rs", "Cargo.toml", ] -edition = "2018" +edition.workspace = true [workspace] members = [ "crates/buildtools", "crates/controller", + "crates/controller/ast_checker", + "crates/controller/base", + "crates/controller/lexer", + "crates/controller/parser", "crates/formatter", "crates/logiscript", "crates/sequencer", @@ -27,10 +31,42 @@ members = [ "crates/xmldiff", ] +[workspace.package] +version = "0.7.0" +authors = ["JeremyHe "] +license = "MIT" +edition = "2018" + +[workspace.dependencies] +chrono = "0.4" +futures = "0.3" +gents = "0.8" +gents_derives = "0.8" +getrandom = "0.2" +im = "15.0" +lazy_static = "1.4" +pest = "2.7" +pest_derive = "2.5" +quick-xml = "0.31" +regex = "1" +serde = "1" +serde_json = "1" +thiserror = "1.0" +xmlserde = "0.10" +xmlserde_derives = "0.10" + +logisheets_lexer = { path = "crates/controller/lexer", version = "0.7.0" } +logisheets_parser = { path = "crates/controller/parser", version = "0.7.0" } +logisheets_base = { path = "crates/controller/base", version = "0.7.0" } +logisheets_controller = { path = "crates/controller", version = "0.7.0" } + +logisheets_workbook_derives = { path = "crates/workbook/derives", version = "0.7.0" } +logisheets_workbook = { path = "crates/workbook", version = "0.7.0" } + [dependencies] -logisheets_controller = {path = "crates/controller", version = "0.6.0"} -logisheets_workbook = {path = "crates/workbook", version = "0.6.0"} +logisheets_controller = { workspace = true } +logisheets_workbook = { workspace = true } [dev-dependencies] glob = "0.3.1" -logiscript = {path = "crates/logiscript", version = "0.1.0"} +logiscript = { path = "crates/logiscript" } diff --git a/crates/buildtools/Cargo.toml b/crates/buildtools/Cargo.toml index 7de38c20..ea942560 100644 --- a/crates/buildtools/Cargo.toml +++ b/crates/buildtools/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "buildtools" -version = "0.1.0" -edition = "2018" -authors = ["ImJeremyHe"] +version.workspace = true +edition.workspace = true +authors.workspace = true [dependencies] -gents = "0.8.0" +gents = { workspace = true } -logisheets_controller = {path = "../controller", features = ["gents"]} -logisheets_sequencer = {path = "../sequencer", features = ["gents"]} +logisheets_controller = { path = "../controller", features = ["gents"] } +logisheets_sequencer = { path = "../sequencer", features = ["gents"] } [[bin]] name = "generate" diff --git a/crates/controller/Cargo.toml b/crates/controller/Cargo.toml index 43bad344..2bd86231 100644 --- a/crates/controller/Cargo.toml +++ b/crates/controller/Cargo.toml @@ -1,39 +1,41 @@ [package] name = "logisheets_controller" -version = "0.6.0" +version.workspace = true +license.workspace = true +authors.workspace = true description = "the core of LogiSheets" -authors = ["ImJeremyHe"] -edition = "2018" -license = "MIT" +edition.workspace = true [dependencies] -thiserror = "1.0.48" -chrono = "0.4.26" +thiserror = { workspace = true } +chrono = { workspace = true } futures = "0.3.19" colorsys = "0.6.7" -im = "15.0.0" +im = { workspace = true } itertools = "0.10.5" -lazy_static = "1.4.0" +lazy_static = { workspace = true } num = "0.4.0" num-bigint = "0.4" num-traits = "0.2" -quick-xml = {version = "0.28", features = ["serialize"]} +quick-xml = { workspace = true, features = ["serialize"] } rand = "0.8.4" -regex = "1" -serde = {version = "1.0.152", features = ["derive"]} +regex = { workspace = true } +serde = { workspace = true, features = ["derive"] } statrs = "0.16.1" unicode-segmentation = "1.10.1" wildescape = "0.1.0" -uuid ={ version = "1.4.1", features = ["v4", "fast-rng", "macro-diagnostics"]} +uuid = { version = "1.4.1", features = ["v4", "fast-rng", "macro-diagnostics"] } -logisheets_base = {version = "0.6.0", path = "./base", features = ["gents"]} -logisheets_lexer = {version = "0.6.0", path = "./lexer"} -logisheets_parser = {version = "0.6.0", path = "./parser"} -logisheets_workbook = {version = "0.6.0", path = "../workbook", features = ["gents"]} -logisheets_astchecker = {version = "0.6.0", path = "./ast_checker"} +logisheets_base = { path = "./base", features = ["gents"], version = "0.7.0" } +logisheets_lexer = { path = "./lexer", version = "0.7.0" } +logisheets_parser = { path = "./parser", version = "0.7.0" } +logisheets_workbook = { path = "../workbook", features = [ + "gents", +], version = "0.7.0" } +logisheets_astchecker = { path = "./ast_checker", version = "0.7.0" } -gents = {version = "0.8.0", optional = true} -gents_derives = {version = "0.8.0", optional = true} +gents = { workspace = true, optional = true } +gents_derives = { workspace = true, optional = true } [features] gents = ["dep:gents", "dep:gents_derives"] diff --git a/crates/controller/ast_checker/Cargo.toml b/crates/controller/ast_checker/Cargo.toml index bb4fd736..a6c1ba27 100644 --- a/crates/controller/ast_checker/Cargo.toml +++ b/crates/controller/ast_checker/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "logisheets_astchecker" -version = "0.6.0" -edition = "2018" description = "validate the arguments in ast" -authors = ["ImJeremyHe"] -license = "MIT" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] -logisheets_parser = {version = "0.6.0", path = "../parser"} -logisheets_base = {version = "0.6.0", path = "../base"} \ No newline at end of file +logisheets_parser = { workspace = true } +logisheets_base = { workspace = true } diff --git a/crates/controller/base/Cargo.toml b/crates/controller/base/Cargo.toml index 6d0479e1..7f9a2f1d 100644 --- a/crates/controller/base/Cargo.toml +++ b/crates/controller/base/Cargo.toml @@ -1,22 +1,22 @@ [package] name = "logisheets_base" -version = "0.6.0" description = "some basic definitions for LogiSheets" -authors = ["ImJeremyHe"] -license = "MIT" -edition = "2018" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true [dependencies] -chrono = "0.4.19" -futures = "0.3.19" -im = "15.0.0" -serde = {version = "1.0.125", features = ["derive"]} -thiserror = "1.0.48" +chrono = { workspace = true } +futures = { workspace = true } +im = { workspace = true } +serde = { workspace = true, features = ["derive"] } +thiserror = { workspace = true } -logisheets_workbook = {version = "0.6.0", path = "../../workbook"} +gents = { workspace = true, optional = true } +gents_derives = { workspace = true, optional = true } -gents = {version = "0.8.0", optional = true} -gents_derives = {version = "0.8.0", optional = true} +logisheets_workbook = { workspace = true } [features] gents = ["dep:gents", "dep:gents_derives"] diff --git a/crates/controller/lexer/Cargo.toml b/crates/controller/lexer/Cargo.toml index 8454b6f7..588246a9 100644 --- a/crates/controller/lexer/Cargo.toml +++ b/crates/controller/lexer/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "logisheets_lexer" -version = "0.6.0" -edition = "2018" description = "the lexer for excel formula" -authors = ["ImJeremyHe"] -license = "MIT" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] -pest = "2.1.3" -pest_derive = "2.1.0" +pest = { workspace = true } +pest_derive = { workspace = true } tracing = "0.1" diff --git a/crates/controller/parser/Cargo.toml b/crates/controller/parser/Cargo.toml index ff89c9e0..d4b3fd07 100644 --- a/crates/controller/parser/Cargo.toml +++ b/crates/controller/parser/Cargo.toml @@ -1,17 +1,18 @@ [package] name = "logisheets_parser" -version = "0.6.0" -edition = "2018" description = "the parser of excel formula" -authors = ["ImJeremyHe"] -license = "MIT" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true [dependencies] -thiserror = "1.0.48" -lazy_static = "1.4.0" -pest = "2.1.3" -pest_derive = "2.1.0" -chrono = "0.4.19" -regex = "1" -logisheets_lexer = {version = "0.6.0", path = "../lexer"} -logisheets_base = {version = "0.6.0", path = "../base"} +thiserror = { workspace = true } +lazy_static = { workspace = true } +pest = { workspace = true } +pest_derive = { workspace = true } +chrono = { workspace = true } +regex = { workspace = true } + +logisheets_lexer = { workspace = true } +logisheets_base = { workspace = true } diff --git a/crates/formatter/Cargo.toml b/crates/formatter/Cargo.toml index a2868ad3..48c95f24 100644 --- a/crates/formatter/Cargo.toml +++ b/crates/formatter/Cargo.toml @@ -1,10 +1,11 @@ [package] name = "logisheets_formatter" -edition = "2018" -version = "0.1.0" description = "LogiSheets Custom Number Formatter" -license = "MIT" +edition.workspace = true +version.workspace = true +license.workspace = true +authors.workspace = true [dependencies] -lazy_static = "1.4.0" -regex = "1" \ No newline at end of file +lazy_static = { workspace = true } +regex = { workspace = true } diff --git a/crates/logiscript/Cargo.toml b/crates/logiscript/Cargo.toml index 11bad59f..9dd09eae 100644 --- a/crates/logiscript/Cargo.toml +++ b/crates/logiscript/Cargo.toml @@ -1,13 +1,13 @@ [package] -authors = ["ImJeremyHe"] -edition = "2018" name = "logiscript" +authors.workspace = true +edition.workspace = true version = "0.1.0" description = "A simple script for building and testing LogiSheets" -license = "MIT" +license.workspace = true [dependencies] -pest = "2.7.0" -pest_derive = "2.5.6" +pest = { workspace = true } +pest_derive = { workspace = true } -logisheets_controller = {version = "*", path = "../controller"} +logisheets_controller = { workspace = true } diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index 164fb500..74629d44 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -1,23 +1,23 @@ [package] -authors = ["ImJeremyHe"] -edition = "2018" name = "logisheets_sequencer" version = "0.1.0" +edition.workspace = true +authors.workspace = true description = "A server that provides LogiSheets with the ability of users' online editting" -license = "MIT" +license.workspace = true [dependencies] async-channel = "1.9.0" async-trait = "0.1.52" -ezsockets = {version = "0.5.1"} -serde = {version = "1.0"} -serde_json = {version = "1.0"} -tokio = {version = "1.33"} +ezsockets = { version = "0.5.1" } +serde = { workspace = true } +serde_json = { workspace = true } +tokio = { version = "1.33" } -logisheets_controller = {version = "*", path = "../controller", features = ["sequencer"]} +logisheets_controller = { workspace = true, features = ["sequencer"] } -gents = {version = "0.8.0", optional = true} -gents_derives = {version = "0.8.0", optional = true} +gents = { workspace = true, optional = true } +gents_derives = { workspace = true, optional = true } [features] gents = ["dep:gents", "dep:gents_derives", "logisheets_controller/gents"] diff --git a/crates/wasms/fc/Cargo.toml b/crates/wasms/fc/Cargo.toml index 9c193a02..55c30c1f 100644 --- a/crates/wasms/fc/Cargo.toml +++ b/crates/wasms/fc/Cargo.toml @@ -11,13 +11,13 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -wasm-bindgen = {version = "0.2.84", features = ["serde-serialize"]} -web-sys = {version = "0.3.56", features = ["console"]} -console_error_panic_hook = {version = "0.1.6", optional = true} +wasm-bindgen = { version = "0.2.84", features = ["serde-serialize"] } +web-sys = { version = "0.3.56", features = ["console"] } +console_error_panic_hook = { version = "0.1.6", optional = true } # Specify the feature of the crate used in `logisheets_controller`. -getrandom = {version = "0.2.8", features = ["js"]} +getrandom = { workspace = true, features = ["js"] } -logisheets_controller = {version = "*", path = '../../../crates/controller'} +logisheets_controller = { workspace = true } [dev-dependencies] wasm-bindgen-test = "0.3.30" diff --git a/crates/wasms/server/Cargo.toml b/crates/wasms/server/Cargo.toml index d970328b..6cabbef4 100644 --- a/crates/wasms/server/Cargo.toml +++ b/crates/wasms/server/Cargo.toml @@ -1,8 +1,8 @@ [package] -authors = ["Jeremy He"] -edition = "2018" +authors.workspace = true +edition.workspace = true name = "logisheets_wasm_server" -version = "0.3.0" +version.workspace = true [lib] crate-type = ["cdylib", "rlib"] @@ -12,24 +12,24 @@ default = ["console_error_panic_hook"] [dependencies] singlyton = "4.1.1" -wasm-bindgen = {version = "0.2.84", features = ["serde-serialize"]} -web-sys = {version = "0.3.56", features = ["console"]} +wasm-bindgen = { version = "0.2.84", features = ["serde-serialize"] } +web-sys = { version = "0.3.56", features = ["console"] } # Specify the feature of the crate used in `logisheets_controller`. -getrandom = {version = "0.2.8", features = ["js"]} -serde = {version = "1.0", features = ["derive"]} -serde_json = "1.0" +getrandom = { workspace = true, features = ["js"] } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } serde-wasm-bindgen = "0.5" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # code size when deploying. -console_error_panic_hook = {version = "0.1.6", optional = true} +console_error_panic_hook = { version = "0.1.6", optional = true } -logisheets_controller = {version = "*", path = "../../controller", features = ["gents"]} -logisheets_base = {version = "*", path = "../../controller/base"} -logisheets_workbook = {version = "*", path = "../../workbook"} +logisheets_controller = { workspace = true, features = ["gents"] } +logisheets_base = { workspace = true } +logisheets_workbook = { workspace = true } -xmlserde = "0.10" +xmlserde = { workspace = true } [dev-dependencies] wasm-bindgen-test = "0.3.30" diff --git a/crates/workbook/Cargo.toml b/crates/workbook/Cargo.toml index 362660a8..7f240841 100644 --- a/crates/workbook/Cargo.toml +++ b/crates/workbook/Cargo.toml @@ -1,27 +1,26 @@ [package] -authors = ["ImJeremyHe"] -edition = "2018" name = "logisheets_workbook" -version = "0.6.0" -license = "MIT" description = "Tools for LogiSheets to unarchive and write .xlsx file" +authors.workspace = true +edition.workspace = true +version.workspace = true +license.workspace = true [dependencies] -regex = "1" -serde = {version = "1.0.152", features = ["derive"]} -serde_json = "1.0.95" -thiserror = "1.0.48" -zip = {version = "0.6.0", default-features = false, features = ["deflate"]} +regex = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +thiserror = { workspace = true } +zip = { version = "0.6.0", default-features = false, features = ["deflate"] } +gents = { workspace = true, optional = true } +gents_derives = { workspace = true, optional = true } +xmlserde = { workspace = true } +xmlserde_derives = { workspace = true } -logisheets_workbook_derives = {version = "0.4.0", path = "./derives"} - -xmlserde = "0.10" -xmlserde_derives = "0.10" -gents = {version = "0.8.0", optional = true} -gents_derives = {version = "0.8.0", optional = true} +logisheets_workbook_derives = { workspace = true } [dev-dependencies] -xmldiff = {version = "0.3.0", path = "../xmldiff"} +xmldiff = { version = "*", path = "../xmldiff" } [features] gents = ["dep:gents", "dep:gents_derives"] diff --git a/crates/workbook/derives/Cargo.toml b/crates/workbook/derives/Cargo.toml index 17be74cb..dcb171b9 100644 --- a/crates/workbook/derives/Cargo.toml +++ b/crates/workbook/derives/Cargo.toml @@ -1,16 +1,16 @@ [package] name = "logisheets_workbook_derives" -version = "0.4.0" description = "macros that help LogiSheets serde the xml files" -authors = ["ImJeremyHe"] -license = "MIT" -edition = "2018" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true [lib] proc-macro = true [dependencies] -syn = {version = "1.0.86", features = ["full"]} +syn = { version = "1.0.86", features = ["full"] } quote = "1.0.15" paste = "1.0.12" proc-macro2 = "1.0.36" diff --git a/crates/xmldiff/Cargo.toml b/crates/xmldiff/Cargo.toml index bbdc4f42..1eda51bb 100644 --- a/crates/xmldiff/Cargo.toml +++ b/crates/xmldiff/Cargo.toml @@ -1,11 +1,11 @@ [package] -authors = ["ImJeremyHe"] -edition = "2018" name = "xmldiff" -version = "0.3.0" -license = "MIT" +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true description = "compare 2 .xml files and show their differences" repository = "https://github.com/logisky/LogiSheets/crates/xmldiff" [dependencies] -quick-xml = { version = "0.31", features = ["serialize"] } +quick-xml = { workspace = true, features = ["serialize"] } diff --git a/resources/funcs/README.md b/resources/funcs/README.md index 7afb6adb..89a9b8a6 100644 --- a/resources/funcs/README.md +++ b/resources/funcs/README.md @@ -1,39 +1,37 @@ # Function Signatures -Used in formula arguments check and intellisense. +Used for formula argument validation and IntelliSense. -## Spec +## Specification -We use `JSON` to describe a function signature. -This `JSON` object has these fields: +We use `JSON` format to describe a function signature. The `JSON` object includes the following fields: -- name: The function's name in upper case -- argCount: Valid count of args -- args: Describe properties of each argument. -- description +- **name**: The function's name in uppercase. +- **argCount**: Constraints on the number of arguments. +- **args**: Describes the properties of each argument. +- **description**: A description of the function. ### argCount -`argCount` is an object having these fields: - -- le: arg count must be less or equal than the value -- ge: arg count must be greater or equal than the value -- eq: arg count must be equal to the value -- odd: arg count must be odd -- even: arg count must be even +`argCount` is an object that defines constraints on the number of arguments. It includes the following fields: +- **le**: The argument count must be less than or equal to this value. +- **ge**: The argument count must be greater than or equal to this value. +- **eq**: The argument count must be equal to this value. +- **odd**: The argument count must be odd. +- **even**: The argument count must be even. ### args -`args` is a list of object. Each object has these fields: - -- argName -- refOnly - - type: Boolean - - default: false - - description: If this is true, it means this argument only accept **A1** or **A1:B2**, default false. -- startRepeated - - type: Boolean - - default: false - - description: If this is true, it means that this argument and those after it makes a group that can be repeated for multiple times. -- description \ No newline at end of file +`args` is a list of objects, each describing an argument's properties. Each object includes the following fields: + +- **argName**: The name of the argument. +- **refOnly**: + - **type**: Boolean. + - **default**: `false`. + - **description**: If `true`, this argument only accepts references like **A1** or **A1:B2**. Default is `false`. +- **startRepeated**: + - **type**: Boolean. + - **default**: `false`. + - **description**: If `true`, this argument and subsequent ones form a group that can be repeated multiple times. +- **description**: A description of the argument. diff --git a/scripts/index.ts b/scripts/index.ts index 67d6b889..aeecdef7 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -13,10 +13,10 @@ const plugins = [ ], }, globOptions: { - nosort: true - } + nosort: true, + }, }), ] -plugins.forEach(plugin => { +plugins.forEach((plugin) => { plugin.apply() -}) \ No newline at end of file +}) diff --git a/scripts/merge-jsons/index.ts b/scripts/merge-jsons/index.ts index 3e981dc7..1a671c6d 100644 --- a/scripts/merge-jsons/index.ts +++ b/scripts/merge-jsons/index.ts @@ -20,12 +20,12 @@ interface OutputFile { } /** - * + * * Files to merge, and output path. */ interface IMergeJsonFiles { - files: string[]; - outputPath: string; + files: string[] + outputPath: string } interface Options { debug?: boolean @@ -43,18 +43,20 @@ export class MergeJsonWebpackPlugin { logger: Logger constructor(options: Options) { - this.options = Object.assign({ - debug: false, - encoding: UTF8_ENCODING, - overwrite: true, - mergeToArray: false, - cwd: process.cwd(), - }, options) + this.options = Object.assign( + { + debug: false, + encoding: UTF8_ENCODING, + overwrite: true, + mergeToArray: false, + cwd: process.cwd(), + }, + options + ) this.logger = new Logger(this.options.debug) this.logger.debug(JSON.stringify(this.options, undefined, 2)) } - /** * Extract files from the input options. * It can be either string or pattern. @@ -69,32 +71,30 @@ export class MergeJsonWebpackPlugin { // check if groupby if (groupBy) { - const defaultGlobOptions = { mark: true, cwd: this.options.cwd } + const defaultGlobOptions = {mark: true, cwd: this.options.cwd} // glob option - const globOptions = { ...defaultGlobOptions, ...this.options.globOptions } + const globOptions = { + ...defaultGlobOptions, + ...this.options.globOptions, + } // extract files groupBy.map((g) => { - const { pattern, fileName } = g + const {pattern, fileName} = g const files = glob.sync(pattern, globOptions) - filesToProcess.push( - { - files, - outputPath: fileName - } - ) + filesToProcess.push({ + files, + outputPath: fileName, + }) }) } else if (files) { - filesToProcess.push( - { - files, - outputPath: this.options.output?.fileName - } - ) + filesToProcess.push({ + files, + outputPath: this.options.output?.fileName, + }) } return filesToProcess } - apply() { this.logger.debug('Running apply() ::::::') const fileList: Array = this.getFileToProcess() @@ -102,26 +102,26 @@ export class MergeJsonWebpackPlugin { for (const opt of fileList) { this.processFiles(opt) } - } /** - * + * * @param compilation webpack compilation object. * @param files List of file names. * @param outputPath Output path to write merged json files. */ processFiles = (filesInfo: IMergeJsonFiles) => { const initValue = this.options.mergeToArray ? [] : {} - const mergedJSON = filesInfo.files.map(file => { - try { - const content = this.readContent(file) - return this.parseJson(file, content.toString()) - } catch (e) { - this.logger.error(e) - } - return {} - }) + const mergedJSON = filesInfo.files + .map((file) => { + try { + const content = this.readContent(file) as Buffer + return this.parseJson(file, content.toString()) + } catch (e) { + this.logger.error(e) + } + return {} + }) .reduce((acc, curr) => this.mergeDeep(acc, curr), initValue) this.logger.debug(JSON.stringify(mergedJSON), 'result json') // add assets to compilation. @@ -129,14 +129,15 @@ export class MergeJsonWebpackPlugin { const outputPathInfo = path.parse(filesInfo.outputPath) if (!fs.existsSync(outputPathInfo.dir)) fs.mkdirSync(outputPathInfo.dir, {recursive: true}) - fs.writeFileSync(filesInfo.outputPath, content, {encoding: this.options.encoding}) + fs.writeFileSync(filesInfo.outputPath, content, { + encoding: this.options.encoding, + }) } - /** * Reads a file from file system, if not found it will search in assets. - * @param compilation - * @param contextPath + * @param compilation + * @param contextPath * @param compilation fileName */ readContent = (fileName: string) => { @@ -152,18 +153,20 @@ export class MergeJsonWebpackPlugin { } /** - * - * @param fileName - * @param content + * + * @param fileName + * @param content */ parseJson(fileName: string, content: string) { if (!content) { - throw new Error(`Data appears to be empty in the file := [ ${fileName} ]`) + throw new Error( + `Data appears to be empty in the file := [ ${fileName} ]` + ) } // Source: https://github.com/sindresorhus/strip-bom/blob/master/index.js // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string // conversion translates it to FEFF (UTF-16 BOM) - if (content.charCodeAt(0) === 0xFEFF) { + if (content.charCodeAt(0) === 0xfeff) { content = content.slice(1) } // try to get a JSON object from the file data @@ -171,7 +174,7 @@ export class MergeJsonWebpackPlugin { // eslint-disable-next-line no-useless-catch try { const fileContent = JSON.parse(content) - //to prefix object with filename ,requirement as request in issue#31 + //to prefix object with filename ,requirement as request in issue#31 if (this.options.prefixFileName) { if (typeof this.options.prefixFileName === 'function') { json[this.options.prefixFileName(fileName)] = fileContent @@ -195,7 +198,11 @@ export class MergeJsonWebpackPlugin { * code contributed by @leonardopurro */ mergeDeep = (target, source) => { - if (Array.isArray(target) && typeof source === 'object' && this.options.mergeToArray) + if ( + Array.isArray(target) && + typeof source === 'object' && + this.options.mergeToArray + ) target.push(source) else if (typeof target == 'object' && typeof source == 'object') { for (const key in source) {