├── .gitignore ├── .replit ├── LICENSE.txt ├── README.md ├── dusk.go ├── go.mod └── go.sum /.gitignore: -------------------------------------------------------------------------------- 1 | pkgs/ 2 | .replit 3 | replit.nix 4 | main 5 | dusk 6 | chongos.md -------------------------------------------------------------------------------- /.replit: -------------------------------------------------------------------------------- 1 | language = "go" 2 | run = "go build -ldflags \"-s -w\" main.go && ./main ls" -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dusk 2 | 3 | This is **the** package manager for [The Night Programming language](https://github.com/DynamicSquid/night). 4 | This provides a seamless interface for configuring and managing packages. 5 | 6 | ## Features 7 | 8 | Here are the current features: 9 | 10 | - `dusk add` installs the package(s) of your choice, just list them after the command. 11 | - `dusk del` deletes the package(s) provided. 12 | - `dusk upd` updates the package(s) provided. 13 | - `dusk inf` gets information about the given package(s) from the server. 14 | - `dusk ls` lists all installed packages. 15 | - **IN ALPHA** `dusk find` finds packages containing the given parameters 16 | --- 17 | 18 | ## Getting Started 19 | 20 | Dusk is already distributed through Night. You can find installation instructions at the [Night Website](https://night-website.dynamicsquid.repl.co/index.html). 21 | 22 | You can also install Dusk from source if you'd wish. Here's how: 23 | 24 | ### Installing from Source 25 | 26 | 1. Install the Golang compiler, using the instructions at [the official Golang website](https://golang.org/doc/install) 27 | 28 | 2. Clone this repo with: 29 | `git clone https://github.com/firefish111/dusk.git` 30 | or using the GitHub CLI: 31 | `gh repo clone firefish111/dusk` 32 | 33 | 3. Enter the source folder: `cd dusk` 34 | 35 | 4. Compile dusk using `go build dusk.go` 36 | 37 | And that's it! 38 | -------------------------------------------------------------------------------- /dusk.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "io/fs" 8 | "io/ioutil" 9 | "net/http" 10 | "os" 11 | "strings" 12 | 13 | // haha chinese package go brrrrrrr 14 | "github.com/gookit/color" 15 | ) 16 | 17 | // safety go brrrrrr 18 | func safe(e error) { 19 | if e != nil { 20 | panic(e) 21 | } 22 | } 23 | 24 | // long boi function chain 25 | func vparse(ver interface{}) string { 26 | return strings.Trim( 27 | strings.Join( 28 | strings.Fields( 29 | fmt.Sprint(ver), 30 | ), ".", 31 | ), "[]", 32 | ) 33 | } 34 | 35 | func main() { 36 | meta := make(map[string]map[string]interface{}) 37 | // not paying attention to error, because am smort 38 | os.Mkdir("./pkgs", 0755) 39 | 40 | // haha colours go brrrrrr 41 | indigo := color.C256(63, false) 42 | lime := color.C256(155, false) 43 | pink := color.C256(164, false) 44 | orange := color.C256(202, false) 45 | bold := color.Style{color.Bold} 46 | rederr := color.Style{color.FgRed} 47 | 48 | // if not exist 49 | if _, err := os.Stat("./pkgs/metadata.json"); !errors.Is(err, fs.ErrNotExist) { 50 | // readfile 51 | dat, err := ioutil.ReadFile("./pkgs/metadata.json") 52 | safe(err) 53 | // put contents of file in meta, parsed as json 54 | err = json.Unmarshal([]byte(dat), &meta) 55 | safe(err) 56 | } 57 | 58 | if len(os.Args) == 1 || (len(os.Args) <= 2 && os.Args[1] != "ls") { 59 | // usage 60 | fmt.Fprintln(os.Stderr, "usage: dusk command package [more packages]") 61 | os.Exit(1) 62 | } else if os.Args[1] == "ls" { 63 | // listing packages 64 | if len(meta) == 0 { 65 | indigo.Println("Unfortunately, no packages are installed.") 66 | } else { 67 | indigo.Println("Installed packages are:") 68 | for ky := range meta { 69 | bold.Print(pink.Sprint("Package ")) 70 | orange.Printf("%s ", ky) 71 | lime.Printf("v%s\n", vparse(meta[ky]["version"])) 72 | } 73 | } 74 | os.Exit(0) 75 | } 76 | for _, pkg := range os.Args[2:] { // iterates over all the packages passed 77 | if os.Args[1] == "del" { 78 | err := os.Remove("./pkgs/" + pkg + ".night") // delete night file 79 | safe(err) 80 | bold.Print(pink.Sprint("Uninstalled package ")) 81 | orange.Printf("%s ", pkg) 82 | lime.Printf("v%s\n", vparse(meta[pkg]["version"])) 83 | 84 | delete(meta, pkg) 85 | } else { 86 | client := &http.Client{} // creates client 87 | 88 | // res, err := client.Get("https://duskcdn.firefish.repl.co/cdn/" + pkg) 89 | var method string 90 | if method = "GET"; os.Args[1] == "inf" { 91 | method = "POST" 92 | } 93 | req, err := http.NewRequest(method, fmt.Sprintf( 94 | "https://duskcdn.firefish.repl.co/cdn/%s", pkg, 95 | ), nil) // initialise request 96 | safe(err) 97 | 98 | req.Header.Add("X-Requested-With", "night-dusk-pkg") 99 | res, err := client.Do(req) // send request 100 | safe(err) 101 | if res.StatusCode != 200 { 102 | panic(fmt.Sprintf("Status Code %d", res.StatusCode)) 103 | os.Exit(1) 104 | } 105 | 106 | if os.Args[1] != "inf" { 107 | body, err := ioutil.ReadAll(res.Body) // read body of response 108 | res.Body.Close() 109 | safe(err) 110 | switch os.Args[1] { 111 | case "upd": 112 | if _, err = os.Stat("./pkgs/" + pkg + ".night"); !os.IsNotExist(err) { 113 | 114 | err = ioutil.WriteFile("./pkgs/"+pkg+".night", body, 0666) 115 | safe(err) // write to night file 116 | 117 | if vparse(res.Header["X-Package-Version"]) == vparse(meta[pkg]["version"]) { 118 | fmt.Fprintln(os.Stderr, rederr.Sprintf("Package %s already at latest version.", pkg)) 119 | os.Exit(0) 120 | } 121 | 122 | bold.Print(pink.Sprint("Updated package ")) 123 | orange.Printf("%s ", pkg) 124 | lime.Printf("v%s to v%s\n", 125 | vparse(meta[pkg]["version"]), 126 | vparse(res.Header["X-Package-Version"]), 127 | ) 128 | 129 | meta[pkg]["version"] = res.Header["X-Package-Version"] 130 | break 131 | } 132 | fmt.Fprintln(os.Stderr, 133 | rederr.Sprint("Warning: destination file doesn't exist, installing package instead")) 134 | fallthrough 135 | case "add": 136 | if _, err = os.Stat("./pkgs/" + pkg + ".night"); !os.IsNotExist(err) { 137 | panic(fmt.Sprintf("File already exists, please use %s", 138 | lime.Sprint("dusk upd **[packages]**"), 139 | )) 140 | } 141 | 142 | err = ioutil.WriteFile("./pkgs/"+pkg+".night", body, 0666) 143 | safe(err) // write to night file 144 | 145 | bold.Print(pink.Sprint("Installed package ")) 146 | orange.Printf("%s ", pkg) 147 | lime.Printf("v%s\n", vparse(res.Header["X-Package-Version"])) 148 | 149 | meta[pkg] = make(map[string]interface{}) 150 | meta[pkg]["version"] = res.Header["X-Package-Version"] 151 | } 152 | } else { 153 | bold.Print(pink.Sprint("Package ")) 154 | orange.Printf("%s ", pkg) 155 | lime.Printf("v%s\n", vparse(res.Header["X-Package-Version"])) 156 | } 157 | } 158 | } 159 | dat, err := json.Marshal(meta) 160 | safe(err) 161 | err = ioutil.WriteFile("./pkgs/metadata.json", dat, 0666) 162 | safe(err) 163 | } 164 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module main 2 | 3 | go 1.7 4 | 5 | require github.com/gookit/color v1.4.2 // indirect 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= 3 | github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 6 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 7 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= 8 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= 9 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c= 10 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 11 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 12 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 13 | --------------------------------------------------------------------------------