From f95e1517700b203d384b5ce6bf8535478c8d4b62 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Fri, 30 Jul 2021 02:29:56 +0800 Subject: [PATCH] v2.20.0 - fixed error handling, dropped CSON support, fixed crash when badges.config missing --- HISTORY.md | 10 ++ README.md | 2 +- package-lock.json | 194 ++++++++++------------- package.json | 12 +- source/bin.ts | 13 +- source/index.ts | 89 ++++------- source/install.ts | 1 - test-fixtures/out-expected/projectz.cson | 69 -------- test-fixtures/out-expected/projectz.json | 56 +++++++ test-fixtures/src/bower.json | 2 +- test-fixtures/src/component.json | 2 +- test-fixtures/src/package.json | 2 +- test-fixtures/src/projectz.cson | 69 -------- test-fixtures/src/projectz.json | 56 +++++++ 14 files changed, 258 insertions(+), 319 deletions(-) delete mode 100644 test-fixtures/out-expected/projectz.cson create mode 100644 test-fixtures/out-expected/projectz.json delete mode 100644 test-fixtures/src/projectz.cson create mode 100644 test-fixtures/src/projectz.json diff --git a/HISTORY.md b/HISTORY.md index 6088500a..9b82b753 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,15 @@ # History +## v2.20.0 2021 July 30 + +- Fixed fatal errors going unreported +- No longer support CSON for package files, JSON only. +- No longer outputs logging line info if `--verbose` is not present +- Better debugging for file and json reading, writing, and directory reading. +- Fixed missing `package.json:badges.config` from crashing the compile. +- `--debug` now tells you to use `--verbose` instead, rather than doing nothing. +- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation) + ## v2.19.0 2021 July 29 - Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation) diff --git a/README.md b/README.md index 902a00d7..b9d0e67c 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Projectz helps you maintain the following data files: It does this by reading them, combining their data in memory, and then outputting the appropriate fields and over-rides for each file. -If you are making use of multiple meta data files, you may find defining a projectz meta file (`projectz.json` for JSON, or `projectz.cson` for [CSON](https://github.com/bevry/cson)) to be useful. The projectz meta file can serve as a central location for the configuration of all the other files. However, if you only require one meta data file, then you can ignore this ability. +If you are making use of multiple meta data files, you may find defining a projectz meta file (`projectz.json` for JSON to be useful. The projectz meta file can serve as a central location for the configuration of all the other files. However, if you only require one meta data file, then you can ignore this ability. Projectz takes notes of these meta data fields: diff --git a/package-lock.json b/package-lock.json index 06d22462..f32eb2c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "projectz", - "version": "2.19.0", + "version": "2.20.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.19.0", + "version": "2.20.0", "license": "MIT", "dependencies": { + "@bevry/file": "^1.1.0", + "@bevry/json": "^1.4.0", "badges": "^4.26.0", - "caterpillar": "^6.6.0", - "cson-parser": "^4.0.9", - "errlop": "^4.2.0", + "caterpillar": "^6.7.0", "fellow": "^6.23.0", "get-cli-arg": "^7.1.0", "spdx-expression-parse": "^3.0.1", @@ -27,7 +27,7 @@ "@typescript-eslint/parser": "^4.28.5", "assert-helpers": "^8.2.0", "eslint": "^7.31.0", - "eslint-config-bevry": "^3.25.0", + "eslint-config-bevry": "^3.26.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^3.4.0", "filedirname": "^2.6.0", @@ -154,7 +154,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/@bevry/ansi/-/ansi-3.0.0.tgz", "integrity": "sha512-6jgJlOpitWyz2CMnXWg5aUGFFeo1Mc1JdLEY7FQeSdeI1XTurrax2+DRRv5FEOH2sPowH/TJJIrKSyqbWOBi7A==", - "dev": true, "dependencies": { "editions": "^6.1.0" }, @@ -165,6 +164,32 @@ "url": "https://bevry.me/fund" } }, + "node_modules/@bevry/file": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@bevry/file/-/file-1.1.0.tgz", + "integrity": "sha512-mDfnxj4PkROljUrEmWvcIxXL1KB/kjgWumNcFDjaghGbJnXaLYyp10GYHDbKgvOsjKQlRpLdO7zt5kLddNGI3Q==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://bevry.me/fund" + } + }, + "node_modules/@bevry/json": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@bevry/json/-/json-1.4.0.tgz", + "integrity": "sha512-0Z5m7IiXTuA1GiEBlsofvELILycQtiUfWe4arQMjmiXHPALgvg+3UxTRPBKoiJyOHAEio+8k6X7e6BGZz28OlQ==", + "dependencies": { + "@bevry/file": "^1.1.0", + "errlop": "^4.2.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://bevry.me/fund" + } + }, "node_modules/@bevry/update-contributors": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/@bevry/update-contributors/-/update-contributors-1.19.0.tgz", @@ -281,9 +306,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.4.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.6.tgz", - "integrity": "sha512-FKyawK3o5KL16AwbeFajen8G4K3mmqUrQsehn5wNKs8IzlKHE8TfnSmILXVMVziAEcnB23u1RCFU1NT6hSyr7Q==", + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.7.tgz", + "integrity": "sha512-aDDY54sst8sx47CWT6QQqIZp45yURq4dic0+HCYfYNcY5Ejlb/CLmFnRLfy3wQuYafOeh3lB/DAKaqRKBtcZmA==", "dev": true }, "node_modules/@types/rimraf": { @@ -822,14 +847,13 @@ "dev": true }, "node_modules/caterpillar": { - "version": "6.6.0", - "resolved": "https://registry.npmjs.org/caterpillar/-/caterpillar-6.6.0.tgz", - "integrity": "sha512-IWK7YOOURXf6ZB+8o9zZoj+5cwZmoKMjLkE0ec7iS6BOAJJ/UmfnvyTL2iYTYTS6dnsCvaFs/o258RVoRamG0Q==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/caterpillar/-/caterpillar-6.7.0.tgz", + "integrity": "sha512-siVqKWwA1yEf5f3J+fh1jukp7ERv72ejo7HqAd4LfiQQFU4L70Jn26SvVDkvHUeyN74Ykx5dFxgYVoiEhep+nw==", "dependencies": { - "@bevry/ansi": "^2.1.0", - "editions": "^6.0.0", - "get-current-line": "^6.2.0", - "rfc-log-levels": "^3.14.0" + "@bevry/ansi": "^3.0.0", + "get-current-line": "^6.5.0", + "rfc-log-levels": "^3.16.0" }, "engines": { "node": ">=10" @@ -838,17 +862,6 @@ "url": "https://bevry.me/fund" } }, - "node_modules/caterpillar/node_modules/@bevry/ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@bevry/ansi/-/ansi-2.1.0.tgz", - "integrity": "sha512-jkTQzUdapAkusrgZUAOS2vBoUO5Taz+8hzaOrzj7e7XlUDfUZtygS6K8Ou0xkdb59OSL2IAnO6FEx4rTRAPSnQ==", - "engines": { - "node": ">=4" - }, - "funding": { - "url": "https://bevry.me/fund" - } - }, "node_modules/chalk": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz", @@ -905,18 +918,6 @@ "integrity": "sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw==", "dev": true }, - "node_modules/coffeescript": { - "version": "1.12.7", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.12.7.tgz", - "integrity": "sha512-pLXHFxQMPklVoEekowk8b3erNynC+DVJzChxS/LCBBgR6/8AJkHivkm//zbowcfc7BTCAjryuhx6gPqPRfsFoA==", - "bin": { - "cake": "bin/cake", - "coffee": "bin/coffee" - }, - "engines": { - "node": ">=0.8.0" - } - }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -991,17 +992,6 @@ "node": ">= 8" } }, - "node_modules/cson-parser": { - "version": "4.0.9", - "resolved": "https://registry.npmjs.org/cson-parser/-/cson-parser-4.0.9.tgz", - "integrity": "sha512-I79SAcCYquWnEfXYj8hBqOOWKj6eH6zX1hhX3yqmS4K3bYp7jME3UFpHPzu3rUew0oyfc0s8T6IlWGXRAheHag==", - "dependencies": { - "coffeescript": "1.12.7" - }, - "engines": { - "node": ">=10.13" - } - }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -1220,9 +1210,9 @@ } }, "node_modules/eslint-config-bevry": { - "version": "3.25.0", - "resolved": "https://registry.npmjs.org/eslint-config-bevry/-/eslint-config-bevry-3.25.0.tgz", - "integrity": "sha512-KSLmsapqtJEBBc30tni60QGIX2X3RT4B4q0sRGDttdBvQuln8D+LUj457yT/dwJu7uZI1FjpvcgBaqndb+QVoQ==", + "version": "3.26.0", + "resolved": "https://registry.npmjs.org/eslint-config-bevry/-/eslint-config-bevry-3.26.0.tgz", + "integrity": "sha512-tnWhFx0rW19euIxjB75AIM3OFAYV+433Ae7qPb5eMHAmkRf66GSkJ2B4wUkTkG55bxErvDItR2mw07jOdRy25A==", "dev": true, "dependencies": { "semver": "^7.3.5" @@ -1664,9 +1654,9 @@ } }, "node_modules/flatted": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.1.tgz", - "integrity": "sha512-OMQjaErSFHmHqZe+PSidH5n8j3O0F2DdnVh8JB4j4eUQ2k6KvB0qGfrKIhapvez5JerBbmWkaLYUYWISaESoXg==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.2.tgz", + "integrity": "sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==", "dev": true }, "node_modules/forever-agent": { @@ -2550,9 +2540,9 @@ "dev": true }, "node_modules/native-promise-pool": { - "version": "3.17.0", - "resolved": "https://registry.npmjs.org/native-promise-pool/-/native-promise-pool-3.17.0.tgz", - "integrity": "sha512-Sj9x8BjjJTkdsDQyv4bYZYeBkcl+aDVY6/tXwpkRMQO/pRQ6U0p1/+vodqTdjgGZgYN2N5c7bmZSlfTebpJXTQ==", + "version": "3.18.0", + "resolved": "https://registry.npmjs.org/native-promise-pool/-/native-promise-pool-3.18.0.tgz", + "integrity": "sha512-+nfrjyfjwthhXiX7louIJPivTPwkFAjIgB5zBgbl8CZFY1OrWX+8hauW9YjzBdRH0GFSShXP+pDVG5H8VsnIdA==", "dev": true, "engines": { "node": ">=10" @@ -2858,9 +2848,9 @@ } }, "node_modules/readdir-cluster": { - "version": "3.15.0", - "resolved": "https://registry.npmjs.org/readdir-cluster/-/readdir-cluster-3.15.0.tgz", - "integrity": "sha512-pRzvJ1e0vjin9VtnQI69PhpAMnqp5TOuf+KhggvwLdGLnTnauH2hqB8Gd9lnyALoMux8pb8qfokzAKkbp19tZA==", + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/readdir-cluster/-/readdir-cluster-3.16.0.tgz", + "integrity": "sha512-xBCM2uXoc72YzjTMVR6QwoqfHhXXJdAjUDYHvUnB03fAruyfPPlbiYANWFemV/tFeqeQ9s6+5TB3LpeLeeThpg==", "dev": true, "engines": { "node": ">=10" @@ -3924,11 +3914,24 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/@bevry/ansi/-/ansi-3.0.0.tgz", "integrity": "sha512-6jgJlOpitWyz2CMnXWg5aUGFFeo1Mc1JdLEY7FQeSdeI1XTurrax2+DRRv5FEOH2sPowH/TJJIrKSyqbWOBi7A==", - "dev": true, "requires": { "editions": "^6.1.0" } }, + "@bevry/file": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@bevry/file/-/file-1.1.0.tgz", + "integrity": "sha512-mDfnxj4PkROljUrEmWvcIxXL1KB/kjgWumNcFDjaghGbJnXaLYyp10GYHDbKgvOsjKQlRpLdO7zt5kLddNGI3Q==" + }, + "@bevry/json": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@bevry/json/-/json-1.4.0.tgz", + "integrity": "sha512-0Z5m7IiXTuA1GiEBlsofvELILycQtiUfWe4arQMjmiXHPALgvg+3UxTRPBKoiJyOHAEio+8k6X7e6BGZz28OlQ==", + "requires": { + "@bevry/file": "^1.1.0", + "errlop": "^4.2.0" + } + }, "@bevry/update-contributors": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/@bevry/update-contributors/-/update-contributors-1.19.0.tgz", @@ -4021,9 +4024,9 @@ "dev": true }, "@types/node": { - "version": "16.4.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.6.tgz", - "integrity": "sha512-FKyawK3o5KL16AwbeFajen8G4K3mmqUrQsehn5wNKs8IzlKHE8TfnSmILXVMVziAEcnB23u1RCFU1NT6hSyr7Q==", + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.7.tgz", + "integrity": "sha512-aDDY54sst8sx47CWT6QQqIZp45yURq4dic0+HCYfYNcY5Ejlb/CLmFnRLfy3wQuYafOeh3lB/DAKaqRKBtcZmA==", "dev": true }, "@types/rimraf": { @@ -4375,21 +4378,13 @@ "dev": true }, "caterpillar": { - "version": "6.6.0", - "resolved": "https://registry.npmjs.org/caterpillar/-/caterpillar-6.6.0.tgz", - "integrity": "sha512-IWK7YOOURXf6ZB+8o9zZoj+5cwZmoKMjLkE0ec7iS6BOAJJ/UmfnvyTL2iYTYTS6dnsCvaFs/o258RVoRamG0Q==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/caterpillar/-/caterpillar-6.7.0.tgz", + "integrity": "sha512-siVqKWwA1yEf5f3J+fh1jukp7ERv72ejo7HqAd4LfiQQFU4L70Jn26SvVDkvHUeyN74Ykx5dFxgYVoiEhep+nw==", "requires": { - "@bevry/ansi": "^2.1.0", - "editions": "^6.0.0", - "get-current-line": "^6.2.0", - "rfc-log-levels": "^3.14.0" - }, - "dependencies": { - "@bevry/ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@bevry/ansi/-/ansi-2.1.0.tgz", - "integrity": "sha512-jkTQzUdapAkusrgZUAOS2vBoUO5Taz+8hzaOrzj7e7XlUDfUZtygS6K8Ou0xkdb59OSL2IAnO6FEx4rTRAPSnQ==" - } + "@bevry/ansi": "^3.0.0", + "get-current-line": "^6.5.0", + "rfc-log-levels": "^3.16.0" } }, "chalk": { @@ -4434,11 +4429,6 @@ "integrity": "sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw==", "dev": true }, - "coffeescript": { - "version": "1.12.7", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.12.7.tgz", - "integrity": "sha512-pLXHFxQMPklVoEekowk8b3erNynC+DVJzChxS/LCBBgR6/8AJkHivkm//zbowcfc7BTCAjryuhx6gPqPRfsFoA==" - }, "color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -4501,14 +4491,6 @@ "which": "^2.0.1" } }, - "cson-parser": { - "version": "4.0.9", - "resolved": "https://registry.npmjs.org/cson-parser/-/cson-parser-4.0.9.tgz", - "integrity": "sha512-I79SAcCYquWnEfXYj8hBqOOWKj6eH6zX1hhX3yqmS4K3bYp7jME3UFpHPzu3rUew0oyfc0s8T6IlWGXRAheHag==", - "requires": { - "coffeescript": "1.12.7" - } - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -4686,9 +4668,9 @@ } }, "eslint-config-bevry": { - "version": "3.25.0", - "resolved": "https://registry.npmjs.org/eslint-config-bevry/-/eslint-config-bevry-3.25.0.tgz", - "integrity": "sha512-KSLmsapqtJEBBc30tni60QGIX2X3RT4B4q0sRGDttdBvQuln8D+LUj457yT/dwJu7uZI1FjpvcgBaqndb+QVoQ==", + "version": "3.26.0", + "resolved": "https://registry.npmjs.org/eslint-config-bevry/-/eslint-config-bevry-3.26.0.tgz", + "integrity": "sha512-tnWhFx0rW19euIxjB75AIM3OFAYV+433Ae7qPb5eMHAmkRf66GSkJ2B4wUkTkG55bxErvDItR2mw07jOdRy25A==", "dev": true, "requires": { "semver": "^7.3.5" @@ -4984,9 +4966,9 @@ } }, "flatted": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.1.tgz", - "integrity": "sha512-OMQjaErSFHmHqZe+PSidH5n8j3O0F2DdnVh8JB4j4eUQ2k6KvB0qGfrKIhapvez5JerBbmWkaLYUYWISaESoXg==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.2.tgz", + "integrity": "sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==", "dev": true }, "forever-agent": { @@ -5658,9 +5640,9 @@ "dev": true }, "native-promise-pool": { - "version": "3.17.0", - "resolved": "https://registry.npmjs.org/native-promise-pool/-/native-promise-pool-3.17.0.tgz", - "integrity": "sha512-Sj9x8BjjJTkdsDQyv4bYZYeBkcl+aDVY6/tXwpkRMQO/pRQ6U0p1/+vodqTdjgGZgYN2N5c7bmZSlfTebpJXTQ==", + "version": "3.18.0", + "resolved": "https://registry.npmjs.org/native-promise-pool/-/native-promise-pool-3.18.0.tgz", + "integrity": "sha512-+nfrjyfjwthhXiX7louIJPivTPwkFAjIgB5zBgbl8CZFY1OrWX+8hauW9YjzBdRH0GFSShXP+pDVG5H8VsnIdA==", "dev": true }, "natural-compare": { @@ -5879,9 +5861,9 @@ } }, "readdir-cluster": { - "version": "3.15.0", - "resolved": "https://registry.npmjs.org/readdir-cluster/-/readdir-cluster-3.15.0.tgz", - "integrity": "sha512-pRzvJ1e0vjin9VtnQI69PhpAMnqp5TOuf+KhggvwLdGLnTnauH2hqB8Gd9lnyALoMux8pb8qfokzAKkbp19tZA==", + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/readdir-cluster/-/readdir-cluster-3.16.0.tgz", + "integrity": "sha512-xBCM2uXoc72YzjTMVR6QwoqfHhXXJdAjUDYHvUnB03fAruyfPPlbiYANWFemV/tFeqeQ9s6+5TB3LpeLeeThpg==", "dev": true }, "regexpp": { diff --git a/package.json b/package.json index 1d5ef85d..4563c39c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "title": "Projectz", "name": "projectz", - "version": "2.19.0", + "version": "2.20.0", "description": "Stop wasting time syncing and updating your project's README and Package Files!", "homepage": "https://github.com/bevry/projectz", "license": "MIT", @@ -149,10 +149,10 @@ } }, "dependencies": { + "@bevry/file": "^1.1.0", + "@bevry/json": "^1.4.0", "badges": "^4.26.0", - "caterpillar": "^6.6.0", - "cson-parser": "^4.0.9", - "errlop": "^4.2.0", + "caterpillar": "^6.7.0", "fellow": "^6.23.0", "get-cli-arg": "^7.1.0", "spdx-expression-parse": "^3.0.1", @@ -165,7 +165,7 @@ "@typescript-eslint/parser": "^4.28.5", "assert-helpers": "^8.2.0", "eslint": "^7.31.0", - "eslint-config-bevry": "^3.25.0", + "eslint-config-bevry": "^3.26.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^3.4.0", "filedirname": "^2.6.0", @@ -218,4 +218,4 @@ "boundation": { "desiredNodeOnly": true } -} +} \ No newline at end of file diff --git a/source/bin.ts b/source/bin.ts index 9404f39f..6f3488f3 100755 --- a/source/bin.ts +++ b/source/bin.ts @@ -24,9 +24,9 @@ async function main(): Promise { ) return process.exit(1) } - if (process.argv.includes('-d')) { + if (process.argv.includes('-d') || process.argv.includes('--debug')) { console.log( - 'projecz now requires -d argument to be specifie via --verbose' + 'projecz now requires -d argument to be specified via --verbose' ) return process.exit(1) } @@ -35,7 +35,7 @@ async function main(): Promise { const level = d ? 7 : 6 // Setup our logging - const logger = new Logger({ lineLevel: level }) + const logger = new Logger({ lineLevel: d ? level : -Infinity }) const filter = new Filter({ filterLevel: level }) const human = new Human() @@ -50,12 +50,13 @@ async function main(): Promise { }) await project.compile() } catch (err) { - // error - logger.log('err', err.stack) + // fatal + // do not use logger.log, as if a fatal error happened, it won't output it + console.error(err.stack || err) return process.exit(1) } - // Done + // done logger.log('info', 'Completed successfully') } else { // output help diff --git a/source/index.ts b/source/index.ts index 21e75a89..dd7c9aa3 100644 --- a/source/index.ts +++ b/source/index.ts @@ -4,15 +4,11 @@ // First we need to import the libraries we require. // Load in the file system libraries -import { promises as fsPromises } from 'fs' -const { readdir, readFile, writeFile } = fsPromises +import { readFile, readDirectory, writeFile } from '@bevry/file' import { resolve, join, dirname } from 'path' -// Errlop used for wrapping errors -import Errlop from 'errlop' - -// CSON is used for loading in our configuration files -import { parse as parseCSON } from 'cson-parser' +// Handle configuration files +import { readJSON, writeJSON } from '@bevry/json' // [TypeChecker](https://github.com/bevry/typechecker) is used for checking data types import { isString, isPlainObject, isEmptyPlainObject } from 'typechecker' @@ -54,16 +50,6 @@ import type { EnhancedReadmesData, } from './types.js' -async function parseFile(path: string): Promise { - try { - const str = await readFile(path, 'utf-8') - const data = parseCSON(str) - return data - } catch (err) { - return Promise.reject(new Errlop(`failed parsing the file: ${path}`, err)) - } -} - interface Options { /** the directory that we wish to do our work on, defaults to `process.cwd()` */ cwd?: string @@ -112,6 +98,7 @@ export class Projectz { constructor(opts: Options) { this.cwd = opts.cwd ? resolve(opts.cwd) : process.cwd() if (opts.log) this.log = opts.log + // this.log = console.log.bind(console) } /** Compile the project */ @@ -138,7 +125,7 @@ export class Projectz { const ReadmeFiles = Object.keys(this.filenamesForReadmeFiles) // Load - const files = await readdir(this.cwd) + const files = await readDirectory(this.cwd) for (const file of files) { const filePath = join(this.cwd, file) @@ -146,7 +133,7 @@ export class Projectz { const basename = file.toLowerCase().split('.').slice(0, -1).join('.') if (basename === key) { this.log('info', `Reading package file: ${filePath}`) - const data = await parseFile>(filePath) + const data = await readJSON>(filePath) this.filenamesForPackageFiles[key] = file this.dataForPackageFiles[key] = data } @@ -155,7 +142,7 @@ export class Projectz { for (const key of ReadmeFiles) { if (file.toLowerCase().startsWith(key)) { this.log('info', `Reading meta file: ${filePath}`) - const data = await readFile(filePath, 'utf-8') + const data = await readFile(filePath) this.filenamesForReadmeFiles[key] = file this.dataForReadmeFiles[key] = data.toString() } @@ -168,6 +155,8 @@ export class Projectz { // ---------------------------------- // Combine + this.log('debug', 'Enhancing packages data') + // Combine the package data const mergedPackagesData: any = { keywords: [], @@ -193,50 +182,40 @@ export class Projectz { // Validate keywords field if (isString(mergedPackagesData.keywords)) { - return Promise.reject( - new Error('projectz: keywords field must be array instead of CSV') - ) + throw new Error('projectz: keywords field must be array instead of CSV') } // Validate sponsors array if (mergedPackagesData.sponsor) { - return Promise.reject( - new Error('projectz: sponsor field is deprecated, use sponsors field') + throw new Error( + 'projectz: sponsor field is deprecated, use sponsors field' ) } if (isString(mergedPackagesData.sponsors)) { - return Promise.reject( - new Error('projectz: sponsors field must be array instead of CSV') - ) + throw new Error('projectz: sponsors field must be array instead of CSV') } // Validate maintainers array if (mergedPackagesData.maintainer) { - return Promise.reject( - new Error( - 'projectz: maintainer field is deprecated, use maintainers field' - ) + throw new Error( + 'projectz: maintainer field is deprecated, use maintainers field' ) } if (isString(mergedPackagesData.maintainers)) { - return Promise.reject( - new Error('projectz: maintainers field must be array instead of CSV') + throw new Error( + 'projectz: maintainers field must be array instead of CSV' ) } // Validate license SPDX string if (isPlainObject(mergedPackagesData.license)) { - return Promise.reject( - new Error( - 'projectz: license field must now be a valid SPDX string: https://docs.npmjs.com/files/package.json#license' - ) + throw new Error( + 'projectz: license field must now be a valid SPDX string: https://docs.npmjs.com/files/package.json#license' ) } if (isPlainObject(mergedPackagesData.licenses)) { - return Promise.reject( - new Error( - 'projectz: licenses field is deprecated, you must now use the license field as a valid SPDX string: https://docs.npmjs.com/files/package.json#license' - ) + throw new Error( + 'projectz: licenses field is deprecated, you must now use the license field as a valid SPDX string: https://docs.npmjs.com/files/package.json#license' ) } @@ -244,19 +223,15 @@ export class Projectz { const objs = ['badges', 'readmes', 'packages', 'github', 'bugs'] for (const key of objs) { if (!isPlainObject(mergedPackagesData[key])) { - return Promise.reject( - new Error(`projectz: ${key} property must be an object`) - ) + throw new Error(`projectz: ${key} property must be an object`) } } // Validate package values for (const [key, value] of Object.entries(mergedPackagesData.packages)) { if (!isPlainObject(value)) { - return Promise.reject( - new Error( - `projectz: custom package data for package ${key} must be an object` - ) + throw new Error( + `projectz: custom package data for package ${key} must be an object` ) } } @@ -267,12 +242,11 @@ export class Projectz { (mergedPackagesData.badges.config && !isPlainObject(mergedPackagesData.badges.config)) ) { - return Promise.reject( - new Error( - 'projectz: badges field must be in the format of: {list: [], config: {}}\nSee https://github.com/bevry/badges for details.' - ) + throw new Error( + 'projectz: badges field must be in the format of: {list: [], config: {}}\nSee https://github.com/bevry/badges for details.' ) } + mergedPackagesData.badges.config ??= {} // ---------------------------------- // Ensure @@ -630,9 +604,8 @@ export class Projectz { if (!filename || key === 'projectz') return const filepath = join(this.cwd, filename) this.log('info', `Saving package file: ${filepath}`) - const data = - JSON.stringify(enhancedPackagesData[key], null, ' ') + '\n' - return writeFile(filepath, data) + const data = enhancedPackagesData[key] + return writeJSON(filepath, data) } ), // save readme files @@ -641,8 +614,8 @@ export class Projectz { if (!filename) return const filepath = join(this.cwd, filename) this.log('info', `Saving readme file: ${filepath}`) - const data = enhancedReadmesData[key] - return writeFile(filepath, data) + const content = enhancedReadmesData[key] + return writeFile(filepath, content) } ), ]) diff --git a/source/install.ts b/source/install.ts index 3f172c73..f969c307 100644 --- a/source/install.ts +++ b/source/install.ts @@ -1,6 +1,5 @@ import { getLink } from './util.js' import { Link, FilenamesForPackageFiles, Editions } from './types.js' -import { isEmptyPlainObject } from 'typechecker' function hydrateTextWithLinks(text: string) { const linksArray: Link[] = [ diff --git a/test-fixtures/out-expected/projectz.cson b/test-fixtures/out-expected/projectz.cson deleted file mode 100644 index 3f3b450a..00000000 --- a/test-fixtures/out-expected/projectz.cson +++ /dev/null @@ -1,69 +0,0 @@ -{ - # ================================= - # META - - name: "ambi" - repo: "bevry/ambi" - version: "2.1.4" - license: "(MIT AND CC-BY-4.0)" - description: "Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically)." - keywords: [ - 'sync', 'async', 'fire', 'exec', 'execute', 'ambidextrous', 'flow' - ] - author: '2015+ Bevry Pty Ltd (http://bevry.me), 2011-2014 Benjamin Lupton (http://balupton.com)' - maintainers: [ - 'Benjamin Lupton (https://github.com/balupton)' - ] - badges: { - "list": [ - "travisci", - "npmversion", - "npmdownloads", - "daviddm", - "daviddmdev", - "---", - "slackin", - "patreon", - "gratipay", - "flattr", - "paypal", - "bitcoin", - "wishlist" - ], - "config": { - "patreonUsername": "bevry", - "gratipayUsername": "bevry", - "flattrCode": "344188/balupton-on-Flattr", - "paypalButtonID": "QB8GQPZAH84N6", - "bitcoinURL": "https://bevry.me/bitcoin", - "wishlistURL": "https://bevry.me/wishlist", - "slackinURL": "https://slack.bevry.me" - } - } - dependencies: - "typechecker": "~2.0.6" - engines: - node: ">=0.8" - scripts: - preinstall: "node ./cyclic.js" - test: "node ./out/text/everything-test.js" - main: "./out/lib/ambi.js" - - # auto detected and enhanced - # - homepage - # - authors - # - maintainers - # - keywords - # - license - # - repository - # - bugs - # - badges - - # ================================= - # Custom Configuration - - packages: - component: - dependencies: - "bevry/typechecker": "master" -} diff --git a/test-fixtures/out-expected/projectz.json b/test-fixtures/out-expected/projectz.json new file mode 100644 index 00000000..74860541 --- /dev/null +++ b/test-fixtures/out-expected/projectz.json @@ -0,0 +1,56 @@ +{ + "name": "ambi", + "repo": "bevry/ambi", + "version": "2.1.4", + "license": "(MIT AND CC-BY-4.0)", + "description": "Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).", + "keywords": [ + "sync", + "async", + "fire", + "exec", + "execute", + "ambidextrous", + "flow" + ], + "author": "2015+ Bevry Pty Ltd (http://bevry.me), 2011-2014 Benjamin Lupton (http://balupton.com)", + "maintainers": [ + "Benjamin Lupton (https://github.com/balupton)" + ], + "badges": { + "list": [ + "travisci", + "npmversion", + "npmdownloads", + "daviddm", + "daviddmdev", + "---", + "slackin", + "patreon", + "gratipay", + "flattr", + "paypal", + "bitcoin", + "wishlist" + ], + "config": { + "patreonUsername": "bevry", + "gratipayUsername": "bevry", + "flattrCode": "344188/balupton-on-Flattr", + "paypalButtonID": "QB8GQPZAH84N6", + "bitcoinURL": "https://bevry.me/bitcoin", + "wishlistURL": "https://bevry.me/wishlist", + "slackinURL": "https://slack.bevry.me" + } + }, + "dependencies": { "typechecker": "~2.0.6" }, + "engines": { "node": ">=0.8" }, + "scripts": { + "preinstall": "node ./cyclic.js", + "test": "node ./out/text/everything-test.js" + }, + "main": "./out/lib/ambi.js", + "packages": { + "component": { "dependencies": { "bevry/typechecker": "master" } } + } +} diff --git a/test-fixtures/src/bower.json b/test-fixtures/src/bower.json index ba9288d4..b93a7630 100644 --- a/test-fixtures/src/bower.json +++ b/test-fixtures/src/bower.json @@ -30,4 +30,4 @@ "flow" ], "main": "./out/lib/ambi.js" -} +} \ No newline at end of file diff --git a/test-fixtures/src/component.json b/test-fixtures/src/component.json index 0522a1c2..fb84535b 100644 --- a/test-fixtures/src/component.json +++ b/test-fixtures/src/component.json @@ -20,4 +20,4 @@ "dependencies": { "bevry/typechecker": "master" } -} +} \ No newline at end of file diff --git a/test-fixtures/src/package.json b/test-fixtures/src/package.json index c63739af..99c7bd64 100644 --- a/test-fixtures/src/package.json +++ b/test-fixtures/src/package.json @@ -43,4 +43,4 @@ }, "main": "./out/lib/ambi.js", "license": "(MIT AND CC-BY-4.0)" -} +} \ No newline at end of file diff --git a/test-fixtures/src/projectz.cson b/test-fixtures/src/projectz.cson deleted file mode 100644 index 3f3b450a..00000000 --- a/test-fixtures/src/projectz.cson +++ /dev/null @@ -1,69 +0,0 @@ -{ - # ================================= - # META - - name: "ambi" - repo: "bevry/ambi" - version: "2.1.4" - license: "(MIT AND CC-BY-4.0)" - description: "Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically)." - keywords: [ - 'sync', 'async', 'fire', 'exec', 'execute', 'ambidextrous', 'flow' - ] - author: '2015+ Bevry Pty Ltd (http://bevry.me), 2011-2014 Benjamin Lupton (http://balupton.com)' - maintainers: [ - 'Benjamin Lupton (https://github.com/balupton)' - ] - badges: { - "list": [ - "travisci", - "npmversion", - "npmdownloads", - "daviddm", - "daviddmdev", - "---", - "slackin", - "patreon", - "gratipay", - "flattr", - "paypal", - "bitcoin", - "wishlist" - ], - "config": { - "patreonUsername": "bevry", - "gratipayUsername": "bevry", - "flattrCode": "344188/balupton-on-Flattr", - "paypalButtonID": "QB8GQPZAH84N6", - "bitcoinURL": "https://bevry.me/bitcoin", - "wishlistURL": "https://bevry.me/wishlist", - "slackinURL": "https://slack.bevry.me" - } - } - dependencies: - "typechecker": "~2.0.6" - engines: - node: ">=0.8" - scripts: - preinstall: "node ./cyclic.js" - test: "node ./out/text/everything-test.js" - main: "./out/lib/ambi.js" - - # auto detected and enhanced - # - homepage - # - authors - # - maintainers - # - keywords - # - license - # - repository - # - bugs - # - badges - - # ================================= - # Custom Configuration - - packages: - component: - dependencies: - "bevry/typechecker": "master" -} diff --git a/test-fixtures/src/projectz.json b/test-fixtures/src/projectz.json new file mode 100644 index 00000000..74860541 --- /dev/null +++ b/test-fixtures/src/projectz.json @@ -0,0 +1,56 @@ +{ + "name": "ambi", + "repo": "bevry/ambi", + "version": "2.1.4", + "license": "(MIT AND CC-BY-4.0)", + "description": "Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).", + "keywords": [ + "sync", + "async", + "fire", + "exec", + "execute", + "ambidextrous", + "flow" + ], + "author": "2015+ Bevry Pty Ltd (http://bevry.me), 2011-2014 Benjamin Lupton (http://balupton.com)", + "maintainers": [ + "Benjamin Lupton (https://github.com/balupton)" + ], + "badges": { + "list": [ + "travisci", + "npmversion", + "npmdownloads", + "daviddm", + "daviddmdev", + "---", + "slackin", + "patreon", + "gratipay", + "flattr", + "paypal", + "bitcoin", + "wishlist" + ], + "config": { + "patreonUsername": "bevry", + "gratipayUsername": "bevry", + "flattrCode": "344188/balupton-on-Flattr", + "paypalButtonID": "QB8GQPZAH84N6", + "bitcoinURL": "https://bevry.me/bitcoin", + "wishlistURL": "https://bevry.me/wishlist", + "slackinURL": "https://slack.bevry.me" + } + }, + "dependencies": { "typechecker": "~2.0.6" }, + "engines": { "node": ">=0.8" }, + "scripts": { + "preinstall": "node ./cyclic.js", + "test": "node ./out/text/everything-test.js" + }, + "main": "./out/lib/ambi.js", + "packages": { + "component": { "dependencies": { "bevry/typechecker": "master" } } + } +}