Skip to content

Commit

Permalink
Merge pull request #2 from LiteLDev/develop
Browse files Browse the repository at this point in the history
Add features for v0.2.0
  • Loading branch information
futrime authored Jan 17, 2023
2 parents 0cc8dfb + 4b71c6a commit ef73ef6
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

## Checklist before merging

Thank you for your contribution to the repo.
Thank you for your contribution to the repository.
Before submitting this PR, please make sure:

- [ ] Your code builds clean without any errors or warnings
- [ ] Your code follows the code style of LitelDev
- [ ] Your code follows the code style of LiteLDev
- [ ] You have tested all functions
- [ ] You have not used code without license
- [ ] You have added statement for third-party code
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unrelease]

## [0.2.0] - 2023-01-11

### Added

- Possession field in tooth.json to specify directory to remove when uninstalling a tooth.

### Fixed

- Fix failing to fetch tooth when the repository does not contain go.mod file.
- Fix failing to parse tooth file when the tooth is downloaded via GOPROXY.
- Fix failing to parse tooth when tooth.json is the only file in the tooth.

### Changed

- Change extension name of tooth files to .tth

## [0.1.0] - 2023-01-17

### Added

- Basic functions: cache, install, list, show, tooth init, and uninstall.

[unreleased]: https://github.com/LiteLDev/Lip/compare/v0.1.0...HEAD
[0.2.0]: https://github.com/LiteLDev/Lip/releases/tag/v0.1.0...v0.2.0
[0.1.0]: https://github.com/LiteLDev/Lip/releases/tag/v0.1.0
16 changes: 15 additions & 1 deletion docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,18 @@
[![Latest Tag](https://img.shields.io/github/v/tag/LiteLDev/Lip?label=LATEST%20TAG&style=for-the-badge)](https://github.com/LiteLDev/Lip/releases/latest)
[![Downloads](https://img.shields.io/github/downloads/LiteLDev/Lip/latest/total?style=for-the-badge)](https://github.com/LiteLDev/Lip/releases/latest)

Lip is a package installer for LiteLoaderBDS. You can use Lip to install packages from any LiteLoaderBDS registries, or directly from any Git repository.
Lip is a package installer for LiteLoaderBDS. You can use Lip to install packages from any LiteLoaderBDS registries, or directly from any Git repository.

Please take a look at our documentation for how to install and use Lip:

- [Installation](installation.md)
- [Usage](getting_started.md)

We release updates regularly. Find more details in our changelog:

- [Changelog](https://github.com/LiteLDev/Lip/blob/main/CHANGELOG.md)

If you find bugs, need help, or want to talk to the developers, please report with an issue:

- [Open an issue](https://github.com/LiteLDev/Lip/issues/new/choose)

6 changes: 1 addition & 5 deletions docs/en/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- [Installation](installation.md)

- [Developer's Guide](developer_s_guide.md)
- [Creator's Guide](creator_s_guide.md)

- Commands

Expand All @@ -28,10 +28,6 @@

- [tooth.json File Reference](tooth_json_file_reference.md)

- Development

- [Getting Started](development/getting_started.md)

- Maintenance

- Global Data Directory
Expand Down
10 changes: 5 additions & 5 deletions docs/en/commands/lip_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lip install [options] <tooth url/files>
Install a tooth from:

- tooth repositories via Goproxy.
- local or remote standalone tooth files (with suffix `.tt`).
- local or remote standalone tooth files (with suffix `.tth`).

For the tooth repository, you can specific the version by add suffix like `@1.2.3` or `@1.2.0-beta.3`. However, when another version is installed and you run Lip without `--upgrade` or `--force-reinstall` flag, Lip will not install the specific version.

Expand All @@ -35,7 +35,7 @@ Note that `lip install` prefers to leave the installed version as-is unless `--u
When looking at the items to be installed, Lip checks what type of item each is, in the following order:

1. Tooth repository, which can be accessed via Goproxy.
2. Local tooth file with suffix `.tt`.
2. Local tooth file with suffix `.tth`.

In the first case, all letters will be converted to lowercase before processing.

Expand Down Expand Up @@ -98,12 +98,12 @@ lip install --force-reinstall example.com/some_user/some_tooth
Install from URL of a tooth:

```shell
lip install https://example.com/example.tt
lip install https://example.com/example.tth
```

Install from a local tooth:

```shell
lip install example.tt
lip install ./example/example.tt
lip install example.tth
lip install ./example/example.tth
```
6 changes: 3 additions & 3 deletions docs/en/developer_s_guide.md → docs/en/creator_s_guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Developer's Guide
# Creator's Guide

We're pleased that you are interested in developing your stuff on Lip.
We're pleased that you are interested in creating with Lip.

## Ensure you have a working Lip

Expand All @@ -25,7 +25,7 @@ Then you can fill in the information in tooth.json to make your work recognized

### Pack the tooth

Currently we have not provided commands to pack a tooth. You can just zip everything (make sure tooth.json is under the root of the zip file) and change its extension name from ".zip" to ".tt".
Currently we have not provided commands to pack a tooth. You can just zip everything (make sure tooth.json is under the root of the zip file) and change its extension name from ".zip" to ".tth".

## Next Steps

Expand Down
8 changes: 4 additions & 4 deletions docs/en/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ By default, Lip will fetch teeth via GOPROXY, a proxy of Git repos.
### Install a tooth from URL

```shell
> lip install https://example.com/exampletooth.tt
> lip install https://example.com/exampletooth.tth
[...]
Successfully installed all tooth files.
```

Lip only supports URLs started with "http://" or "https://". All URLs should ends with ".tt".
Lip only supports URLs started with "http://" or "https://". All URLs should ends with ".tth".

### Install a tooth from a tooth file

```shell
> lip install exampletooth.tt
> lip install exampletooth.tth
[...]
Successfully installed all tooth files.
```

The tooth file should have ".tt" extension name.
The tooth file should have ".tth" extension name.

### Install multiple teeth

Expand Down
29 changes: 27 additions & 2 deletions docs/en/tooth_json_file_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ A tooth.json includes directives as shown in the following example. These are de
"source": "",
"destination": ""
}
],
"possession": [
"plugins/LiteLoader/"
]
}
```
Expand Down Expand Up @@ -92,7 +95,7 @@ Only lowercase letters, digits, dashes, underlines, dots and slashes [a-z0-9-_./

The tooth path must uniquely identify your tooth. For most teeth, the path is a URL where Lip can find the code. For teeth that won’t ever be downloaded directly, the tooth path can be just some name you control that will ensure uniqueness.

Note that the tooth path should not include protocol prefix (e.g. "https://" or "git://"), which already violates the syntax. Meanwhile, the tooth path should not end with ".tt", which will be regarded as a standalone tooth archive file.
Note that the tooth path should not include protocol prefix (e.g. "https://" or "git://"), which already violates the syntax. Meanwhile, the tooth path should not end with ".tth", which will be regarded as a standalone tooth archive file.

If you would like to publish your tooth, please make the tooth path a real URL. For example, the first character should be a letter or a digit.

Expand Down Expand Up @@ -289,4 +292,26 @@ Extract from tooth root and place to BDS root:

### Notes

Do not add any prefix like "/", "./" or "../". Otherwise, Lip will refused to install the tooth. If the source is right the root of the tooth, just leave the value a blank string. Similarly, if the destination is the root of BDS, leave the value a blank string.
Do not add any prefix like "/", "./" or "../". Otherwise, Lip will refused to install the tooth. If the source is right the root of the tooth, just leave the value a blank string. Similarly, if the destination is the root of BDS, leave the value a blank string.

## possession

Declares the which folders are in the possession of the tooth. When uninstalling, files in the declared folders will be removed.

### Syntax

Each item of the list should be a valid directory path relative to the root of BDS ending with "/".

### Examples

```json
{
"possession": [
"plugins/LiteLoader/"
]
}
```

### Notes

Do not take the possession of any directory that might be used by other tooth, e.g. public directories like worlds/.
2 changes: 1 addition & 1 deletion src/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Description:
Install teeth from:
- tooth repositories.
- local or remote standalone tooth files (with suffix .tt).
- local or remote standalone tooth files (with suffix .tth).
Options:
-h, --help Show help.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/install/specifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s Specifier) ToothVersion() version.Version {

// getSpecifierType gets the type of the requirement specifier.
func getSpecifierType(specifier string) SpecifierType {
if strings.HasSuffix(specifier, ".tt") {
if strings.HasSuffix(specifier, ".tth") {
if strings.HasPrefix(specifier, "http://") || strings.HasPrefix(specifier, "https://") {
return ToothURLSpecifierType
} else {
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/install/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ func fetchVersionList(repoPath string) ([]versionutils.Version, error) {
var versionList []versionutils.Version
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
version, err := versionutils.NewFromString(strings.TrimPrefix(scanner.Text(), "v"))
versionString := scanner.Text()
versionString = strings.TrimPrefix(versionString, "v")
versionString = strings.TrimSuffix(versionString, "+incompatible")
version, err := versionutils.NewFromString(versionString)
if err != nil {
continue
}
Expand Down Expand Up @@ -182,8 +185,8 @@ func fetchLatestVersion(repoPath string) (versionutils.Version, error) {
return versionutils.Version{}, errors.New("cannot find a stable latest version: " + repoPath)
}

// Remove the prefix v.
versionString = strings.TrimPrefix(versionString, "v")
versionString = strings.TrimSuffix(versionString, "+incompatible")

// Parse the version.
version, err := versionutils.NewFromString(versionString)
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/tooth/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const defaultToothJsonContent = `{
"source": "<placement source>",
"destination": "<placement destination>"
}
]
],
"possession": [
"<private directory of your tooth ends with '/'>"
]
}`

const helpMessage = `
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ func uninstall(recordFileName string) error {
}
}

// Iterate over the possessions and delete the folders as well as
// the files in the folders.
for _, possession := range currentRecord.Possession {
workspaceDir, err := localfile.WorkSpaceDir()
if err != nil {
return err
}

// Remove the folder.
err = os.RemoveAll(workspaceDir + "/" + possession)
if err != nil {
return errors.New("cannot delete the folder " + workspaceDir + "/" + possession + ": " + err.Error())
}
}

// Delete the record file.
err = os.Remove(recordDir + "/" + recordFileName)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/localfile/localfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func GetCachedToothFileName(fullSpecifier string) string {
// Encode the full specifier with Base64.
fullSpecifier = base64.StdEncoding.EncodeToString([]byte(fullSpecifier))

return fullSpecifier + ".tt"
return fullSpecifier + ".tth"
}

// GetRecordFileName returns the file name of the record file.
Expand Down
24 changes: 15 additions & 9 deletions src/tooth/toothfile/toothfile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package toothfile includes functions for .tt files.
// Package toothfile includes functions for .tth files.
package toothfile

import (
Expand All @@ -14,24 +14,27 @@ import (
recordutils "github.com/liteldev/lip/tooth/toothrecord"
)

// ToothFile is the struct that contains the metadata of a .tt file.
// ToothFile is the struct that contains the metadata of a .tth file.
type ToothFile struct {
filePath string
metadata metadata.Metadata
}

// New creates a new ToothFile struct from a file path of a .tt file.
// New creates a new ToothFile struct from a file path of a .tth file.
func New(filePath string) (ToothFile, error) {
r, err := zip.OpenReader(filePath)
if err != nil {
return ToothFile{}, errors.New("failed to open tooth file " + filePath)
}
defer r.Close()

// Get the file prefix.
filePrefix := getFilePrefix(r)

// Iterate through the files in the archive,
// and find tooth.json.
for _, f := range r.File {
if f.Name == "tooth.json" {
if f.Name == filePrefix+"tooth.json" {
// Open tooth.json.
rc, err := f.Open()
if err != nil {
Expand Down Expand Up @@ -62,17 +65,17 @@ func New(filePath string) (ToothFile, error) {
return ToothFile{}, errors.New("tooth.json not found in " + filePath)
}

// FilePath returns the file path of the .tt file.
// FilePath returns the file path of the .tth file.
func (t ToothFile) FilePath() string {
return t.filePath
}

// Metadata returns the metadata of the .tt file.
// Metadata returns the metadata of the .tth file.
func (t ToothFile) Metadata() metadata.Metadata {
return t.metadata
}

// Install installs the .tt file.
// Install installs the .tth file.
// TODO#1: Check if the tooth is already installed.
// TODO#2: Directory placement.
func (t ToothFile) Install() error {
Expand Down Expand Up @@ -115,13 +118,16 @@ func (t ToothFile) Install() error {
return err
}

// Open the .tt file.
// Open the .tth file.
r, err := zip.OpenReader(t.filePath)
if err != nil {
return errors.New("failed to open tooth file " + t.filePath)
}
defer r.Close()

// Get the file prefix.
filePrefix := getFilePrefix(r)

for _, placement := range t.metadata.Placement {
source := placement.Source
destination := workSpaceDir + "/" + placement.Destination
Expand All @@ -137,7 +143,7 @@ func (t ToothFile) Install() error {
continue
}

if f.Name == source {
if f.Name == filePrefix+source {
// Open the source file.
rc, err := f.Open()
if err != nil {
Expand Down
Loading

0 comments on commit ef73ef6

Please sign in to comment.