├── .gitignore ├── .scalafmt.conf ├── LICENSE ├── README.md ├── build.sbt ├── package-lock.json ├── package.json ├── project ├── build.properties └── plugins.sbt └── src └── main └── scala └── dex ├── LibName.scala ├── buildTool.scala ├── clipboard.scala ├── fetch.scala ├── main.scala ├── prompts.scala ├── scaladex.scala └── util.scala /.gitignore: -------------------------------------------------------------------------------- 1 | #mill 2 | out 3 | 4 | # sbt 5 | lib_managed 6 | project/project 7 | target 8 | 9 | # Eclipse 10 | .cache* 11 | .classpath 12 | .project 13 | .scala_dependencies 14 | .settings 15 | .target 16 | .worksheet 17 | 18 | # IntelliJ 19 | .idea 20 | .idea_modules 21 | *.iml 22 | 23 | # ENSIME 24 | .ensime 25 | .ensime_lucene 26 | .ensime_cache 27 | 28 | # Mac 29 | .DS_Store 30 | 31 | # Akka Persistence 32 | journal 33 | snapshots 34 | 35 | # Log files 36 | *.log 37 | 38 | #Floobits 39 | .floo 40 | 41 | # Local Dynamo DB 42 | dynamodb_lib 43 | *.db 44 | 45 | # Node 46 | node_modules 47 | website/translated_docs 48 | website/build/ 49 | website/yarn.lock 50 | website/node_modules 51 | website/i18n/* 52 | 53 | .bloop 54 | .vscode 55 | .history 56 | .metals 57 | project/metals.sbt 58 | .ammonite 59 | 60 | # Version file 61 | version 62 | 63 | # BSP files 64 | .bsp 65 | 66 | .direnv 67 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version = "3.5.9" 2 | runner.dialect = scala3 3 | fileOverride { 4 | "glob:**/scaladex/src/**" { 5 | runner.dialect = scala3 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## dexsearch 2 | 3 | This humble CLI lets you search for Scala libraries via Scaladex, and stores them in your clipboard, well formatted, ready to paste in build files and scripts. 4 | 5 | ## Installation 6 | 7 | Requires nodejs/npm installed. 8 | 9 | ``` 10 | npm install dexsearch -g 11 | ``` 12 | 13 | ### Example commands 14 | 15 | ```bash 16 | $ dexsearch 17 | $ dexsearch --help 18 | $ dexsearch --build-tool mill fs2 19 | $ dexsearch -b sbt decline 20 | ``` 21 | 22 | ## Demo 23 | 24 | ![2023-01-07 09 48 19](https://user-images.githubusercontent.com/1052965/211144583-27fd93c2-ad63-4386-9dc9-4d8e749ec185.gif) 25 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | import org.scalajs.linker.interface.StandardConfig 2 | enablePlugins(ScalaJSPlugin) 3 | enablePlugins(NpmPackagePlugin) 4 | 5 | name := "dexsearch" 6 | version := "0.1.5" 7 | 8 | scalaVersion := "3.2.1" // or any other Scala version >= 2.11.12 9 | 10 | libraryDependencies ++= Seq( 11 | "com.monovore" %%% "decline-effect" % "2.4.1" 12 | ) 13 | 14 | // This is an application with a main method 15 | scalaJSUseMainModuleInitializer := true 16 | Compile / scalaJSLinkerConfig := { 17 | val c = scalaJSLinkerConfig.value 18 | c.withModuleKind(ModuleKind.ESModule).withJSHeader("#!/usr/bin/env node\n") 19 | } 20 | licenses := Seq(License.Apache2) 21 | 22 | npmPackageAuthor := "Neandertech" 23 | npmPackageDescription := "CLI that uses the Scaladex API to quickly search libraries and copy them to the clipboard" 24 | npmPackageName := "dexsearch" 25 | npmPackageNpmrcScope := Some("neandertech") 26 | npmPackageBinaryEnable := true 27 | npmPackageDependencies ++= { 28 | Seq( 29 | "node-fetch" -> "^2.6.1", 30 | "prompts" -> "^2.4.2", 31 | "clipboardy" -> "^3.0.0" 32 | ) 33 | } 34 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scaladex-search", 3 | "lockfileVersion": 3, 4 | "requires": true, 5 | "packages": { 6 | "": { 7 | "dependencies": { 8 | "clipboardy": "^3.0.0", 9 | "node-fetch": "^2.6.7", 10 | "prompts": "^2.4.2" 11 | } 12 | }, 13 | "node_modules/arch": { 14 | "version": "2.2.0", 15 | "resolved": "https://registry.npmjs.org/arch/-/arch-2.2.0.tgz", 16 | "integrity": "sha512-Of/R0wqp83cgHozfIYLbBMnej79U/SVGOOyuB3VVFv1NRM/PSFMK12x9KVtiYzJqmnU5WR2qp0Z5rHb7sWGnFQ==", 17 | "funding": [ 18 | { 19 | "type": "github", 20 | "url": "https://github.com/sponsors/feross" 21 | }, 22 | { 23 | "type": "patreon", 24 | "url": "https://www.patreon.com/feross" 25 | }, 26 | { 27 | "type": "consulting", 28 | "url": "https://feross.org/support" 29 | } 30 | ] 31 | }, 32 | "node_modules/clipboardy": { 33 | "version": "3.0.0", 34 | "resolved": "https://registry.npmjs.org/clipboardy/-/clipboardy-3.0.0.tgz", 35 | "integrity": "sha512-Su+uU5sr1jkUy1sGRpLKjKrvEOVXgSgiSInwa/qeID6aJ07yh+5NWc3h2QfjHjBnfX4LhtFcuAWKUsJ3r+fjbg==", 36 | "dependencies": { 37 | "arch": "^2.2.0", 38 | "execa": "^5.1.1", 39 | "is-wsl": "^2.2.0" 40 | }, 41 | "engines": { 42 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 43 | }, 44 | "funding": { 45 | "url": "https://github.com/sponsors/sindresorhus" 46 | } 47 | }, 48 | "node_modules/cross-spawn": { 49 | "version": "7.0.3", 50 | "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", 51 | "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", 52 | "dependencies": { 53 | "path-key": "^3.1.0", 54 | "shebang-command": "^2.0.0", 55 | "which": "^2.0.1" 56 | }, 57 | "engines": { 58 | "node": ">= 8" 59 | } 60 | }, 61 | "node_modules/execa": { 62 | "version": "5.1.1", 63 | "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", 64 | "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", 65 | "dependencies": { 66 | "cross-spawn": "^7.0.3", 67 | "get-stream": "^6.0.0", 68 | "human-signals": "^2.1.0", 69 | "is-stream": "^2.0.0", 70 | "merge-stream": "^2.0.0", 71 | "npm-run-path": "^4.0.1", 72 | "onetime": "^5.1.2", 73 | "signal-exit": "^3.0.3", 74 | "strip-final-newline": "^2.0.0" 75 | }, 76 | "engines": { 77 | "node": ">=10" 78 | }, 79 | "funding": { 80 | "url": "https://github.com/sindresorhus/execa?sponsor=1" 81 | } 82 | }, 83 | "node_modules/get-stream": { 84 | "version": "6.0.1", 85 | "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", 86 | "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", 87 | "engines": { 88 | "node": ">=10" 89 | }, 90 | "funding": { 91 | "url": "https://github.com/sponsors/sindresorhus" 92 | } 93 | }, 94 | "node_modules/human-signals": { 95 | "version": "2.1.0", 96 | "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", 97 | "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", 98 | "engines": { 99 | "node": ">=10.17.0" 100 | } 101 | }, 102 | "node_modules/is-docker": { 103 | "version": "2.2.1", 104 | "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", 105 | "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", 106 | "bin": { 107 | "is-docker": "cli.js" 108 | }, 109 | "engines": { 110 | "node": ">=8" 111 | }, 112 | "funding": { 113 | "url": "https://github.com/sponsors/sindresorhus" 114 | } 115 | }, 116 | "node_modules/is-stream": { 117 | "version": "2.0.1", 118 | "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", 119 | "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", 120 | "engines": { 121 | "node": ">=8" 122 | }, 123 | "funding": { 124 | "url": "https://github.com/sponsors/sindresorhus" 125 | } 126 | }, 127 | "node_modules/is-wsl": { 128 | "version": "2.2.0", 129 | "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", 130 | "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", 131 | "dependencies": { 132 | "is-docker": "^2.0.0" 133 | }, 134 | "engines": { 135 | "node": ">=8" 136 | } 137 | }, 138 | "node_modules/isexe": { 139 | "version": "2.0.0", 140 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", 141 | "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" 142 | }, 143 | "node_modules/kleur": { 144 | "version": "3.0.3", 145 | "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", 146 | "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", 147 | "engines": { 148 | "node": ">=6" 149 | } 150 | }, 151 | "node_modules/merge-stream": { 152 | "version": "2.0.0", 153 | "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", 154 | "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" 155 | }, 156 | "node_modules/mimic-fn": { 157 | "version": "2.1.0", 158 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", 159 | "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", 160 | "engines": { 161 | "node": ">=6" 162 | } 163 | }, 164 | "node_modules/node-fetch": { 165 | "version": "2.6.7", 166 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", 167 | "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", 168 | "dependencies": { 169 | "whatwg-url": "^5.0.0" 170 | }, 171 | "engines": { 172 | "node": "4.x || >=6.0.0" 173 | }, 174 | "peerDependencies": { 175 | "encoding": "^0.1.0" 176 | }, 177 | "peerDependenciesMeta": { 178 | "encoding": { 179 | "optional": true 180 | } 181 | } 182 | }, 183 | "node_modules/npm-run-path": { 184 | "version": "4.0.1", 185 | "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", 186 | "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", 187 | "dependencies": { 188 | "path-key": "^3.0.0" 189 | }, 190 | "engines": { 191 | "node": ">=8" 192 | } 193 | }, 194 | "node_modules/onetime": { 195 | "version": "5.1.2", 196 | "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", 197 | "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", 198 | "dependencies": { 199 | "mimic-fn": "^2.1.0" 200 | }, 201 | "engines": { 202 | "node": ">=6" 203 | }, 204 | "funding": { 205 | "url": "https://github.com/sponsors/sindresorhus" 206 | } 207 | }, 208 | "node_modules/path-key": { 209 | "version": "3.1.1", 210 | "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", 211 | "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", 212 | "engines": { 213 | "node": ">=8" 214 | } 215 | }, 216 | "node_modules/prompts": { 217 | "version": "2.4.2", 218 | "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", 219 | "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", 220 | "dependencies": { 221 | "kleur": "^3.0.3", 222 | "sisteransi": "^1.0.5" 223 | }, 224 | "engines": { 225 | "node": ">= 6" 226 | } 227 | }, 228 | "node_modules/shebang-command": { 229 | "version": "2.0.0", 230 | "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", 231 | "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", 232 | "dependencies": { 233 | "shebang-regex": "^3.0.0" 234 | }, 235 | "engines": { 236 | "node": ">=8" 237 | } 238 | }, 239 | "node_modules/shebang-regex": { 240 | "version": "3.0.0", 241 | "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", 242 | "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", 243 | "engines": { 244 | "node": ">=8" 245 | } 246 | }, 247 | "node_modules/signal-exit": { 248 | "version": "3.0.7", 249 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", 250 | "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" 251 | }, 252 | "node_modules/sisteransi": { 253 | "version": "1.0.5", 254 | "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", 255 | "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" 256 | }, 257 | "node_modules/strip-final-newline": { 258 | "version": "2.0.0", 259 | "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", 260 | "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", 261 | "engines": { 262 | "node": ">=6" 263 | } 264 | }, 265 | "node_modules/tr46": { 266 | "version": "0.0.3", 267 | "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", 268 | "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" 269 | }, 270 | "node_modules/webidl-conversions": { 271 | "version": "3.0.1", 272 | "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", 273 | "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" 274 | }, 275 | "node_modules/whatwg-url": { 276 | "version": "5.0.0", 277 | "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", 278 | "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", 279 | "dependencies": { 280 | "tr46": "~0.0.3", 281 | "webidl-conversions": "^3.0.0" 282 | } 283 | }, 284 | "node_modules/which": { 285 | "version": "2.0.2", 286 | "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", 287 | "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", 288 | "dependencies": { 289 | "isexe": "^2.0.0" 290 | }, 291 | "bin": { 292 | "node-which": "bin/node-which" 293 | }, 294 | "engines": { 295 | "node": ">= 8" 296 | } 297 | } 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "dependencies": { 4 | "clipboardy": "^3.0.0", 5 | "node-fetch": "^2.6.7", 6 | "prompts": "^2.4.2" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.8.2 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta40") 2 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.12.0") 3 | addSbtPlugin("io.chrisdavenport" % "sbt-npm-package" % "0.1.2") 4 | -------------------------------------------------------------------------------- /src/main/scala/dex/LibName.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import com.monovore.decline.Argument 4 | import cats.data.ValidatedNel 5 | import cats.data.Validated.Valid 6 | import com.monovore.decline.Opts 7 | 8 | case class LibName(value: String) 9 | object LibName: 10 | val argument: Opts[Option[LibName]] = 11 | Opts 12 | .argument[String]("name of the library to search") 13 | .map(LibName(_)) 14 | .orNone 15 | -------------------------------------------------------------------------------- /src/main/scala/dex/buildTool.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import cats.data.ValidatedNel 4 | import cats.syntax.all._ 5 | import com.monovore.decline.Opts 6 | 7 | enum BuildTool: 8 | case SBT 9 | case Mill 10 | case Bleep 11 | case ScalaCLI 12 | case Ammonite 13 | 14 | object BuildTool: 15 | 16 | val metavar: String = s"[${BuildTool.values.mkString(", ")}]" 17 | 18 | def fromString(str: String): ValidatedNel[String, BuildTool] = 19 | str.toLowerCase() match 20 | case "sbt" => BuildTool.SBT.valid 21 | case "mill" => BuildTool.Mill.valid 22 | case "bleep" => BuildTool.Bleep.valid 23 | case "scalacli" | "cli" => BuildTool.ScalaCLI.valid 24 | case "amm" | "ammonite" => BuildTool.ScalaCLI.valid 25 | case other => 26 | s"Unkown build tool, expected one of [${BuildTool.values.mkString(", ")}]".invalidNel 27 | 28 | val opt: Opts[Option[BuildTool]] = Opts 29 | .option[String]( 30 | long = "build-tool", 31 | short = "b", 32 | help = "Build tool that receives the dependency", 33 | metavar = metavar 34 | ) 35 | .mapValidated[BuildTool](fromString) 36 | .orNone 37 | 38 | end BuildTool 39 | -------------------------------------------------------------------------------- /src/main/scala/dex/clipboard.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSImport 5 | import cats.effect.IO 6 | 7 | @JSImport("clipboardy", JSImport.Namespace) 8 | @js.native 9 | object clipboardy extends js.Object: 10 | val default: Clipboard = js.native 11 | 12 | @js.native 13 | trait Clipboard extends js.Any: 14 | def write(s: String): js.Promise[Unit] = js.native 15 | 16 | def copyToClipboard(lines: Seq[String]): IO[Unit] = IO.fromPromise { 17 | IO { 18 | clipboardy.default.write(lines.mkString(System.lineSeparator())) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/scala/dex/fetch.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSImport 5 | import cats.effect.IO 6 | 7 | @JSImport("node-fetch", JSImport.Default) 8 | @js.native 9 | object fetch extends js.Function1[String, js.Thenable[FetchResponse]]: 10 | override def apply(arg1: String): js.Thenable[FetchResponse] = js.native 11 | 12 | trait FetchResponse extends js.Object: 13 | def status: Int 14 | def json(): js.Thenable[js.Any] 15 | def text(): js.Thenable[String] 16 | 17 | object ioFetch: 18 | def get(url: String): IO[IOFetchResponse] = 19 | IO.fromThenable(IO(fetch(url))).map(IOFetchResponse(_)) 20 | 21 | case class IOFetchResponse(underlying: FetchResponse): 22 | export underlying.status 23 | 24 | def json: IO[js.Any] = IO.fromThenable(IO(underlying.json())) 25 | def text: IO[String] = IO.fromThenable(IO(underlying.text())) 26 | -------------------------------------------------------------------------------- /src/main/scala/dex/main.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSImport 5 | 6 | // @main 7 | def main() = println(util.inspect(prompts.default)) 8 | 9 | import scala.scalajs.js 10 | import scala.scalajs.js.JSConverters._ 11 | import scala.util.Success 12 | import scala.util.Failure 13 | import com.monovore.decline.CommandApp 14 | import com.monovore.decline.Opts 15 | import cats.syntax.all._ 16 | import com.monovore.decline.effect.CommandIOApp 17 | import cats.effect.IO 18 | import cats.effect.ExitCode 19 | 20 | object Main 21 | extends CommandIOApp("dex", "searches scaladex for Scala libraries"): 22 | 23 | val doneMessage = "Dependencies were copied to your clipboard, ready to paste" 24 | 25 | def main = (BuildTool.opt, LibName.argument).mapN { 26 | (maybeBuildTool, maybeLibName) => 27 | for 28 | libName <- maybeLibName.map(IO.pure(_)).getOrElse(promptLibName) 29 | projects <- scaladex.search(libName.value) 30 | project <- promptProject(projects) 31 | modules <- promptModules(project) 32 | details <- scaladex.project(project.organization, project.repository) 33 | version <- promptVersion(details) 34 | buildTool <- maybeBuildTool.map(IO.pure(_)).getOrElse(promptBuildTool) 35 | content = format(buildTool, details.groupId, modules, version) 36 | _ <- copyToClipboard(content) 37 | _ <- IO.println(doneMessage) 38 | yield ExitCode(0) 39 | } 40 | end main 41 | 42 | def format( 43 | buildTool: BuildTool, 44 | groupId: String, 45 | modules: js.Array[String], 46 | version: String 47 | ): List[String] = modules.toList.map { case module => 48 | buildTool match 49 | case BuildTool.SBT => s""""$groupId" %% "$module" % "$version"""" 50 | case BuildTool.Mill => s"""ivy"$groupId::$module:$version"""" 51 | case BuildTool.Bleep => s"""$groupId::$module:$version""" 52 | case BuildTool.ScalaCLI => 53 | s"""//> using dep "$groupId::$module:$version"""" 54 | case BuildTool.Ammonite => 55 | s"""import $$ivy.`$groupId::$module:$version`""" 56 | } 57 | 58 | end Main 59 | -------------------------------------------------------------------------------- /src/main/scala/dex/prompts.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.annotation.JSImport 5 | import scala.scalajs.js.Promise 6 | import scala.scalajs.js.Thenable 7 | import cats.effect.IO 8 | import scala.scalajs.js.JSConverters._ 9 | 10 | @js.native 11 | @JSImport("prompts", JSImport.Namespace) 12 | object prompts extends js.Any: 13 | def default[T](x: js.Object): Promise[T] = js.native 14 | 15 | def ioPrompt[T](x: js.Object): IO[T] = 16 | IO.fromPromise(IO(prompts.default(x))) 17 | 18 | def promptLibName: IO[LibName] = 19 | val libNameQuestion = new js.Object { 20 | val `type` = "text" 21 | val name = "libName" 22 | val message = "Which library ?" 23 | } 24 | 25 | trait LibNameAnswer extends js.Object { 26 | val libName: String 27 | } 28 | 29 | ioPrompt[LibNameAnswer](libNameQuestion).map(_.libName).map(LibName(_)) 30 | end promptLibName 31 | 32 | def promptProject(project: js.Array[Project]): IO[Project] = 33 | val projectQuestion = new js.Object { 34 | val `type` = "autocomplete" 35 | val name = "project" 36 | val message = "From which repo ?" 37 | val choices = project.map { p => 38 | new js.Object { 39 | val title = s"${p.repository} from ${p.organization}" 40 | val value = p 41 | } 42 | } 43 | } 44 | 45 | trait ProjectAnswer extends js.Object { 46 | val project: Project 47 | } 48 | 49 | ioPrompt[ProjectAnswer](projectQuestion).map(_.project) 50 | end promptProject 51 | 52 | def promptModules(project: Project): IO[js.Array[String]] = 53 | val moduleQuestion = new js.Object { 54 | val `type` = "autocompleteMultiselect" 55 | val name = "modules" 56 | val message = "Which modules ?" 57 | val choices = project.artifacts.map { artifact => 58 | new js.Object { 59 | val title = artifact 60 | val value = artifact 61 | } 62 | } 63 | } 64 | 65 | trait ProjectAnswer extends js.Object { 66 | val modules: js.Array[String] 67 | } 68 | 69 | ioPrompt[ProjectAnswer](moduleQuestion).map(_.modules) 70 | end promptModules 71 | 72 | def promptVersion(project: ProjectDetails): IO[String] = 73 | val versionQuestion = new js.Object { 74 | val `type` = "autocomplete" 75 | val name = "version" 76 | val message = "Which version ?" 77 | val choices = project.versions.map { version => 78 | new js.Object { 79 | val title = version 80 | val value = version 81 | } 82 | } 83 | } 84 | 85 | trait VersionAnswer extends js.Object: 86 | val version: String 87 | 88 | ioPrompt[VersionAnswer](versionQuestion).map(_.version) 89 | end promptVersion 90 | 91 | def promptBuildTool: IO[BuildTool] = 92 | val versionQuestion = new js.Object { 93 | val `type` = "select" 94 | val name = "buildTool" 95 | val message = "Which build tool ?" 96 | val choices = BuildTool.values.map { bt => 97 | new js.Object { 98 | val title = bt.toString() 99 | val value = bt 100 | } 101 | }.toJSArray 102 | } 103 | 104 | trait VersionAnswer extends js.Object { 105 | val buildTool: BuildTool 106 | } 107 | 108 | ioPrompt[VersionAnswer](versionQuestion).map(_.buildTool) 109 | end promptBuildTool 110 | -------------------------------------------------------------------------------- /src/main/scala/dex/scaladex.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import scala.scalajs.js 4 | import scala.scalajs.js.JSConverters._ 5 | import scala.scalajs.js.Thenable 6 | import cats.effect.IO 7 | 8 | object scaladex: 9 | 10 | val target = "JVM" 11 | val scalaVersion = "2.13" 12 | 13 | def search(name: String): IO[js.Array[Project]] = 14 | val n = name.trim() 15 | ioFetch 16 | .get( 17 | s"https://index.scala-lang.org/api/search?q=$n&target=$target&scalaVersion=$scalaVersion" 18 | ) 19 | .flatMap(_.json) 20 | .map { json => 21 | json.asInstanceOf[js.Array[Project]].filter { project => 22 | project.repository.contains(n) || project.artifacts 23 | .exists(_.contains(n)) 24 | } 25 | } 26 | 27 | def project(org: String, repo: String): IO[ProjectDetails] = 28 | ioFetch 29 | .get( 30 | s"https://index.scala-lang.org/api/project?organization=$org&repository=$repo" 31 | ) 32 | .flatMap(_.json) 33 | .map { json => 34 | json.asInstanceOf[ProjectDetails] 35 | } 36 | end project 37 | 38 | end scaladex 39 | 40 | @js.native 41 | trait Project extends js.Object: 42 | def organization: String = js.native 43 | def repository: String = js.native 44 | def artifacts: js.Array[String] = js.native 45 | 46 | @js.native 47 | trait ProjectDetails extends js.Object: 48 | def artifacts: js.Array[String] 49 | def versions: js.Array[String] 50 | def groupId: String 51 | def version: String 52 | -------------------------------------------------------------------------------- /src/main/scala/dex/util.scala: -------------------------------------------------------------------------------- 1 | package dex 2 | 3 | import scala.scalajs.js 4 | import js.annotation.JSImport 5 | 6 | /** Using this to discover the interface of objects, dynamically, to make sense 7 | * of the differences between 8 | */ 9 | @JSImport("util", JSImport.Namespace) 10 | @js.native 11 | object util extends js.Any: 12 | def inspect(any: js.Any): js.Any = js.native 13 | --------------------------------------------------------------------------------