diff --git a/package.json b/package.json index 199c209..1253b18 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@commitlint/config-conventional": "^18.6.2", "@semantic-release/changelog": "^6.0.3", "@semantic-release/git": "^10.0.1", - "@types/node": "^20.11.19", + "@types/node": "^20.11.20", "@types/which": "^3.0.3", "@types/yeoman-assert": "^3.1.4", "@types/yosay": "^2.0.3", @@ -63,7 +63,7 @@ "commitizen": "^4.3.0", "cz-conventional-changelog": "3.3.0", "doctoc": "^2.2.1", - "eslint": "^8.56.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "husky": "^9.0.11", "lint-staged": "^15.2.2", @@ -71,9 +71,9 @@ "prettier": "^3.2.5", "rimraf": "^5.0.5", "semantic-release": "^23.0.2", - "terser": "^5.27.2", + "terser": "^5.28.1", "tsup": "^8.0.2", - "type-fest": "^4.10.2", + "type-fest": "^4.10.3", "typescript": "^5.3.3", "vite-node": "^1.3.1", "vitest": "^0.34.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b4798fe..39d89c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,7 +33,7 @@ dependencies: devDependencies: "@commitlint/cli": specifier: ^18.6.1 - version: 18.6.1(@types/node@20.11.19)(typescript@5.3.3) + version: 18.6.1(@types/node@20.11.20)(typescript@5.3.3) "@commitlint/config-conventional": specifier: ^18.6.2 version: 18.6.2 @@ -44,8 +44,8 @@ devDependencies: specifier: ^10.0.1 version: 10.0.1(semantic-release@23.0.2) "@types/node": - specifier: ^20.11.19 - version: 20.11.19 + specifier: ^20.11.20 + version: 20.11.20 "@types/which": specifier: ^3.0.3 version: 3.0.3 @@ -57,10 +57,10 @@ devDependencies: version: 2.0.3 "@typescript-eslint/eslint-plugin": specifier: ^7.0.2 - version: 7.0.2(@typescript-eslint/parser@7.0.2)(eslint@8.56.0)(typescript@5.3.3) + version: 7.0.2(@typescript-eslint/parser@7.0.2)(eslint@8.57.0)(typescript@5.3.3) "@typescript-eslint/parser": specifier: ^7.0.2 - version: 7.0.2(eslint@8.56.0)(typescript@5.3.3) + version: 7.0.2(eslint@8.57.0)(typescript@5.3.3) "@yeoman/types": specifier: ^1.1.2 version: 1.1.2(@types/inquirer@9.0.7)(mem-fs@4.0.0) @@ -69,19 +69,19 @@ devDependencies: version: 6.26.1 commitizen: specifier: ^4.3.0 - version: 4.3.0(@types/node@20.11.19)(typescript@5.3.3) + version: 4.3.0(@types/node@20.11.20)(typescript@5.3.3) cz-conventional-changelog: specifier: 3.3.0 - version: 3.3.0(@types/node@20.11.19)(typescript@5.3.3) + version: 3.3.0(@types/node@20.11.20)(typescript@5.3.3) doctoc: specifier: ^2.2.1 version: 2.2.1 eslint: - specifier: ^8.56.0 - version: 8.56.0 + specifier: ^8.57.0 + version: 8.57.0 eslint-config-prettier: specifier: ^9.1.0 - version: 9.1.0(eslint@8.56.0) + version: 9.1.0(eslint@8.57.0) husky: specifier: ^9.0.11 version: 9.0.11 @@ -101,23 +101,23 @@ devDependencies: specifier: ^23.0.2 version: 23.0.2(typescript@5.3.3) terser: - specifier: ^5.27.2 - version: 5.27.2 + specifier: ^5.28.1 + version: 5.28.1 tsup: specifier: ^8.0.2 version: 8.0.2(typescript@5.3.3) type-fest: - specifier: ^4.10.2 - version: 4.10.2 + specifier: ^4.10.3 + version: 4.10.3 typescript: specifier: ^5.3.3 version: 5.3.3 vite-node: specifier: ^1.3.1 - version: 1.3.1(@types/node@20.11.19)(terser@5.27.2) + version: 1.3.1(@types/node@20.11.20)(terser@5.28.1) vitest: specifier: ^0.34.6 - version: 0.34.6(terser@5.27.2) + version: 0.34.6(terser@5.28.1) yeoman-assert: specifier: ^3.1.1 version: 3.1.1 @@ -185,7 +185,7 @@ packages: dev: true optional: true - /@commitlint/cli@18.6.1(@types/node@20.11.19)(typescript@5.3.3): + /@commitlint/cli@18.6.1(@types/node@20.11.20)(typescript@5.3.3): resolution: { integrity: sha512-5IDE0a+lWGdkOvKH892HHAZgbAjcj1mT5QrfA/SVbLJV/BbBMGyKN0W5mhgjekPJJwEQdVNvhl9PwUacY58Usw==, @@ -195,7 +195,7 @@ packages: dependencies: "@commitlint/format": 18.6.1 "@commitlint/lint": 18.6.1 - "@commitlint/load": 18.6.1(@types/node@20.11.19)(typescript@5.3.3) + "@commitlint/load": 18.6.1(@types/node@20.11.20)(typescript@5.3.3) "@commitlint/read": 18.6.1 "@commitlint/types": 18.6.1 execa: 5.1.1 @@ -288,7 +288,7 @@ packages: "@commitlint/types": 18.6.1 dev: true - /@commitlint/load@18.6.1(@types/node@20.11.19)(typescript@5.3.3): + /@commitlint/load@18.6.1(@types/node@20.11.20)(typescript@5.3.3): resolution: { integrity: sha512-p26x8734tSXUHoAw0ERIiHyW4RaI4Bj99D8YgUlVV9SedLf8hlWAfyIFhHRIhfPngLlCe0QYOdRKYFt8gy56TA==, @@ -301,7 +301,7 @@ packages: "@commitlint/types": 18.6.1 chalk: 4.1.2 cosmiconfig: 8.3.6(typescript@5.3.3) - cosmiconfig-typescript-loader: 5.0.0(@types/node@20.11.19)(cosmiconfig@8.3.6)(typescript@5.3.3) + cosmiconfig-typescript-loader: 5.0.0(@types/node@20.11.20)(cosmiconfig@8.3.6)(typescript@5.3.3) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 @@ -677,7 +677,7 @@ packages: dev: true optional: true - /@eslint-community/eslint-utils@4.4.0(eslint@8.56.0): + /@eslint-community/eslint-utils@4.4.0(eslint@8.57.0): resolution: { integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==, @@ -686,7 +686,7 @@ packages: peerDependencies: eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 dependencies: - eslint: 8.56.0 + eslint: 8.57.0 eslint-visitor-keys: 3.4.3 dev: true @@ -718,10 +718,10 @@ packages: - supports-color dev: true - /@eslint/js@8.56.0: + /@eslint/js@8.57.0: resolution: { - integrity: sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==, + integrity: sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==, } engines: { node: ^12.22.0 || ^14.17.0 || >=16.0.0 } dev: true @@ -797,6 +797,18 @@ packages: "@jridgewell/trace-mapping": 0.3.19 dev: true + /@jridgewell/gen-mapping@0.3.4: + resolution: + { + integrity: sha512-Oud2QPM5dHviZNn4y/WhhYKSXksv+1xLEIsNrAbGcFzUN3ubqWRFT5gwPchNc5NuzILOU4tPBDTZ4VwhL8Y7cw==, + } + engines: { node: ">=6.0.0" } + dependencies: + "@jridgewell/set-array": 1.1.2 + "@jridgewell/sourcemap-codec": 1.4.15 + "@jridgewell/trace-mapping": 0.3.23 + dev: true + /@jridgewell/resolve-uri@3.1.1: resolution: { @@ -827,8 +839,8 @@ packages: integrity: sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==, } dependencies: - "@jridgewell/gen-mapping": 0.3.3 - "@jridgewell/trace-mapping": 0.3.22 + "@jridgewell/gen-mapping": 0.3.4 + "@jridgewell/trace-mapping": 0.3.23 dev: true /@jridgewell/sourcemap-codec@1.4.15: @@ -848,10 +860,10 @@ packages: "@jridgewell/sourcemap-codec": 1.4.15 dev: true - /@jridgewell/trace-mapping@0.3.22: + /@jridgewell/trace-mapping@0.3.23: resolution: { - integrity: sha512-Wf963MzWtA2sjrNt+g18IAln9lKnlRp+K2eH4jjIoF1wYeq3aMREpG09xhlhdzS0EjwU7qmUJYangWa+151vZw==, + integrity: sha512-9/4foRoUKp8s96tSkh8DlAAc5A0Ty8vLXld+l9gjKKY6ckwI8G15f0hskGmuLZu78ZlGa1vtsfOa+lnB4vG6Jg==, } dependencies: "@jridgewell/resolve-uri": 3.1.2 @@ -908,7 +920,7 @@ packages: engines: { node: ">= 8" } dependencies: "@nodelib/fs.scandir": 2.1.5 - fastq: 1.15.0 + fastq: 1.17.1 /@npmcli/agent@2.2.0: resolution: @@ -2268,24 +2280,24 @@ packages: } dev: true - /@types/node@16.18.82: + /@types/node@16.18.83: resolution: { - integrity: sha512-pcDZtkx9z8XYV+ius2P3Ot2VVrcYOfXffBQUBuiszrlUzKSmoDYqo+mV+IoL8iIiIjjtOMvNSmH1hwJ+Q+f96Q==, + integrity: sha512-TmBqzDY/GeCEmLob/31SunOQnqYE3ZiiuEh1U9o3HqE1E2cqKZQA5RQg4krEguCY3StnkXyDmCny75qyFLx/rA==, } - /@types/node@18.19.17: + /@types/node@18.19.18: resolution: { - integrity: sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng==, + integrity: sha512-80CP7B8y4PzZF0GWx15/gVWRrB5y/bIjNI84NK3cmQJu0WZwvmj2WMA5LcofQFVfLqqCSp545+U2LsrVzX36Zg==, } dependencies: undici-types: 5.26.5 - /@types/node@20.11.19: + /@types/node@20.11.20: resolution: { - integrity: sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==, + integrity: sha512-7/rR21OS+fq8IyHTgtLkDK949uzsa6n8BkziAKtPVpugIkO6D+/ooXMvzXxDnZrmtXVfjb1bKQafYpb8s89LOg==, } dependencies: undici-types: 5.26.5 @@ -2309,7 +2321,7 @@ packages: integrity: sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==, } dependencies: - "@types/node": 20.11.19 + "@types/node": 20.11.20 /@types/unist@2.0.8: resolution: @@ -2325,7 +2337,7 @@ packages: } dependencies: "@types/expect": 1.20.4 - "@types/node": 20.11.19 + "@types/node": 20.11.20 /@types/which@3.0.3: resolution: @@ -2340,7 +2352,7 @@ packages: integrity: sha512-hKiUQ1VVfJW1CFE/trneWj2oTcZ/VPGbiSB6RV/lGOGb6zpue+9jelw5fh0jMA5usEsKllK8LrzlKoPe2tghpw==, } dependencies: - "@types/node": 20.11.19 + "@types/node": 20.11.20 dev: true /@types/yosay@2.0.3: @@ -2350,7 +2362,7 @@ packages: } dev: true - /@typescript-eslint/eslint-plugin@7.0.2(@typescript-eslint/parser@7.0.2)(eslint@8.56.0)(typescript@5.3.3): + /@typescript-eslint/eslint-plugin@7.0.2(@typescript-eslint/parser@7.0.2)(eslint@8.57.0)(typescript@5.3.3): resolution: { integrity: sha512-/XtVZJtbaphtdrWjr+CJclaCVGPtOdBpFEnvtNf/jRV0IiEemRrL0qABex/nEt8isYcnFacm3nPHYQwL+Wb7qg==, @@ -2365,13 +2377,13 @@ packages: optional: true dependencies: "@eslint-community/regexpp": 4.10.0 - "@typescript-eslint/parser": 7.0.2(eslint@8.56.0)(typescript@5.3.3) + "@typescript-eslint/parser": 7.0.2(eslint@8.57.0)(typescript@5.3.3) "@typescript-eslint/scope-manager": 7.0.2 - "@typescript-eslint/type-utils": 7.0.2(eslint@8.56.0)(typescript@5.3.3) - "@typescript-eslint/utils": 7.0.2(eslint@8.56.0)(typescript@5.3.3) + "@typescript-eslint/type-utils": 7.0.2(eslint@8.57.0)(typescript@5.3.3) + "@typescript-eslint/utils": 7.0.2(eslint@8.57.0)(typescript@5.3.3) "@typescript-eslint/visitor-keys": 7.0.2 debug: 4.3.4 - eslint: 8.56.0 + eslint: 8.57.0 graphemer: 1.4.0 ignore: 5.3.1 natural-compare: 1.4.0 @@ -2382,7 +2394,7 @@ packages: - supports-color dev: true - /@typescript-eslint/parser@7.0.2(eslint@8.56.0)(typescript@5.3.3): + /@typescript-eslint/parser@7.0.2(eslint@8.57.0)(typescript@5.3.3): resolution: { integrity: sha512-GdwfDglCxSmU+QTS9vhz2Sop46ebNCXpPPvsByK7hu0rFGRHL+AusKQJ7SoN+LbLh6APFpQwHKmDSwN35Z700Q==, @@ -2400,7 +2412,7 @@ packages: "@typescript-eslint/typescript-estree": 7.0.2(typescript@5.3.3) "@typescript-eslint/visitor-keys": 7.0.2 debug: 4.3.4 - eslint: 8.56.0 + eslint: 8.57.0 typescript: 5.3.3 transitivePeerDependencies: - supports-color @@ -2417,7 +2429,7 @@ packages: "@typescript-eslint/visitor-keys": 7.0.2 dev: true - /@typescript-eslint/type-utils@7.0.2(eslint@8.56.0)(typescript@5.3.3): + /@typescript-eslint/type-utils@7.0.2(eslint@8.57.0)(typescript@5.3.3): resolution: { integrity: sha512-IKKDcFsKAYlk8Rs4wiFfEwJTQlHcdn8CLwLaxwd6zb8HNiMcQIFX9sWax2k4Cjj7l7mGS5N1zl7RCHOVwHq2VQ==, @@ -2431,9 +2443,9 @@ packages: optional: true dependencies: "@typescript-eslint/typescript-estree": 7.0.2(typescript@5.3.3) - "@typescript-eslint/utils": 7.0.2(eslint@8.56.0)(typescript@5.3.3) + "@typescript-eslint/utils": 7.0.2(eslint@8.57.0)(typescript@5.3.3) debug: 4.3.4 - eslint: 8.56.0 + eslint: 8.57.0 ts-api-utils: 1.2.1(typescript@5.3.3) typescript: 5.3.3 transitivePeerDependencies: @@ -2473,7 +2485,7 @@ packages: - supports-color dev: true - /@typescript-eslint/utils@7.0.2(eslint@8.56.0)(typescript@5.3.3): + /@typescript-eslint/utils@7.0.2(eslint@8.57.0)(typescript@5.3.3): resolution: { integrity: sha512-PZPIONBIB/X684bhT1XlrkjNZJIEevwkKDsdwfiu1WeqBxYEEdIgVDgm8/bbKHVu+6YOpeRqcfImTdImx/4Bsw==, @@ -2482,13 +2494,13 @@ packages: peerDependencies: eslint: ^8.56.0 dependencies: - "@eslint-community/eslint-utils": 4.4.0(eslint@8.56.0) + "@eslint-community/eslint-utils": 4.4.0(eslint@8.57.0) "@types/json-schema": 7.0.15 "@types/semver": 7.5.7 "@typescript-eslint/scope-manager": 7.0.2 "@typescript-eslint/types": 7.0.2 "@typescript-eslint/typescript-estree": 7.0.2(typescript@5.3.3) - eslint: 8.56.0 + eslint: 8.57.0 semver: 7.6.0 transitivePeerDependencies: - supports-color @@ -2594,7 +2606,7 @@ packages: "@yeoman/types": ^1.0.0 mem-fs: ^4.0.0 dependencies: - "@types/node": 16.18.82 + "@types/node": 16.18.83 "@yeoman/transform": 1.2.0 "@yeoman/types": 1.1.2(@types/inquirer@9.0.7)(mem-fs@4.0.0) binary-extensions: 2.2.0 @@ -2623,7 +2635,7 @@ packages: } engines: { node: ^16.13.0 || >=18.12.0 } dependencies: - "@types/node": 16.18.82 + "@types/node": 16.18.83 minimatch: 9.0.3 readable-stream: 4.5.2 @@ -2647,7 +2659,7 @@ packages: optional: true dependencies: "@types/inquirer": 9.0.7 - "@types/node": 16.18.82 + "@types/node": 16.18.83 mem-fs: 4.0.0 /JSONStream@1.3.5: @@ -3651,7 +3663,7 @@ packages: } engines: { node: ">= 6" } - /commitizen@4.3.0(@types/node@20.11.19)(typescript@5.3.3): + /commitizen@4.3.0(@types/node@20.11.20)(typescript@5.3.3): resolution: { integrity: sha512-H0iNtClNEhT0fotHvGV3E9tDejDeS04sN1veIebsKYGMuGscFaswRoYJKmT3eW85eIJAs0F28bG2+a/9wCOfPw==, @@ -3660,7 +3672,7 @@ packages: hasBin: true dependencies: cachedir: 2.3.0 - cz-conventional-changelog: 3.3.0(@types/node@20.11.19)(typescript@5.3.3) + cz-conventional-changelog: 3.3.0(@types/node@20.11.20)(typescript@5.3.3) dedent: 0.7.0 detect-indent: 6.1.0 find-node-modules: 2.1.3 @@ -3807,7 +3819,7 @@ packages: } dev: true - /cosmiconfig-typescript-loader@5.0.0(@types/node@20.11.19)(cosmiconfig@8.3.6)(typescript@5.3.3): + /cosmiconfig-typescript-loader@5.0.0(@types/node@20.11.20)(cosmiconfig@8.3.6)(typescript@5.3.3): resolution: { integrity: sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA==, @@ -3818,7 +3830,7 @@ packages: cosmiconfig: ">=8.2" typescript: ">=4" dependencies: - "@types/node": 20.11.19 + "@types/node": 20.11.20 cosmiconfig: 8.3.6(typescript@5.3.3) jiti: 1.21.0 typescript: 5.3.3 @@ -3891,7 +3903,7 @@ packages: engines: { node: ">=4" } hasBin: true - /cz-conventional-changelog@3.3.0(@types/node@20.11.19)(typescript@5.3.3): + /cz-conventional-changelog@3.3.0(@types/node@20.11.20)(typescript@5.3.3): resolution: { integrity: sha512-U466fIzU5U22eES5lTNiNbZ+d8dfcHcssH4o7QsdWaCcRs/feIPCxKYSWkYBNs5mny7MvEfwpTLWjvbm94hecw==, @@ -3899,13 +3911,13 @@ packages: engines: { node: ">= 10" } dependencies: chalk: 2.4.2 - commitizen: 4.3.0(@types/node@20.11.19)(typescript@5.3.3) + commitizen: 4.3.0(@types/node@20.11.20)(typescript@5.3.3) conventional-commit-types: 3.0.0 lodash.map: 4.6.0 longest: 2.0.1 word-wrap: 1.2.5 optionalDependencies: - "@commitlint/load": 18.6.1(@types/node@20.11.19)(typescript@5.3.3) + "@commitlint/load": 18.6.1(@types/node@20.11.20)(typescript@5.3.3) transitivePeerDependencies: - "@types/node" - typescript @@ -4367,7 +4379,7 @@ packages: engines: { node: ">=12" } dev: true - /eslint-config-prettier@9.1.0(eslint@8.56.0): + /eslint-config-prettier@9.1.0(eslint@8.57.0): resolution: { integrity: sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==, @@ -4376,7 +4388,7 @@ packages: peerDependencies: eslint: ">=7.0.0" dependencies: - eslint: 8.56.0 + eslint: 8.57.0 dev: true /eslint-scope@7.2.2: @@ -4398,18 +4410,18 @@ packages: engines: { node: ^12.22.0 || ^14.17.0 || >=16.0.0 } dev: true - /eslint@8.56.0: + /eslint@8.57.0: resolution: { - integrity: sha512-Go19xM6T9puCOWntie1/P997aXxFsOi37JIHRWI514Hc6ZnaHGKY9xFhrU65RT6CcBEzZoGG1e6Nq+DT04ZtZQ==, + integrity: sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==, } engines: { node: ^12.22.0 || ^14.17.0 || >=16.0.0 } hasBin: true dependencies: - "@eslint-community/eslint-utils": 4.4.0(eslint@8.56.0) + "@eslint-community/eslint-utils": 4.4.0(eslint@8.57.0) "@eslint-community/regexpp": 4.10.0 "@eslint/eslintrc": 2.1.4 - "@eslint/js": 8.56.0 + "@eslint/js": 8.57.0 "@humanwhocodes/config-array": 0.11.14 "@humanwhocodes/module-importer": 1.0.1 "@nodelib/fs.walk": 1.2.8 @@ -4673,10 +4685,10 @@ packages: } dev: false - /fastq@1.15.0: + /fastq@1.17.1: resolution: { - integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==, + integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==, } dependencies: reusify: 1.0.4 @@ -4861,15 +4873,15 @@ packages: } engines: { node: ^10.12.0 || >=12.0.0 } dependencies: - flatted: 3.2.9 + flatted: 3.3.1 keyv: 4.5.4 rimraf: 3.0.2 dev: true - /flatted@3.2.9: + /flatted@3.3.1: resolution: { - integrity: sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==, + integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==, } dev: true @@ -6918,7 +6930,7 @@ packages: mem-fs: ^4.0.0 dependencies: "@types/ejs": 3.1.5 - "@types/node": 18.19.17 + "@types/node": 18.19.18 binaryextensions: 4.19.0 commondir: 1.0.1 deep-extend: 0.6.0 @@ -6939,7 +6951,7 @@ packages: } engines: { node: ">=16.13.0" } dependencies: - "@types/node": 18.19.17 + "@types/node": 18.19.18 "@types/vinyl": 2.0.11 vinyl: 3.0.0 vinyl-file: 5.0.0 @@ -6952,7 +6964,7 @@ packages: } engines: { node: ">=18.0.0" } dependencies: - "@types/node": 20.11.19 + "@types/node": 20.11.20 "@types/vinyl": 2.0.11 vinyl: 3.0.0 vinyl-file: 5.0.0 @@ -8023,7 +8035,7 @@ packages: } engines: { node: ">=16.13.0" } dependencies: - "@types/node": 16.18.82 + "@types/node": 16.18.83 p-queue: 7.4.1 readable-stream: 4.5.2 @@ -8160,7 +8172,7 @@ packages: dependencies: "@babel/code-frame": 7.23.5 index-to-position: 0.1.2 - type-fest: 4.10.2 + type-fest: 4.10.3 /parse-passwd@1.0.0: resolution: @@ -8656,7 +8668,7 @@ packages: dependencies: find-up-simple: 1.0.0 read-pkg: 9.0.1 - type-fest: 4.10.2 + type-fest: 4.10.3 /read-pkg-up@11.0.0: resolution: @@ -8668,7 +8680,7 @@ packages: dependencies: find-up-simple: 1.0.0 read-pkg: 9.0.1 - type-fest: 4.10.2 + type-fest: 4.10.3 dev: true /read-pkg-up@7.0.1: @@ -8706,7 +8718,7 @@ packages: "@types/normalize-package-data": 2.4.4 normalize-package-data: 6.0.0 parse-json: 8.1.0 - type-fest: 4.10.2 + type-fest: 4.10.3 unicorn-magic: 0.1.0 /readable-stream@2.3.8: @@ -9899,10 +9911,10 @@ packages: unique-string: 3.0.0 dev: true - /terser@5.27.2: + /terser@5.28.1: resolution: { - integrity: sha512-sHXmLSkImesJ4p5apTeT63DsV4Obe1s37qT8qvwHRmVxKTBH7Rv9Wr26VcAMmLbmk9UliiwK8z+657NyJHHy/w==, + integrity: sha512-wM+bZp54v/E9eRRGXb5ZFDvinrJIOaTapx3WUokyVGZu5ucVCK55zEgGd5Dl2fSr3jUo5sDiERErUWLY6QPFyA==, } engines: { node: ">=10" } hasBin: true @@ -10248,10 +10260,10 @@ packages: engines: { node: ">=14.16" } dev: true - /type-fest@4.10.2: + /type-fest@4.10.3: resolution: { - integrity: sha512-anpAG63wSpdEbLwOqH8L84urkL6PiVIov3EMmgIhhThevh9aiMQov+6Btx0wldNcvm4wV+e2/Rt1QdDwKHFbHw==, + integrity: sha512-JLXyjizi072smKGGcZiAJDCNweT8J+AuRxmPZ1aG7TERg4ijx9REl8CNhbr36RV4qXqL1gO1FF9HL8OkVmmrsA==, } engines: { node: ">=16" } @@ -10502,7 +10514,7 @@ packages: replace-ext: 2.0.0 teex: 1.0.1 - /vite-node@0.34.6(@types/node@20.11.19)(terser@5.27.2): + /vite-node@0.34.6(@types/node@20.11.20)(terser@5.28.1): resolution: { integrity: sha512-nlBMJ9x6n7/Amaz6F3zJ97EBwR2FkzhBRxF5e+jE6LA3yi6Wtc2lyTij1OnDMIr34v5g/tVQtsVAzhT0jc5ygA==, @@ -10515,7 +10527,7 @@ packages: mlly: 1.5.0 pathe: 1.1.2 picocolors: 1.0.0 - vite: 5.0.12(@types/node@20.11.19)(terser@5.27.2) + vite: 5.0.12(@types/node@20.11.20)(terser@5.28.1) transitivePeerDependencies: - "@types/node" - less @@ -10527,7 +10539,7 @@ packages: - terser dev: true - /vite-node@1.3.1(@types/node@20.11.19)(terser@5.27.2): + /vite-node@1.3.1(@types/node@20.11.20)(terser@5.28.1): resolution: { integrity: sha512-azbRrqRxlWTJEVbzInZCTchx0X69M/XPTCz4H+TLvlTcR/xH/3hkRqhOakT41fMJCMzXTu4UvegkZiEoJAWvng==, @@ -10539,7 +10551,7 @@ packages: debug: 4.3.4 pathe: 1.1.2 picocolors: 1.0.0 - vite: 5.1.3(@types/node@20.11.19)(terser@5.27.2) + vite: 5.1.3(@types/node@20.11.20)(terser@5.28.1) transitivePeerDependencies: - "@types/node" - less @@ -10551,7 +10563,7 @@ packages: - terser dev: true - /vite@5.0.12(@types/node@20.11.19)(terser@5.27.2): + /vite@5.0.12(@types/node@20.11.20)(terser@5.28.1): resolution: { integrity: sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w==, @@ -10582,16 +10594,16 @@ packages: terser: optional: true dependencies: - "@types/node": 20.11.19 + "@types/node": 20.11.20 esbuild: 0.19.12 postcss: 8.4.33 rollup: 4.9.6 - terser: 5.27.2 + terser: 5.28.1 optionalDependencies: fsevents: 2.3.3 dev: true - /vite@5.1.3(@types/node@20.11.19)(terser@5.27.2): + /vite@5.1.3(@types/node@20.11.20)(terser@5.28.1): resolution: { integrity: sha512-UfmUD36DKkqhi/F75RrxvPpry+9+tTkrXfMNZD+SboZqBCMsxKtO52XeGzzuh7ioz+Eo/SYDBbdb0Z7vgcDJew==, @@ -10622,16 +10634,16 @@ packages: terser: optional: true dependencies: - "@types/node": 20.11.19 + "@types/node": 20.11.20 esbuild: 0.19.12 postcss: 8.4.35 rollup: 4.12.0 - terser: 5.27.2 + terser: 5.28.1 optionalDependencies: fsevents: 2.3.3 dev: true - /vitest@0.34.6(terser@5.27.2): + /vitest@0.34.6(terser@5.28.1): resolution: { integrity: sha512-+5CALsOvbNKnS+ZHMXtuUC7nL8/7F1F2DnHGjSsszX8zCjWSSviphCb/NuS9Nzf4Q03KyyDRBAXhF/8lffME4Q==, @@ -10667,7 +10679,7 @@ packages: dependencies: "@types/chai": 4.3.11 "@types/chai-subset": 1.3.5 - "@types/node": 20.11.19 + "@types/node": 20.11.20 "@vitest/expect": 0.34.6 "@vitest/runner": 0.34.6 "@vitest/snapshot": 0.34.6 @@ -10686,8 +10698,8 @@ packages: strip-literal: 1.3.0 tinybench: 2.6.0 tinypool: 0.7.0 - vite: 5.0.12(@types/node@20.11.19)(terser@5.27.2) - vite-node: 0.34.6(@types/node@20.11.19)(terser@5.27.2) + vite: 5.0.12(@types/node@20.11.20)(terser@5.28.1) + vite-node: 0.34.6(@types/node@20.11.20)(terser@5.28.1) why-is-node-running: 2.2.2 transitivePeerDependencies: - less @@ -11065,7 +11077,7 @@ packages: optional: true dependencies: "@types/lodash-es": 4.17.12 - "@types/node": 18.19.17 + "@types/node": 18.19.18 "@yeoman/namespace": 1.0.0 "@yeoman/types": 1.1.2(@types/inquirer@9.0.7)(mem-fs@4.0.0) chalk: 5.3.0 @@ -11113,7 +11125,7 @@ packages: mem-fs-editor: 10.0.3 sinon: 16.1.3 temp-dir: 3.0.0 - type-fest: 4.10.2 + type-fest: 4.10.3 yeoman-environment: 4.3.0(@yeoman/types@1.1.2)(mem-fs@4.0.0) yeoman-generator: 7.1.1(@yeoman/types@1.1.2)(mem-fs@4.0.0)(yeoman-environment@4.3.0) dev: true diff --git a/src/app.ts b/src/app.ts index 3b30d6a..3cf8aeb 100644 --- a/src/app.ts +++ b/src/app.ts @@ -25,6 +25,7 @@ class AppGenerator extends Generator { private generator: GeneratorInterface | undefined = undefined; private readonly choices = GeneratorFactory.getAvailable(); public abort: boolean = false; + public user: string = ""; constructor(args: string | Array, options: AppOptions) { super(args, options); @@ -50,6 +51,8 @@ class AppGenerator extends Generator { } public async initializing(): Promise { + this.user = await GitHelper.getGitUserName(this); + this.log( yosay( `Welcome to the\n${chalk.bold.magenta( diff --git a/src/generators/ClangGenerator.ts b/src/generators/ClangGenerator.ts index 5d0e3fc..a3f03b2 100644 --- a/src/generators/ClangGenerator.ts +++ b/src/generators/ClangGenerator.ts @@ -10,11 +10,12 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, PackageManager, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; import { NodeEnvironment } from "../environments/index.js"; @@ -39,6 +40,7 @@ export class ClangGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), new PackageManager(this.generator).getQuestion(), ); @@ -81,6 +83,10 @@ export class ClangGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; this.generator.options.pkg = this.generator.options.pkg || answers.pkg; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.generator.env.options.nodePackageManager = diff --git a/src/generators/CrestronSimplGenerator.ts b/src/generators/CrestronSimplGenerator.ts index 45fb3ea..9fc5f7a 100644 --- a/src/generators/CrestronSimplGenerator.ts +++ b/src/generators/CrestronSimplGenerator.ts @@ -11,11 +11,12 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, PackageManager, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; import { NodeEnvironment } from "../environments/index.js"; @@ -40,6 +41,7 @@ export class CrestronSimplGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), new PackageManager(this.generator).getQuestion(), ); @@ -82,6 +84,10 @@ export class CrestronSimplGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; this.generator.options.pkg = this.generator.options.pkg || answers.pkg; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.generator.env.options.nodePackageManager = diff --git a/src/generators/HtmlGenerator.ts b/src/generators/HtmlGenerator.ts index 2aed6ed..0f2998e 100644 --- a/src/generators/HtmlGenerator.ts +++ b/src/generators/HtmlGenerator.ts @@ -10,11 +10,12 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, PackageManager, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; import { NodeEnvironment } from "../environments/index.js"; @@ -39,6 +40,7 @@ export class HtmlGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), new PackageManager(this.generator).getQuestion(), ); @@ -81,6 +83,10 @@ export class HtmlGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; this.generator.options.pkg = this.generator.options.pkg || answers.pkg; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.generator.env.options.nodePackageManager = diff --git a/src/generators/JavascriptGenerator.ts b/src/generators/JavascriptGenerator.ts index f867e25..2d3cff4 100644 --- a/src/generators/JavascriptGenerator.ts +++ b/src/generators/JavascriptGenerator.ts @@ -10,11 +10,12 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, PackageManager, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; import { NodeEnvironment } from "../environments/index.js"; @@ -39,6 +40,7 @@ export class JavascriptGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), new PackageManager(this.generator).getQuestion(), ); @@ -81,6 +83,10 @@ export class JavascriptGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; this.generator.options.pkg = this.generator.options.pkg || answers.pkg; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.generator.env.options.nodePackageManager = diff --git a/src/generators/NodeCliGenerator.ts b/src/generators/NodeCliGenerator.ts index 2ee9881..303ebd7 100644 --- a/src/generators/NodeCliGenerator.ts +++ b/src/generators/NodeCliGenerator.ts @@ -10,11 +10,12 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, PackageManager, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; import { NodeEnvironment } from "../environments/index.js"; @@ -39,6 +40,7 @@ export class NodeCliGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), new PackageManager(this.generator).getQuestion(), ); @@ -81,6 +83,10 @@ export class NodeCliGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; this.generator.options.pkg = this.generator.options.pkg || answers.pkg; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.generator.env.options.nodePackageManager = diff --git a/src/generators/PythonGenerator.ts b/src/generators/PythonGenerator.ts index 7ff0804..61fc174 100644 --- a/src/generators/PythonGenerator.ts +++ b/src/generators/PythonGenerator.ts @@ -10,10 +10,11 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; @@ -36,6 +37,7 @@ export class PythonGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), ); } @@ -76,6 +78,10 @@ export class PythonGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + this.generator.options.description = this.generator.options.skipPrompts ? this.generator.options.description : answers.description; diff --git a/src/generators/TypescriptGenerator.ts b/src/generators/TypescriptGenerator.ts index eb0231b..b5aba03 100644 --- a/src/generators/TypescriptGenerator.ts +++ b/src/generators/TypescriptGenerator.ts @@ -10,11 +10,12 @@ import { } from "../@types/index.js"; import AppGenerator from "../app.js"; import { - ProjectName, - ProjectId, - ProjectDescription, + Author, Git, PackageManager, + ProjectDescription, + ProjectId, + ProjectName, } from "../questions/index.js"; import { ConfigHelper } from "../helpers/index.js"; import { NodeEnvironment } from "../environments/index.js"; @@ -39,6 +40,7 @@ export class TypescriptGenerator implements GeneratorInterface { new ProjectName(this.generator).getQuestion(), new ProjectId(this.generator).getQuestion(), new ProjectDescription(this.generator).getQuestion(), + new Author(this.generator).getQuestion(), new Git(this.generator).getQuestion(), new PackageManager(this.generator).getQuestion(), ); @@ -81,6 +83,10 @@ export class TypescriptGenerator implements GeneratorInterface { this.generator.options.id = this.generator.options.id || answers.id; this.generator.options.pkg = this.generator.options.pkg || answers.pkg; + this.generator.options.author = this.generator.options.skipPrompts + ? this.generator.options.author + : answers.author; + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.generator.env.options.nodePackageManager = diff --git a/src/helpers/CliHelper.ts b/src/helpers/CliHelper.ts index 3592c50..fb029a7 100644 --- a/src/helpers/CliHelper.ts +++ b/src/helpers/CliHelper.ts @@ -48,14 +48,12 @@ export class CliHelper { type: String, alias: "d", description: "Description of the project", - default: "", }, { name: "author", type: String, alias: "a", description: "Author of the project", - default: "", }, { name: "git", diff --git a/src/helpers/GitHelper.ts b/src/helpers/GitHelper.ts index 049b2fc..14947f6 100644 --- a/src/helpers/GitHelper.ts +++ b/src/helpers/GitHelper.ts @@ -2,20 +2,16 @@ import Generator from "yeoman-generator"; import which from "which"; export class GitHelper { - private static async isGitInstalled(): Promise { + public static async isGitInstalled(): Promise { return await which("git").catch(() => undefined); } - private static async getGitUserName( - generator: Generator, - ): Promise { - return await generator.git.name(); + public static async getGitUserName(generator: Generator): Promise { + return (await generator.git.name()) || ""; } - private static async getGitUserEmail( - generator: Generator, - ): Promise { - return await generator.git.email(); + public static async getGitUserEmail(generator: Generator): Promise { + return (await generator.git.email()) || ""; } public static async init(generator: Generator): Promise { diff --git a/src/questions/Author.ts b/src/questions/Author.ts index bc10ebd..ced8f70 100644 --- a/src/questions/Author.ts +++ b/src/questions/Author.ts @@ -1,16 +1,26 @@ import { PromptQuestion } from "@yeoman/types"; -import { BaseQuestion } from "./index.js"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers } from "../@types/index.js"; import AppGenerator from "../app.js"; export class Author extends BaseQuestion { public constructor(generator: AppGenerator) { super(generator); - // this.generator.options.author = this.generator.git.name(); + + if (this.generator.options.author) { + return; + } + + if ( + this.generator.options.author === undefined && + this.generator.options.skipPrompts + ) { + this.generator.options.author = this.getDefault(); + } } private getDefault(): string { - return ""; + return this.generator.user; } public getQuestion(): PromptQuestion { diff --git a/src/questions/Git.ts b/src/questions/Git.ts index 4257ac3..b33dc2b 100644 --- a/src/questions/Git.ts +++ b/src/questions/Git.ts @@ -1,5 +1,5 @@ import { PromptQuestion } from "@yeoman/types"; -import { BaseQuestion } from "./index.js"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers } from "../@types/index.js"; import AppGenerator from "../app.js"; diff --git a/src/questions/PackageManager.ts b/src/questions/PackageManager.ts index cda81c3..eabafb0 100644 --- a/src/questions/PackageManager.ts +++ b/src/questions/PackageManager.ts @@ -1,5 +1,5 @@ import { PromptQuestion } from "@yeoman/types"; -import { BaseQuestion } from "./index.js"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers, NodePackageManager } from "../@types/index.js"; import { ConfigHelper } from "../helpers/index.js"; import AppGenerator from "../app.js"; diff --git a/src/questions/ProjectDescription.ts b/src/questions/ProjectDescription.ts index 2dd3ce3..65e9667 100644 --- a/src/questions/ProjectDescription.ts +++ b/src/questions/ProjectDescription.ts @@ -1,6 +1,6 @@ import { PromptQuestion } from "@yeoman/types"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers } from "../@types/index.js"; -import { BaseQuestion } from "./index.js"; import AppGenerator from "../app.js"; export class ProjectDescription extends BaseQuestion { diff --git a/src/questions/ProjectId.ts b/src/questions/ProjectId.ts index 9fc407f..289ed84 100644 --- a/src/questions/ProjectId.ts +++ b/src/questions/ProjectId.ts @@ -1,6 +1,6 @@ import { PromptQuestion } from "@yeoman/types"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers } from "../@types/index.js"; -import { BaseQuestion } from "./index.js"; import AppGenerator from "../app.js"; export class ProjectId extends BaseQuestion { diff --git a/src/questions/ProjectName.ts b/src/questions/ProjectName.ts index 5efffb9..728ef4e 100644 --- a/src/questions/ProjectName.ts +++ b/src/questions/ProjectName.ts @@ -1,8 +1,8 @@ import path from "node:path"; import { PromptQuestion } from "@yeoman/types"; -import AppGenerator from "../app.js"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers } from "../@types/index.js"; -import { BaseQuestion } from "./index.js"; +import AppGenerator from "../app.js"; export class ProjectName extends BaseQuestion { public constructor(generator: AppGenerator) { diff --git a/src/questions/ProjectType.ts b/src/questions/ProjectType.ts index 21c91f3..2888776 100644 --- a/src/questions/ProjectType.ts +++ b/src/questions/ProjectType.ts @@ -1,6 +1,6 @@ import { PromptQuestion } from "@yeoman/types"; +import { BaseQuestion } from "./BaseQuestion.js"; import { Answers, GeneratorSignature } from "../@types/index.js"; -import { BaseQuestion } from "./index.js"; import AppGenerator from "../app.js"; export class ProjectType extends BaseQuestion { diff --git a/src/questions/index.ts b/src/questions/index.ts index 4fa3a32..dc5d9f1 100644 --- a/src/questions/index.ts +++ b/src/questions/index.ts @@ -1,4 +1,4 @@ -export * from "./BaseQuestion.js"; +export * from "./Author.js"; export * from "./Git.js"; export * from "./PackageManager.js"; export * from "./ProjectDescription.js"; diff --git a/templates/c/LICENSE b/templates/c/LICENSE index 2def622..632413b 100644 --- a/templates/c/LICENSE +++ b/templates/c/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/c/all-contributorsrc.ejs b/templates/c/all-contributorsrc.ejs index 59514c6..9e82da5 100644 --- a/templates/c/all-contributorsrc.ejs +++ b/templates/c/all-contributorsrc.ejs @@ -1,6 +1,6 @@ { "projectName": <%- JSON.stringify(id) %>, - "projectOwner": "", + "projectOwner": <%- JSON.stringify(author) %>, "repoType": "github", "repoHost": "https://github.com", "files": [ diff --git a/templates/c/package.json.ejs b/templates/c/package.json.ejs index 2c277ad..dbab277 100644 --- a/templates/c/package.json.ejs +++ b/templates/c/package.json.ejs @@ -4,6 +4,7 @@ "description": <%- JSON.stringify(description) %>, "version": "0.0.0", "license": "MIT", + "author": <%- JSON.stringify(author) %>, "repository": { "type": "git", "url": "" diff --git a/templates/html/LICENSE b/templates/html/LICENSE index 2def622..632413b 100644 --- a/templates/html/LICENSE +++ b/templates/html/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/html/all-contributorsrc.ejs b/templates/html/all-contributorsrc.ejs index 59514c6..9e82da5 100644 --- a/templates/html/all-contributorsrc.ejs +++ b/templates/html/all-contributorsrc.ejs @@ -1,6 +1,6 @@ { "projectName": <%- JSON.stringify(id) %>, - "projectOwner": "", + "projectOwner": <%- JSON.stringify(author) %>, "repoType": "github", "repoHost": "https://github.com", "files": [ diff --git a/templates/html/package.json.ejs b/templates/html/package.json.ejs index 47f9355..309206b 100644 --- a/templates/html/package.json.ejs +++ b/templates/html/package.json.ejs @@ -4,6 +4,7 @@ "description": <%- JSON.stringify(description) %>, "version": "0.0.0", "license": "MIT", + "author": <%- JSON.stringify(author) %>, "main": "assets/js/app.js", "type": "module", "repository": { diff --git a/templates/javascript/LICENSE b/templates/javascript/LICENSE index 2def622..632413b 100644 --- a/templates/javascript/LICENSE +++ b/templates/javascript/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/javascript/all-contributorsrc.ejs b/templates/javascript/all-contributorsrc.ejs index 59514c6..9e82da5 100644 --- a/templates/javascript/all-contributorsrc.ejs +++ b/templates/javascript/all-contributorsrc.ejs @@ -1,6 +1,6 @@ { "projectName": <%- JSON.stringify(id) %>, - "projectOwner": "", + "projectOwner": <%- JSON.stringify(author) %>, "repoType": "github", "repoHost": "https://github.com", "files": [ diff --git a/templates/javascript/package.json.ejs b/templates/javascript/package.json.ejs index 174d91b..1b152a5 100644 --- a/templates/javascript/package.json.ejs +++ b/templates/javascript/package.json.ejs @@ -4,6 +4,7 @@ "description": <%- JSON.stringify(description) %>, "version": "0.0.0", "license": "MIT", + "author": <%- JSON.stringify(author) %>, "main": "src/app.js", "type": "module", "repository": { diff --git a/templates/nodecli/LICENSE b/templates/nodecli/LICENSE index 2def622..632413b 100644 --- a/templates/nodecli/LICENSE +++ b/templates/nodecli/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/nodecli/all-contributorsrc.ejs b/templates/nodecli/all-contributorsrc.ejs index 59514c6..9e82da5 100644 --- a/templates/nodecli/all-contributorsrc.ejs +++ b/templates/nodecli/all-contributorsrc.ejs @@ -1,6 +1,6 @@ { "projectName": <%- JSON.stringify(id) %>, - "projectOwner": "", + "projectOwner": <%- JSON.stringify(author) %>, "repoType": "github", "repoHost": "https://github.com", "files": [ diff --git a/templates/nodecli/package.json.ejs b/templates/nodecli/package.json.ejs index ac935f8..613d109 100644 --- a/templates/nodecli/package.json.ejs +++ b/templates/nodecli/package.json.ejs @@ -4,6 +4,7 @@ "description": <%- JSON.stringify(description) %>, "version": "0.0.0", "license": "MIT", + "author": <%- JSON.stringify(author) %>, "main": "src/app.js", "type": "module", "files": [ diff --git a/templates/python/LICENSE b/templates/python/LICENSE index 2def622..632413b 100644 --- a/templates/python/LICENSE +++ b/templates/python/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/simpl/LICENSE b/templates/simpl/LICENSE index 2def622..632413b 100644 --- a/templates/simpl/LICENSE +++ b/templates/simpl/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/simpl/all-contributorsrc.ejs b/templates/simpl/all-contributorsrc.ejs index 59514c6..9e82da5 100644 --- a/templates/simpl/all-contributorsrc.ejs +++ b/templates/simpl/all-contributorsrc.ejs @@ -1,6 +1,6 @@ { "projectName": <%- JSON.stringify(id) %>, - "projectOwner": "", + "projectOwner": <%- JSON.stringify(author) %>, "repoType": "github", "repoHost": "https://github.com", "files": [ diff --git a/templates/simpl/package.json.ejs b/templates/simpl/package.json.ejs index 4099858..a3981e1 100644 --- a/templates/simpl/package.json.ejs +++ b/templates/simpl/package.json.ejs @@ -4,6 +4,7 @@ "description": <%- JSON.stringify(description) %>, "version": "0.0.0", "license": "MIT", + "author": <%- JSON.stringify(author) %>, "repository": { "type": "git", "url": "" diff --git a/templates/typescript/LICENSE b/templates/typescript/LICENSE index 2def622..632413b 100644 --- a/templates/typescript/LICENSE +++ b/templates/typescript/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) <%- new Date().getFullYear() %> Norgate AV Services Limited +Copyright (c) <%- new Date().getFullYear() %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/typescript/all-contributorsrc.ejs b/templates/typescript/all-contributorsrc.ejs index 59514c6..9e82da5 100644 --- a/templates/typescript/all-contributorsrc.ejs +++ b/templates/typescript/all-contributorsrc.ejs @@ -1,6 +1,6 @@ { "projectName": <%- JSON.stringify(id) %>, - "projectOwner": "", + "projectOwner": <%- JSON.stringify(author) %>, "repoType": "github", "repoHost": "https://github.com", "files": [ diff --git a/templates/typescript/package.json.ejs b/templates/typescript/package.json.ejs index a16cab0..e1671a9 100644 --- a/templates/typescript/package.json.ejs +++ b/templates/typescript/package.json.ejs @@ -4,6 +4,7 @@ "description": <%- JSON.stringify(description) %>, "version": "0.0.0", "license": "MIT", + "author": <%- JSON.stringify(author) %>, "main": "./dist/app.js", "types": "./dist/app.d.ts", "type": "module", diff --git a/tests/c.test.ts b/tests/c.test.ts index 42cff2f..a9f041d 100644 --- a/tests/c.test.ts +++ b/tests/c.test.ts @@ -8,7 +8,16 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; -import { getNodeDependencyObject } from "./helpers.js"; +import { + assertAllContributorsRc, + assertChangeLog, + assertContributing, + assertHuskyGitHooks, + assertLicense, + assertOptionValues, + assertReadMe, + getNodeDependencyObject, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -124,22 +133,15 @@ describe("generator-norgate-av:c", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -155,6 +157,7 @@ describe("generator-norgate-av:c", () => { name: id, displayName: name, description, + author, engines: { node: `>=${engine}`, }, @@ -169,11 +172,7 @@ describe("generator-norgate-av:c", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -181,59 +180,26 @@ describe("generator-norgate-av:c", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -307,23 +273,15 @@ describe("generator-norgate-av:c", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name: destination, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -339,6 +297,7 @@ describe("generator-norgate-av:c", () => { name: id, displayName: destination, description, + author, engines: { node: `>=${engine}`, }, @@ -353,11 +312,7 @@ describe("generator-norgate-av:c", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -365,59 +320,26 @@ describe("generator-norgate-av:c", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -465,18 +387,18 @@ describe("generator-norgate-av:c", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); - assert.equal(result.generator.options.pkg, "pnpm"); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - "pnpm", - ); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + name: destination, + id: "test-project", + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + pkg: "pnpm", + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -492,6 +414,7 @@ describe("generator-norgate-av:c", () => { name: result.generator.options.id, displayName: destination, description: result.generator.options.description, + author: result.generator.options.author, engines: { node: `>=${engine}`, }, @@ -506,14 +429,7 @@ describe("generator-norgate-av:c", () => { }); it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); - assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id: result.generator.options.id }); }); it("should create the correct .nvmrc", () => { @@ -521,71 +437,33 @@ describe("generator-norgate-av:c", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} install`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${result.generator.options.pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${result.generator.options.pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + pkg: result.generator.options.pkg, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${result.generator.options.id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { + id: result.generator.options.id, + author: result.generator.options.author, + }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${result.generator.options.pkg} commitlint --edit $1`, - ); - assert.fileContent( - ".husky/pre-commit", - `${result.generator.options.pkg} lint-staged`, - ); + assertHuskyGitHooks({ pkg: result.generator.options.pkg }); }); it.skipIf(process.env.CI)( diff --git a/tests/helpers.ts b/tests/helpers.ts index 6b18e97..06edc41 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -1,3 +1,15 @@ +import assert from "yeoman-assert"; +import { RunResult } from "yeoman-test"; +import AppGenerator from "../src/app.js"; +import { AppOptions } from "../src/@types/index.js"; + +type AssertionOptions = Partial< + Pick< + AppOptions, + "type" | "id" | "name" | "description" | "author" | "git" | "pkg" + > +>; + export function getNodeDependencyObject( dependencies: Array, store: Record, @@ -15,3 +27,80 @@ export function getNodeDependencyObject( }; }, {}); } + +export function assertReadMe(file: string, { id }: AssertionOptions): void { + assert.fileContent(file, `# ${id}`); + assert.fileContent( + file, + `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, + ); +} + +export function assertLicense( + file: string, + { author }: AssertionOptions, +): void { + assert.fileContent(file, "The MIT License (MIT)"); + assert.fileContent( + file, + `Copyright (c) ${new Date().getFullYear()} ${author}`, + ); +} + +export function assertAllContributorsRc( + file: string, + { id, author }: AssertionOptions, +): void { + assert.fileContent(file, `"projectName": "${id}"`); + assert.fileContent(file, `"projectOwner": "${author}"`); +} + +export function assertChangeLog(file: string, { id }: AssertionOptions): void { + assert.fileContent( + file, + `All notable changes to the "${id}" project will be documented in this file.`, + ); +} + +export function assertOptionValues( + result: RunResult, + { type, name, id, description, author, git, pkg }: AssertionOptions, +): void { + assert.equal(result.generator.options.type, type); + assert.equal(result.generator.options.name, name); + assert.equal(result.generator.options.id, id); + assert.equal(result.generator.options.description, description); + assert.equal(result.generator.options.author, author); + assert.equal(result.generator.options.git, process.env.CI ? false : git); + assert.equal(result.generator.options.pkg, pkg); + assert.equal( + // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + result.generator.env.options.nodePackageManager, + pkg, + ); +} + +export function assertHuskyGitHooks({ pkg }: AssertionOptions): void { + assert.fileContent(".husky/commit-msg", `${pkg} commitlint --edit $1`); + assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); +} + +export function assertContributing( + file: string, + { id, pkg }: AssertionOptions, +): void { + assert.fileContent(file, `/${id}/issues/new/choose`); + assert.fileContent(file, `/${id}.git`); + assert.fileContent(file, `cd ${id}`); + + if (pkg === undefined) { + return; + } + + assert.fileContent(file, `${pkg} install`); + assert.fileContent(file, `If in doubt, you can use the \`${pkg} commit\``); + assert.fileContent(file, `Be sure to run \`${pkg} test\``); + assert.fileContent(file, `Run the \`${pkg} contrib:add\``); + assert.fileContent(file, `${pkg} contrib:add `); +} diff --git a/tests/html.test.ts b/tests/html.test.ts index 8451323..aa600fd 100644 --- a/tests/html.test.ts +++ b/tests/html.test.ts @@ -8,7 +8,16 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; -import { getNodeDependencyObject } from "./helpers.js"; +import { + assertAllContributorsRc, + assertChangeLog, + assertContributing, + assertHuskyGitHooks, + assertLicense, + assertOptionValues, + assertReadMe, + getNodeDependencyObject, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -131,22 +140,15 @@ describe("generator-norgate-av:html", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -162,6 +164,7 @@ describe("generator-norgate-av:html", () => { name: id, displayName: name, description, + author, engines: { node: `>=${engine}`, }, @@ -180,11 +183,7 @@ describe("generator-norgate-av:html", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -192,59 +191,26 @@ describe("generator-norgate-av:html", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -318,23 +284,15 @@ describe("generator-norgate-av:html", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name: destination, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -350,6 +308,7 @@ describe("generator-norgate-av:html", () => { name: id, displayName: destination, description, + author, engines: { node: `>=${engine}`, }, @@ -363,12 +322,12 @@ describe("generator-norgate-av:html", () => { }); }); + it("should create the correct index.html", () => { + assert.fileContent("public/index.html", `${id}`); + }); + it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -376,59 +335,26 @@ describe("generator-norgate-av:html", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -481,18 +407,18 @@ describe("generator-norgate-av:html", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); - assert.equal(result.generator.options.pkg, "pnpm"); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - "pnpm", - ); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + name: destination, + id: "test-project", + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + pkg: "pnpm", + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -508,6 +434,7 @@ describe("generator-norgate-av:html", () => { name: result.generator.options.id, displayName: destination, description: result.generator.options.description, + author: result.generator.options.author, engines: { node: `>=${engine}`, }, @@ -521,87 +448,51 @@ describe("generator-norgate-av:html", () => { }); }); - it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); + it("should create the correct index.html", () => { assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, + "public/index.html", + `${result.generator.options.id}`, ); }); + it("should create the correct README.md", () => { + assertReadMe("README.md", { id: result.generator.options.id }); + }); + it("should create the correct .nvmrc", () => { assert.fileContent(".nvmrc", node.getNodeEngine()); }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} install`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${result.generator.options.pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${result.generator.options.pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + pkg: result.generator.options.pkg, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${result.generator.options.id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { + id: result.generator.options.id, + author: result.generator.options.author, + }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${result.generator.options.pkg} commitlint --edit $1`, - ); - assert.fileContent( - ".husky/pre-commit", - `${result.generator.options.pkg} lint-staged`, - ); + assertHuskyGitHooks({ + pkg: result.generator.options.pkg, + }); }); it.skipIf(process.env.CI)( diff --git a/tests/javascript.test.ts b/tests/javascript.test.ts index 8b3c205..037235f 100644 --- a/tests/javascript.test.ts +++ b/tests/javascript.test.ts @@ -8,7 +8,16 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; -import { getNodeDependencyObject } from "./helpers.js"; +import { + assertAllContributorsRc, + assertChangeLog, + assertContributing, + assertHuskyGitHooks, + assertLicense, + assertOptionValues, + assertReadMe, + getNodeDependencyObject, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -136,22 +145,15 @@ describe("generator-norgate-av:javascript", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -167,6 +169,7 @@ describe("generator-norgate-av:javascript", () => { name: id, displayName: name, description, + author, engines: { node: `>=${engine}`, }, @@ -185,11 +188,7 @@ describe("generator-norgate-av:javascript", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -197,59 +196,26 @@ describe("generator-norgate-av:javascript", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -323,23 +289,15 @@ describe("generator-norgate-av:javascript", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + id, + name: destination, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -355,6 +313,7 @@ describe("generator-norgate-av:javascript", () => { name: id, displayName: destination, description, + author, engines: { node: `>=${engine}`, }, @@ -373,11 +332,7 @@ describe("generator-norgate-av:javascript", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -385,59 +340,26 @@ describe("generator-norgate-av:javascript", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -490,18 +412,18 @@ describe("generator-norgate-av:javascript", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); - assert.equal(result.generator.options.pkg, "pnpm"); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - "pnpm", - ); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + name: destination, + id: "test-project", + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + pkg: "pnpm", + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -517,6 +439,7 @@ describe("generator-norgate-av:javascript", () => { name: result.generator.options.id, displayName: destination, description: result.generator.options.description, + author: result.generator.options.author, engines: { node: `>=${engine}`, }, @@ -535,14 +458,7 @@ describe("generator-norgate-av:javascript", () => { }); it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); - assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id: result.generator.options.id }); }); it("should create the correct .nvmrc", () => { @@ -550,71 +466,33 @@ describe("generator-norgate-av:javascript", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} install`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${result.generator.options.pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${result.generator.options.pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + pkg: result.generator.options.pkg, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${result.generator.options.id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { + id: result.generator.options.id, + author: result.generator.options.author, + }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${result.generator.options.pkg} commitlint --edit $1`, - ); - assert.fileContent( - ".husky/pre-commit", - `${result.generator.options.pkg} lint-staged`, - ); + assertHuskyGitHooks({ pkg: result.generator.options.pkg }); }); it.skipIf(process.env.CI)( diff --git a/tests/nodecli.test.ts b/tests/nodecli.test.ts index 115fb55..39b3c31 100644 --- a/tests/nodecli.test.ts +++ b/tests/nodecli.test.ts @@ -8,7 +8,16 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; -import { getNodeDependencyObject } from "./helpers.js"; +import { + assertAllContributorsRc, + assertChangeLog, + assertContributing, + assertHuskyGitHooks, + assertLicense, + assertOptionValues, + assertReadMe, + getNodeDependencyObject, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -156,22 +165,15 @@ describe("generator-norgate-av:nodecli", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -187,6 +189,7 @@ describe("generator-norgate-av:nodecli", () => { name: id, displayName: name, description, + author, bin: { [id]: "src/app.js", }, @@ -208,11 +211,7 @@ describe("generator-norgate-av:nodecli", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -220,59 +219,26 @@ describe("generator-norgate-av:nodecli", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -346,23 +312,15 @@ describe("generator-norgate-av:nodecli", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name: destination, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -378,6 +336,7 @@ describe("generator-norgate-av:nodecli", () => { name: id, displayName: destination, description, + author, bin: { [id]: "src/app.js", }, @@ -399,11 +358,7 @@ describe("generator-norgate-av:nodecli", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -411,59 +366,26 @@ describe("generator-norgate-av:nodecli", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -516,18 +438,18 @@ describe("generator-norgate-av:nodecli", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); - assert.equal(result.generator.options.pkg, "pnpm"); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - "pnpm", - ); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + name: destination, + id: "test-project", + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + pkg: "pnpm", + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -543,6 +465,7 @@ describe("generator-norgate-av:nodecli", () => { name: result.generator.options.id, displayName: destination, description: result.generator.options.description, + author: result.generator.options.author, bin: { [result.generator.options.id!]: "src/app.js", }, @@ -564,14 +487,7 @@ describe("generator-norgate-av:nodecli", () => { }); it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); - assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id: result.generator.options.id }); }); it("should create the correct .nvmrc", () => { @@ -579,71 +495,33 @@ describe("generator-norgate-av:nodecli", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} install`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${result.generator.options.pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${result.generator.options.pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + pkg: result.generator.options.pkg, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${result.generator.options.id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { + id: result.generator.options.id, + author: result.generator.options.author, + }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${result.generator.options.pkg} commitlint --edit $1`, - ); - assert.fileContent( - ".husky/pre-commit", - `${result.generator.options.pkg} lint-staged`, - ); + assertHuskyGitHooks({ pkg: result.generator.options.pkg }); }); it.skipIf(process.env.CI)( diff --git a/tests/python.test.ts b/tests/python.test.ts index 7f5bea0..f5b97a0 100644 --- a/tests/python.test.ts +++ b/tests/python.test.ts @@ -4,6 +4,13 @@ import assert from "yeoman-assert"; import helpers, { RunResult } from "yeoman-test"; import { describe, beforeAll, afterAll, expect, it } from "vitest"; import AppGenerator from "../src/app.js"; +import { + assertChangeLog, + assertContributing, + assertLicense, + assertOptionValues, + assertReadMe, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -70,15 +77,14 @@ describe("generator-norgate-av:python", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -90,35 +96,19 @@ describe("generator-norgate-av:python", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + assertContributing("CONTRIBUTING.md", { id }); }); it.skipIf(process.env.CI)( @@ -179,16 +169,14 @@ describe("generator-norgate-av:python", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); + assertOptionValues(result, { + type, + id, + name: destination, + description, + author, + git, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -200,35 +188,19 @@ describe("generator-norgate-av:python", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); + assertContributing("CONTRIBUTING.md", { id }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it.skipIf(process.env.CI)( @@ -276,11 +248,17 @@ describe("generator-norgate-av:python", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + id: "test-project", + name: destination, + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -292,44 +270,25 @@ describe("generator-norgate-av:python", () => { }); it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); - assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id: result.generator.options.id }); }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it.skipIf(process.env.CI)( diff --git a/tests/simpl.test.ts b/tests/simpl.test.ts index 61573e4..187971f 100644 --- a/tests/simpl.test.ts +++ b/tests/simpl.test.ts @@ -8,7 +8,16 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; -import { getNodeDependencyObject } from "./helpers.js"; +import { + assertAllContributorsRc, + assertChangeLog, + assertContributing, + assertHuskyGitHooks, + assertLicense, + assertOptionValues, + assertReadMe, + getNodeDependencyObject, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -126,22 +135,15 @@ describe("generator-norgate-av:simpl", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -157,6 +159,7 @@ describe("generator-norgate-av:simpl", () => { name: id, displayName: name, description, + author, engines: { node: `>=${engine}`, }, @@ -171,11 +174,7 @@ describe("generator-norgate-av:simpl", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -183,59 +182,26 @@ describe("generator-norgate-av:simpl", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -309,23 +275,15 @@ describe("generator-norgate-av:simpl", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name: destination, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -341,6 +299,7 @@ describe("generator-norgate-av:simpl", () => { name: id, displayName: destination, description, + author, engines: { node: `>=${engine}`, }, @@ -355,11 +314,7 @@ describe("generator-norgate-av:simpl", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -367,59 +322,26 @@ describe("generator-norgate-av:simpl", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -467,18 +389,18 @@ describe("generator-norgate-av:simpl", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); - assert.equal(result.generator.options.pkg, "pnpm"); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - "pnpm", - ); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + name: destination, + id: "test-project", + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + pkg: "pnpm", + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -494,6 +416,7 @@ describe("generator-norgate-av:simpl", () => { name: result.generator.options.id, displayName: destination, description: result.generator.options.description, + author: result.generator.options.author, engines: { node: `>=${engine}`, }, @@ -508,14 +431,7 @@ describe("generator-norgate-av:simpl", () => { }); it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); - assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id: result.generator.options.id }); }); it("should create the correct .nvmrc", () => { @@ -523,71 +439,33 @@ describe("generator-norgate-av:simpl", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} install`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${result.generator.options.pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${result.generator.options.pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + pkg: result.generator.options.pkg, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${result.generator.options.id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { + id: result.generator.options.id, + author: result.generator.options.author, + }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${result.generator.options.pkg} commitlint --edit $1`, - ); - assert.fileContent( - ".husky/pre-commit", - `${result.generator.options.pkg} lint-staged`, - ); + assertHuskyGitHooks({ pkg: result.generator.options.pkg }); }); it.skipIf(process.env.CI)( diff --git a/tests/typescript.test.ts b/tests/typescript.test.ts index a12462d..ce30679 100644 --- a/tests/typescript.test.ts +++ b/tests/typescript.test.ts @@ -8,7 +8,16 @@ import { NodeEnvironment } from "../src/environments/index.js"; import { ConfigHelper } from "../src/helpers/index.js"; import config from "../config/default.json"; import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js"; -import { getNodeDependencyObject } from "./helpers.js"; +import { + assertAllContributorsRc, + assertChangeLog, + assertContributing, + assertHuskyGitHooks, + assertLicense, + assertOptionValues, + assertReadMe, + getNodeDependencyObject, +} from "./helpers.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const generator = path.resolve(__dirname, "../dist/generators/app"); @@ -88,12 +97,6 @@ const files = [ "vitest.config.ts", ]; -// const lock = { -// pnpm: "pnpm-lock.yaml", -// npm: "package-lock.json", -// yarn: "yarn.lock", -// }; - describe("generator-norgate-av:typescript", () => { describe.each([ { @@ -153,22 +156,15 @@ describe("generator-norgate-av:typescript", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.name, name); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${name}' and CD into it`, () => { @@ -184,6 +180,7 @@ describe("generator-norgate-av:typescript", () => { name: id, displayName: name, description, + author, engines: { node: `>=${engine}`, }, @@ -206,11 +203,7 @@ describe("generator-norgate-av:typescript", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -218,59 +211,26 @@ describe("generator-norgate-av:typescript", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -286,44 +246,6 @@ describe("generator-norgate-av:typescript", () => { }, ); - // describe.skip("typescript:install", () => { - // let result: RunResult; - - // const name = "test"; - // const description = "test-description"; - // const pkg = "pnpm"; - - // beforeAll(async () => { - // result = await helpers - // .create(generator) - // .withOptions({ - // skipInstall: false, - // }) - // .withAnswers({ - // type: "typescript", - // name, - // description, - // git: false, - // pkg, - // openWith: "skip", - // }); - - // process.chdir(name); - // }, 200000); - - // afterAll(() => { - // result?.cleanup(); - // }); - - // it("should install packages using the correct package manager", () => { - // assert.file(lock[pkg]); - // }); - - // it("should always pass", () => { - // expect(1).toEqual(1); - // }); - // }); - describe.each([ { destination: "test", @@ -382,23 +304,15 @@ describe("generator-norgate-av:typescript", () => { }); it("should assign the correct values", () => { - assert.equal(result.generator.options.type, type); - assert.equal(result.generator.options.destination, destination); - assert.equal(result.generator.options.name, destination); - assert.equal(result.generator.options.id, id); - assert.equal(result.generator.options.description, description); - // assert.equal(result.generator.options.author, author); - assert.equal( - result.generator.options.git, - process.env.CI ? false : git, - ); - assert.equal(result.generator.options.pkg, pkg); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - pkg, - ); + assertOptionValues(result, { + type, + name: destination, + id, + description, + author, + git, + pkg: pkg as NodePackageManager, + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -414,6 +328,7 @@ describe("generator-norgate-av:typescript", () => { name: id, displayName: destination, description, + author, engines: { node: `>=${engine}`, }, @@ -436,11 +351,7 @@ describe("generator-norgate-av:typescript", () => { }); it("should create the correct README.md", () => { - assert.fileContent("README.md", `# ${id}`); - assert.fileContent( - "README.md", - `This is the README for your project "${id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id }); }); it("should create the correct .nvmrc", () => { @@ -448,59 +359,26 @@ describe("generator-norgate-av:typescript", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { author }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${id}/issues/new/choose`, - ); - assert.fileContent("CONTRIBUTING.md", `/${id}.git`); - assert.fileContent("CONTRIBUTING.md", `cd ${id}`); - assert.fileContent("CONTRIBUTING.md", `${pkg} install`); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id, + pkg: pkg as NodePackageManager, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { id }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { id, author }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${pkg} commitlint --edit $1`, - ); - assert.fileContent(".husky/pre-commit", `${pkg} lint-staged`); + assertHuskyGitHooks({ pkg: pkg as NodePackageManager }); }); it.skipIf(process.env.CI)( @@ -553,18 +431,18 @@ describe("generator-norgate-av:typescript", () => { result?.cleanup(); }); - it("should assign the correct default values", () => { - assert.equal(result.generator.options.id, "test-project"); - assert.equal(result.generator.options.description, ""); - assert.equal(result.generator.options.author, ""); - assert.equal(result.generator.options.git, !process.env.CI); - assert.equal(result.generator.options.pkg, "pnpm"); - assert.equal( - // @ts-expect-error This is necessary as the env 'options' property doesn't seem to be correctly typed on the Environment. - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - result.generator.env.options.nodePackageManager, - "pnpm", - ); + it("should assign the correct default values", async () => { + assertOptionValues(result, { + type, + name: destination, + id: "test-project", + description: "", + author: process.env.CI + ? "" + : (await result.generator.git.name()) || "", + git: !process.env.CI, + pkg: "pnpm", + }); }); it(`should create a directory named '${destination}' and CD into it`, () => { @@ -580,6 +458,7 @@ describe("generator-norgate-av:typescript", () => { name: result.generator.options.id, displayName: destination, description: result.generator.options.description, + author: result.generator.options.author, engines: { node: `>=${engine}`, }, @@ -602,14 +481,7 @@ describe("generator-norgate-av:typescript", () => { }); it("should create the correct README.md", () => { - assert.fileContent( - "README.md", - `# ${result.generator.options.id}`, - ); - assert.fileContent( - "README.md", - `This is the README for your project "${result.generator.options.id}". After writing up a brief description, we recommend including the following sections.`, - ); + assertReadMe("README.md", { id: result.generator.options.id }); }); it("should create the correct .nvmrc", () => { @@ -617,71 +489,33 @@ describe("generator-norgate-av:typescript", () => { }); it("should create the correct LICENSE", () => { - assert.fileContent("LICENSE", "The MIT License (MIT)"); - assert.fileContent( - "LICENSE", - `Copyright (c) ${new Date().getFullYear()}`, - ); + assertLicense("LICENSE", { + author: result.generator.options.author, + }); }); it("should create the correct CONTRIBUTING.md", () => { - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}/issues/new/choose`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `/${result.generator.options.id}.git`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `cd ${result.generator.options.id}`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} install`, - ); - assert.fileContent( - "CONTRIBUTING.md", - `If in doubt, you can use the \`${result.generator.options.pkg} commit\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Be sure to run \`${result.generator.options.pkg} test\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `Run the \`${result.generator.options.pkg} contrib:add\``, - ); - assert.fileContent( - "CONTRIBUTING.md", - `${result.generator.options.pkg} contrib:add `, - ); + assertContributing("CONTRIBUTING.md", { + id: result.generator.options.id, + pkg: result.generator.options.pkg, + }); }); it("should create the correct CHANGELOG.md", () => { - assert.fileContent( - "CHANGELOG.md", - `All notable changes to the "${result.generator.options.id}" project will be documented in this file.`, - ); + assertChangeLog("CHANGELOG.md", { + id: result.generator.options.id, + }); }); it("should create the correct .all-contributorsrc", () => { - assert.fileContent( - ".all-contributorsrc", - `"projectName": "${result.generator.options.id}"`, - ); + assertAllContributorsRc(".all-contributorsrc", { + id: result.generator.options.id, + author: result.generator.options.author, + }); }); it("should create the correct husky git hooks", () => { - assert.fileContent( - ".husky/commit-msg", - `${result.generator.options.pkg} commitlint --edit $1`, - ); - assert.fileContent( - ".husky/pre-commit", - `${result.generator.options.pkg} lint-staged`, - ); + assertHuskyGitHooks({ pkg: result.generator.options.pkg }); }); it.skipIf(process.env.CI)(