diff --git a/example/todo-list/package.json b/example/todo-list/package.json index 60d8430..94ac849 100644 --- a/example/todo-list/package.json +++ b/example/todo-list/package.json @@ -12,6 +12,6 @@ "dependencies": { "astro": "^4.1.2", "@astrojs/node": "^7.0.4", - "@jsheaven/astro-client-generator": "../../" + "@jsheaven/astro-client-generator": "^1.1.3" } } diff --git a/example/todo-list/src/pages/api-client/create-todo-client.ts b/example/todo-list/src/pages/api-client/create-todo-client.ts index 4856d48..e37c822 100644 --- a/example/todo-list/src/pages/api-client/create-todo-client.ts +++ b/example/todo-list/src/pages/api-client/create-todo-client.ts @@ -23,7 +23,7 @@ export interface ApiResponse { /** return (await fetch('/api/create-todo', { method: 'POST', ... })).json() */ export const createTodo = async (payload: ApiRequest, options: RequestOptions = {}): Promise => { - let requestUrl = 'https://Air-von-Aron.fritz.box--4321.local-credentialless.webcontainer.io/api/create-todo' + let requestUrl = 'http://127.0.0.1:4321/api/create-todo' if (options && options.query) { requestUrl += '?' + Object.keys(options.query) .map((key) => key + '=' + options.query![key]) diff --git a/example/todo-list/src/pages/api-client/get-todos-client.ts b/example/todo-list/src/pages/api-client/get-todos-client.ts index e0a8311..cc97f1d 100644 --- a/example/todo-list/src/pages/api-client/get-todos-client.ts +++ b/example/todo-list/src/pages/api-client/get-todos-client.ts @@ -23,7 +23,7 @@ export interface ApiResponse { /** return (await fetch('/api/get-todos', { method: 'GET', ... })).json() */ export const getTodos = async (options: RequestOptions = {}): Promise => { - let requestUrl = 'https://Air-von-Aron.fritz.box--4321.local-credentialless.webcontainer.io/api/get-todos' + let requestUrl = 'http://127.0.0.1:4321/api/get-todos' if (options && options.query) { requestUrl += '?' + Object.keys(options.query) .map((key) => key + '=' + options.query![key]) diff --git a/example/todo-list/src/pages/api-client/remove-todo-client.ts b/example/todo-list/src/pages/api-client/remove-todo-client.ts index 71efeec..ac1ec5a 100644 --- a/example/todo-list/src/pages/api-client/remove-todo-client.ts +++ b/example/todo-list/src/pages/api-client/remove-todo-client.ts @@ -25,7 +25,7 @@ export interface ApiResponse { /** return (await fetch('/api/remove-todo', { method: 'DELETE', ... })).json() */ export const removeTodo = async (payload: ApiRequest, options: RequestOptions = {}): Promise => { - let requestUrl = 'https://Air-von-Aron.fritz.box--4321.local-credentialless.webcontainer.io/api/remove-todo' + let requestUrl = 'http://127.0.0.1:4321/api/remove-todo' if (options && options.query) { requestUrl += '?' + Object.keys(options.query) .map((key) => key + '=' + options.query![key]) diff --git a/example/todo-list/src/pages/api-client/update-todo-client.ts b/example/todo-list/src/pages/api-client/update-todo-client.ts index 52b3cd1..d5e94da 100644 --- a/example/todo-list/src/pages/api-client/update-todo-client.ts +++ b/example/todo-list/src/pages/api-client/update-todo-client.ts @@ -23,7 +23,7 @@ export interface ApiResponse { /** return (await fetch('/api/update-todo', { method: 'PATCH', ... })).json() */ export const updateTodo = async (payload: ApiRequest, options: RequestOptions = {}): Promise => { - let requestUrl = 'https://Air-von-Aron.fritz.box--4321.local-credentialless.webcontainer.io/api/update-todo' + let requestUrl = 'http://127.0.0.1:4321/api/update-todo' if (options && options.query) { requestUrl += '?' + Object.keys(options.query) .map((key) => key + '=' + options.query![key]) diff --git a/example/todo-list/src/pages/index.astro b/example/todo-list/src/pages/index.astro index 37e7d90..777b5b7 100644 --- a/example/todo-list/src/pages/index.astro +++ b/example/todo-list/src/pages/index.astro @@ -57,7 +57,7 @@ const currentTodos = JSON.parse(readFileSync('./todos.json', 'utf-8')) isDone: false, task: addInput.value, }) - //document.location.reload() + document.location.reload() } addBtn.onclick = () => { @@ -83,7 +83,6 @@ const currentTodos = JSON.parse(readFileSync('./todos.json', 'utf-8')) todo.isDone = checkbox.checked await updateTodo(todo) - //document.location.reload() }), ) @@ -99,7 +98,7 @@ const currentTodos = JSON.parse(readFileSync('./todos.json', 'utf-8')) await removeTodo({ id: todo.id, }) - //document.location.reload() + document.location.reload() }), ) diff --git a/example/todo-list/todos.json b/example/todo-list/todos.json index b250366..215e279 100644 --- a/example/todo-list/todos.json +++ b/example/todo-list/todos.json @@ -1 +1 @@ -[{"id":1,"task":"Implement the code generator","isDone":true},{"id":2,"task":"Reach 100% code coverage with Jest unit tests","isDone":true},{"id":3,"task":"Make some devs out there happy","isDone":true},{"id":4,"task":"Practice acceptance for when haters gonna hate :)","isDone":true},{"id":5,"task":"asd","isDone":false}] \ No newline at end of file +[{"id":1,"task":"Implement the code generator","isDone":true},{"id":2,"task":"Reach 100% code coverage with Jest unit tests","isDone":true},{"id":3,"task":"Make some devs out there happy","isDone":true},{"id":4,"task":"asd","isDone":false}] \ No newline at end of file diff --git a/example/todo-list/yarn.lock b/example/todo-list/yarn.lock index 9999a70..ec10f56 100644 --- a/example/todo-list/yarn.lock +++ b/example/todo-list/yarn.lock @@ -476,9 +476,10 @@ "@jridgewell/sourcemap-codec" "1.4.14" "@jsheaven/astro-client-generator@../../": - version "1.1.1" + version "1.1.3" dependencies: chokidar "^3.5.3" + intermock "^0.2.5" kleur "^4.1.5" ts-morph "^21.0.1" yargs-parser "^21.1.1" @@ -724,6 +725,14 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +argv-tools@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/argv-tools/-/argv-tools-0.1.2.tgz#fc4918a70775b8cc5f8296fa0cfea137bd8a8229" + integrity sha512-wxqoymY0BEu9NblZVQiOTOAiJUjPhaa/kbNMjC2h6bnrmUSgnxKgWJo3lzXvi3bHJRwXyqK/dHzMlZVRT89Cxg== + dependencies: + array-back "^2.0.0" + find-replace "^2.0.1" + aria-query@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.3.0.tgz#650c569e41ad90b51b3d7df5e5eed1c7549c103e" @@ -731,6 +740,13 @@ aria-query@^5.3.0: dependencies: dequal "^2.0.3" +array-back@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/array-back/-/array-back-2.0.0.tgz#6877471d51ecc9c9bfa6136fb6c7d5fe69748022" + integrity sha512-eJv4pLLufP3g5kcZry0j6WXpIbzYw9GUB4mVJZno9wfwiBxbizTnHCw3VJb07cBihbFX48Y7oSrW9y+gt4glyw== + dependencies: + typical "^2.6.1" + array-iterate@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/array-iterate/-/array-iterate-2.0.1.tgz#6efd43f8295b3fee06251d3d62ead4bd9805dd24" @@ -931,7 +947,7 @@ ccount@^2.0.0: resolved "https://registry.yarnpkg.com/ccount/-/ccount-2.0.1.tgz#17a3bf82302e0870d6da43a01311a8bc02a3ecf5" integrity sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg== -chalk@^2.4.2: +chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -1067,6 +1083,27 @@ comma-separated-tokens@^2.0.0: resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz#4e89c9458acb61bc8fef19f4529973b2392839ee" integrity sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg== +command-line-args@5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-5.0.2.tgz#c4e56b016636af1323cf485aa25c3cb203dfbbe4" + integrity sha512-/qPcbL8zpqg53x4rAaqMFlRV4opN3pbla7I7k9x8kyOBMQoGT6WltjN6sXZuxOXw6DgdK7Ad+ijYS5gjcr7vlA== + dependencies: + argv-tools "^0.1.1" + array-back "^2.0.0" + find-replace "^2.0.1" + lodash.camelcase "^4.3.0" + typical "^2.6.1" + +command-line-usage@5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/command-line-usage/-/command-line-usage-5.0.5.tgz#5f25933ffe6dedd983c635d38a21d7e623fda357" + integrity sha512-d8NrGylA5oCXSbGoKz05FkehDAzSmIm4K03S5VDh4d5lZAtTWfc3D1RuETtuQCn8129nYfJfDdF7P/lwcz1BlA== + dependencies: + array-back "^2.0.0" + chalk "^2.4.1" + table-layout "^0.4.3" + typical "^2.6.1" + common-ancestor-path@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz#4f7d2d1394d91b7abdf51871c62f71eadb0182a7" @@ -1126,7 +1163,7 @@ decompress-response@^6.0.0: dependencies: mimic-response "^3.1.0" -deep-extend@^0.6.0: +deep-extend@^0.6.0, deep-extend@~0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== @@ -1345,6 +1382,11 @@ extend@^3.0.0: resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== +faker@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f" + integrity sha512-ILKg69P6y/D8/wSmDXw35Ly0re8QzQ8pMfBCflsGiZG2ZjMUNLYNexA6lz5pkmJlepVdsiDFUxYAzPQ9/+iGLA== + fast-fifo@^1.1.0, fast-fifo@^1.2.0: version "1.3.2" resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.3.2.tgz#286e31de96eb96d38a97899815740ba2a4f3640c" @@ -1375,6 +1417,14 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +find-replace@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/find-replace/-/find-replace-2.0.1.tgz#6d9683a7ca20f8f9aabeabad07e4e2580f528550" + integrity sha512-LzDo3Fpa30FLIBsh6DCDnMN1KW2g4QKkqKmejlImgWY67dDFPX/x9Kh/op/GK522DchQXEvDi/wD48HKW49XOQ== + dependencies: + array-back "^2.0.0" + test-value "^3.0.0" + find-up@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" @@ -1414,6 +1464,13 @@ fs-constants@^1.0.0: resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== +fs-readfile-promise@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/fs-readfile-promise/-/fs-readfile-promise-3.0.1.tgz#d0d307b7f6aedfc920c31fa6e5712efaa297c958" + integrity sha512-LsSxMeaJdYH27XrW7Dmq0Gx63mioULCRel63B5VeELYLavi1wF5s0XfsIdKDFdCL9hsfQ2qBvXJszQtQJ9h17A== + dependencies: + graceful-fs "^4.1.11" + fsevents@~2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" @@ -1466,6 +1523,11 @@ globals@^11.1.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== +graceful-fs@^4.1.11: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + graceful-fs@^4.1.5: version "4.2.10" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" @@ -1652,6 +1714,18 @@ ini@~1.3.0: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== +intermock@^0.2.5: + version "0.2.5" + resolved "https://registry.yarnpkg.com/intermock/-/intermock-0.2.5.tgz#9fbd2003d30f061e28f917fecf5e6fb21f539aae" + integrity sha512-vba3vpjgfi+7ZFoEeBp7dkCuICuDg4isXAU7JIEv4exar505v48ZuYe6KsS6E4TNbQaV3qd0Bb8DOAQY+M9CGg== + dependencies: + command-line-args "5.0.2" + command-line-usage "5.0.5" + faker "4.1.0" + fs-readfile-promise "3.0.1" + tslib "1.10.0" + typescript "^3.7.5" + is-arrayish@^0.3.1: version "0.3.2" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03" @@ -1816,11 +1890,21 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" +lodash.camelcase@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" + integrity sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA== + lodash.merge@^4.6.2: version "4.6.2" resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash.padend@^4.6.1: + version "4.6.1" + resolved "https://registry.yarnpkg.com/lodash.padend/-/lodash.padend-4.6.1.tgz#53ccba047d06e158d311f45da625f4e49e6f166e" + integrity sha512-sOQs2aqGpbl27tmCS1QNZA09Uqp01ZzWfDUoD+xzTii0E7dSQfRKcRetFwa+uXaxaqL+TKm7CgD2JdKP7aZBSw== + log-symbols@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-5.1.0.tgz#a20e3b9a5f53fac6aeb8e2bb22c07cf2c8f16d93" @@ -2714,6 +2798,11 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" +reduce-flatten@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/reduce-flatten/-/reduce-flatten-1.0.1.tgz#258c78efd153ddf93cb561237f61184f3696e327" + integrity sha512-j5WfFJfc9CoXv/WbwVLHq74i/hdTUpy+iNC534LxczMRP67vJeK3V9JOdnL0N1cIRbn9mYhE2yVjvvKXDxvNXQ== + rehype-parse@^9.0.0: version "9.0.0" resolved "https://registry.yarnpkg.com/rehype-parse/-/rehype-parse-9.0.0.tgz#3949faeec6f466ec57774215661e0d75469195d9" @@ -3171,6 +3260,17 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== +table-layout@^0.4.3: + version "0.4.5" + resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-0.4.5.tgz#d906de6a25fa09c0c90d1d08ecd833ecedcb7378" + integrity sha512-zTvf0mcggrGeTe/2jJ6ECkJHAQPIYEwDoqsiqBjI24mvRmQbInK5jq33fyypaCBxX08hMkfmdOqj6haT33EqWw== + dependencies: + array-back "^2.0.0" + deep-extend "~0.6.0" + lodash.padend "^4.6.1" + typical "^2.6.1" + wordwrapjs "^3.0.0" + tar-fs@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784" @@ -3210,6 +3310,14 @@ tar-stream@^3.1.5: fast-fifo "^1.2.0" streamx "^2.15.0" +test-value@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/test-value/-/test-value-3.0.0.tgz#9168c062fab11a86b8d444dd968bb4b73851ce92" + integrity sha512-sVACdAWcZkSU9x7AOmJo5TqE+GyNJknHaHsMrR6ZnhjVlVN9Yx6FjHrsKZ3BjIpPCT68zYesPWkakrNupwfOTQ== + dependencies: + array-back "^2.0.0" + typical "^2.6.1" + to-fast-properties@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" @@ -3250,6 +3358,11 @@ tsconfck@^3.0.0: resolved "https://registry.yarnpkg.com/tsconfck/-/tsconfck-3.0.1.tgz#803ca0ed8f2f2075639e4061238f04b99ba85e85" integrity sha512-7ppiBlF3UEddCLeI1JRx5m2Ryq+xk4JrZuq4EuYXykipebaq1dV0Fhgr1hb7CkmHt32QSgOZlcqVLEtHBG4/mg== +tslib@1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" + integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" @@ -3262,6 +3375,16 @@ type-fest@^2.13.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b" integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA== +typescript@^3.7.5: + version "3.9.10" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" + integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== + +typical@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/typical/-/typical-2.6.1.tgz#5c080e5d661cbbe38259d2e70a3c7253e873881d" + integrity sha512-ofhi8kjIje6npGozTip9Fr8iecmYfEbS06i0JnIg+rh51KakryWF4+jX8lLKZVhy6N+ID45WYSFCxPOdTWCzNg== + unherit@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/unherit/-/unherit-3.0.1.tgz#65b98bb7cb58cee755d7ec699a49e9e8ff172e23" @@ -3487,6 +3610,14 @@ widest-line@^4.0.1: dependencies: string-width "^5.0.1" +wordwrapjs@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/wordwrapjs/-/wordwrapjs-3.0.0.tgz#c94c372894cadc6feb1a66bff64e1d9af92c5d1e" + integrity sha512-mO8XtqyPvykVCsrwj5MlOVWvSnCdT+C+QVbm6blradR7JExAhbkZ7hZ9A+9NUtwzSqrlUo9a67ws0EiILrvRpw== + dependencies: + reduce-flatten "^1.0.1" + typical "^2.6.1" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" diff --git a/package.json b/package.json index 53f5469..746a26b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsheaven/astro-client-generator", - "version": "1.1.2", + "version": "1.1.3", "type": "module", "publishConfig": { "access": "public" diff --git a/src/index.ts b/src/index.ts index 4c04d5d..522914a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,7 +83,17 @@ export const apiClientGenerator = ( return { name: 'astro-client-generator', hooks: { - 'astro:config:setup': async () => { + + 'astro:server:start': async ({ address }) => { + + const actualSite = address.family === 'IPv4' ? + `http://${address.address}:${address.port}` : + `http://[${address.address}]:${address.port}` + + if (apiGeneratorOptions.site && apiGeneratorOptions.site !== actualSite) { + console.log(`🔄 Endpoint host has changed to ${actualSite}. Updating site accordingly.`) + apiGeneratorOptions.site = actualSite + } const watcher = watch(apiGeneratorOptions.apiDir, { ignoreInitial: true, @@ -107,14 +117,17 @@ export const apiClientGenerator = ( if (stats.ctimeMs + 100 > Date.now()) { return } + console.log('🖊️ Endpoint added: ', path) generateClientApis(apiGeneratorOptions) }) - + // initial build generateClientApis(apiGeneratorOptions) }, - 'astro:build:done': async () => { + + 'astro:build:setup': async () => { + // eager generation for initial imports to work well generateClientApis(apiGeneratorOptions) }, }, @@ -360,6 +373,7 @@ export const generateClientApis = (apiGeneratorOptions: ApiClientGeneratorOption // so that we end up with one client code file for one endpoint code file and not override // code by previous code generation attempts const perRoute = groupByApiRoute(apiRouteParseResults as Array) + const codeFiles: Array = [] // invoke codegen per route Object.keys(perRoute).forEach((apiRoute) => { @@ -373,6 +387,7 @@ export const generateClientApis = (apiGeneratorOptions: ApiClientGeneratorOption const parsed = parse(clientFilePath) const clientFileDir = parsed.dir const finalFilePath = `${clientFileDir}${sep}${parsed.name}-client.ts`.toLowerCase() + codeFiles.push(finalFilePath) const project = new Project({ tsConfigFilePath: apiGeneratorOptions.tsConfigPath, @@ -395,13 +410,6 @@ export const generateClientApis = (apiGeneratorOptions: ApiClientGeneratorOption sourceFile.organizeImports(); sourceFile.formatText(); sourceFile.saveSync(); - - // final formatting - const code = readFileSync(finalFilePath, { encoding: 'utf-8' }) - // remove all double-blank lines (non-trivial to do using ts-morph) - const formattedCode = code.replace(/^\n\n$/g, '\n') - // remove all blank lines before opening brackets - writeFileSync(finalFilePath, formattedCode, { encoding: 'utf-8' }) }) console.log('🚀 Finished building endpoint clients.') diff --git a/test/astroClientGenerator.test.ts b/test/astroClientGenerator.test.ts index 61dde3e..0c466a1 100644 --- a/test/astroClientGenerator.test.ts +++ b/test/astroClientGenerator.test.ts @@ -388,8 +388,8 @@ describe('apiClientGenerator', () => { expect(result).toEqual({ name: 'astro-client-generator', hooks: { - 'astro:config:setup': expect.any(Function), - 'astro:build:done': expect.any(Function), + 'astro:server:start': expect.any(Function), + 'astro:build:setup': expect.any(Function), }, }) }) @@ -407,8 +407,8 @@ describe('apiClientGenerator', () => { expect(result).toEqual({ name: 'astro-client-generator', hooks: { - 'astro:config:setup': expect.any(Function), - 'astro:build:done': expect.any(Function), + 'astro:server:start': expect.any(Function), + 'astro:build:setup': expect.any(Function), }, }) }) @@ -427,8 +427,8 @@ describe('apiClientGenerator', () => { expect(result).toEqual({ name: 'astro-client-generator', hooks: { - 'astro:config:setup': expect.any(Function), - 'astro:build:done': expect.any(Function), + 'astro:server:start': expect.any(Function), + 'astro:build:setup': expect.any(Function), }, }) expect(apiGeneratorOptions.site).toEqual('foobar2') diff --git a/yarn.lock b/yarn.lock index cdf21f7..3b0434f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1455,6 +1455,14 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +argv-tools@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/argv-tools/-/argv-tools-0.1.2.tgz#fc4918a70775b8cc5f8296fa0cfea137bd8a8229" + integrity sha512-wxqoymY0BEu9NblZVQiOTOAiJUjPhaa/kbNMjC2h6bnrmUSgnxKgWJo3lzXvi3bHJRwXyqK/dHzMlZVRT89Cxg== + dependencies: + array-back "^2.0.0" + find-replace "^2.0.1" + aria-query@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.3.0.tgz#650c569e41ad90b51b3d7df5e5eed1c7549c103e" @@ -1462,6 +1470,13 @@ aria-query@^5.3.0: dependencies: dequal "^2.0.3" +array-back@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/array-back/-/array-back-2.0.0.tgz#6877471d51ecc9c9bfa6136fb6c7d5fe69748022" + integrity sha512-eJv4pLLufP3g5kcZry0j6WXpIbzYw9GUB4mVJZno9wfwiBxbizTnHCw3VJb07cBihbFX48Y7oSrW9y+gt4glyw== + dependencies: + typical "^2.6.1" + array-iterate@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/array-iterate/-/array-iterate-2.0.1.tgz#6efd43f8295b3fee06251d3d62ead4bd9805dd24" @@ -1786,7 +1801,7 @@ ccount@^2.0.0: resolved "https://registry.yarnpkg.com/ccount/-/ccount-2.0.1.tgz#17a3bf82302e0870d6da43a01311a8bc02a3ecf5" integrity sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg== -chalk@^2.0.0, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -1964,6 +1979,27 @@ comma-separated-tokens@^2.0.0: resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz#4e89c9458acb61bc8fef19f4529973b2392839ee" integrity sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg== +command-line-args@5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-5.0.2.tgz#c4e56b016636af1323cf485aa25c3cb203dfbbe4" + integrity sha512-/qPcbL8zpqg53x4rAaqMFlRV4opN3pbla7I7k9x8kyOBMQoGT6WltjN6sXZuxOXw6DgdK7Ad+ijYS5gjcr7vlA== + dependencies: + argv-tools "^0.1.1" + array-back "^2.0.0" + find-replace "^2.0.1" + lodash.camelcase "^4.3.0" + typical "^2.6.1" + +command-line-usage@5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/command-line-usage/-/command-line-usage-5.0.5.tgz#5f25933ffe6dedd983c635d38a21d7e623fda357" + integrity sha512-d8NrGylA5oCXSbGoKz05FkehDAzSmIm4K03S5VDh4d5lZAtTWfc3D1RuETtuQCn8129nYfJfDdF7P/lwcz1BlA== + dependencies: + array-back "^2.0.0" + chalk "^2.4.1" + table-layout "^0.4.3" + typical "^2.6.1" + common-ancestor-path@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz#4f7d2d1394d91b7abdf51871c62f71eadb0182a7" @@ -2038,7 +2074,7 @@ dedent@^0.7.0: resolved "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz" integrity sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA== -deep-extend@^0.6.0: +deep-extend@^0.6.0, deep-extend@~0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== @@ -2349,6 +2385,11 @@ extend@^3.0.0: resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== +faker@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f" + integrity sha512-ILKg69P6y/D8/wSmDXw35Ly0re8QzQ8pMfBCflsGiZG2ZjMUNLYNexA6lz5pkmJlepVdsiDFUxYAzPQ9/+iGLA== + fast-fifo@^1.1.0, fast-fifo@^1.2.0: version "1.3.2" resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.3.2.tgz#286e31de96eb96d38a97899815740ba2a4f3640c" @@ -2402,6 +2443,14 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +find-replace@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/find-replace/-/find-replace-2.0.1.tgz#6d9683a7ca20f8f9aabeabad07e4e2580f528550" + integrity sha512-LzDo3Fpa30FLIBsh6DCDnMN1KW2g4QKkqKmejlImgWY67dDFPX/x9Kh/op/GK522DchQXEvDi/wD48HKW49XOQ== + dependencies: + array-back "^2.0.0" + test-value "^3.0.0" + find-up@^4.0.0, find-up@^4.1.0: version "4.1.0" resolved "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz" @@ -2436,6 +2485,13 @@ fs-constants@^1.0.0: resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== +fs-readfile-promise@3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/fs-readfile-promise/-/fs-readfile-promise-3.0.1.tgz#d0d307b7f6aedfc920c31fa6e5712efaa297c958" + integrity sha512-LsSxMeaJdYH27XrW7Dmq0Gx63mioULCRel63B5VeELYLavi1wF5s0XfsIdKDFdCL9hsfQ2qBvXJszQtQJ9h17A== + dependencies: + graceful-fs "^4.1.11" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" @@ -2525,6 +2581,11 @@ globals@^11.1.0: resolved "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== +graceful-fs@^4.1.11: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + graceful-fs@^4.1.5, graceful-fs@^4.2.9: version "4.2.10" resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz" @@ -2750,6 +2811,18 @@ ini@~1.3.0: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== +intermock@^0.2.5: + version "0.2.5" + resolved "https://registry.yarnpkg.com/intermock/-/intermock-0.2.5.tgz#9fbd2003d30f061e28f917fecf5e6fb21f539aae" + integrity sha512-vba3vpjgfi+7ZFoEeBp7dkCuICuDg4isXAU7JIEv4exar505v48ZuYe6KsS6E4TNbQaV3qd0Bb8DOAQY+M9CGg== + dependencies: + command-line-args "5.0.2" + command-line-usage "5.0.5" + faker "4.1.0" + fs-readfile-promise "3.0.1" + tslib "1.10.0" + typescript "^3.7.5" + is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz" @@ -3407,6 +3480,11 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" +lodash.camelcase@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" + integrity sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA== + lodash.memoize@4.x: version "4.1.2" resolved "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz" @@ -3417,6 +3495,11 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash.padend@^4.6.1: + version "4.6.1" + resolved "https://registry.yarnpkg.com/lodash.padend/-/lodash.padend-4.6.1.tgz#53ccba047d06e158d311f45da625f4e49e6f166e" + integrity sha512-sOQs2aqGpbl27tmCS1QNZA09Uqp01ZzWfDUoD+xzTii0E7dSQfRKcRetFwa+uXaxaqL+TKm7CgD2JdKP7aZBSw== + log-symbols@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-5.1.0.tgz#a20e3b9a5f53fac6aeb8e2bb22c07cf2c8f16d93" @@ -4389,6 +4472,11 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" +reduce-flatten@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/reduce-flatten/-/reduce-flatten-1.0.1.tgz#258c78efd153ddf93cb561237f61184f3696e327" + integrity sha512-j5WfFJfc9CoXv/WbwVLHq74i/hdTUpy+iNC534LxczMRP67vJeK3V9JOdnL0N1cIRbn9mYhE2yVjvvKXDxvNXQ== + rehype-parse@^9.0.0: version "9.0.0" resolved "https://registry.yarnpkg.com/rehype-parse/-/rehype-parse-9.0.0.tgz#3949faeec6f466ec57774215661e0d75469195d9" @@ -4922,6 +5010,17 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== +table-layout@^0.4.3: + version "0.4.5" + resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-0.4.5.tgz#d906de6a25fa09c0c90d1d08ecd833ecedcb7378" + integrity sha512-zTvf0mcggrGeTe/2jJ6ECkJHAQPIYEwDoqsiqBjI24mvRmQbInK5jq33fyypaCBxX08hMkfmdOqj6haT33EqWw== + dependencies: + array-back "^2.0.0" + deep-extend "~0.6.0" + lodash.padend "^4.6.1" + typical "^2.6.1" + wordwrapjs "^3.0.0" + tar-fs@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784" @@ -4970,6 +5069,14 @@ test-exclude@^6.0.0: glob "^7.1.4" minimatch "^3.0.4" +test-value@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/test-value/-/test-value-3.0.0.tgz#9168c062fab11a86b8d444dd968bb4b73851ce92" + integrity sha512-sVACdAWcZkSU9x7AOmJo5TqE+GyNJknHaHsMrR6ZnhjVlVN9Yx6FjHrsKZ3BjIpPCT68zYesPWkakrNupwfOTQ== + dependencies: + array-back "^2.0.0" + typical "^2.6.1" + tmpl@1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz" @@ -5024,6 +5131,11 @@ tsconfck@^3.0.0: resolved "https://registry.yarnpkg.com/tsconfck/-/tsconfck-3.0.1.tgz#803ca0ed8f2f2075639e4061238f04b99ba85e85" integrity sha512-7ppiBlF3UEddCLeI1JRx5m2Ryq+xk4JrZuq4EuYXykipebaq1dV0Fhgr1hb7CkmHt32QSgOZlcqVLEtHBG4/mg== +tslib@1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" + integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" @@ -5046,11 +5158,21 @@ type-fest@^2.13.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b" integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA== +typescript@^3.7.5: + version "3.9.10" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" + integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== + typescript@^4.9.5: version "4.9.5" resolved "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz" integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typical@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/typical/-/typical-2.6.1.tgz#5c080e5d661cbbe38259d2e70a3c7253e873881d" + integrity sha512-ofhi8kjIje6npGozTip9Fr8iecmYfEbS06i0JnIg+rh51KakryWF4+jX8lLKZVhy6N+ID45WYSFCxPOdTWCzNg== + unherit@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/unherit/-/unherit-3.0.1.tgz#65b98bb7cb58cee755d7ec699a49e9e8ff172e23" @@ -5300,6 +5422,14 @@ widest-line@^4.0.1: dependencies: string-width "^5.0.1" +wordwrapjs@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/wordwrapjs/-/wordwrapjs-3.0.0.tgz#c94c372894cadc6feb1a66bff64e1d9af92c5d1e" + integrity sha512-mO8XtqyPvykVCsrwj5MlOVWvSnCdT+C+QVbm6blradR7JExAhbkZ7hZ9A+9NUtwzSqrlUo9a67ws0EiILrvRpw== + dependencies: + reduce-flatten "^1.0.1" + typical "^2.6.1" + wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"