Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 36 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,57 @@
# script-manager
# Script Manager

A dependency manager for scripts to use in the mod CC: Tweaked of Minecraft.
**SCM** is a script manager for Minecrafts ComputerCraft mod.

# Install
Download SCM with the following command:
We are using [CC: Tweaked](https://tweaked.cc/) and in some cases some additional peripherals, which we ideally mention in the repositories of the scripts that use them.

**SCM** is used so you don't have to worry too much about your libraries. You can focus on writing your program and if it uses external libraries, they will be installed automatically. Furthermore, if you want to keep your scripts up-to-date, **SCM** saves the source of the programs you've installed and lets you update them by just typing `scm update <name>`.

[Documentation](https://github.com/mc-cc-scripts/script-manager/wiki) | [MIT License](https://github.com/mc-cc-scripts/script-manager/blob/master/LICENSE)

# Quickstart
## Installation
Download **SCM** with the following command:

pastebin run 1kKZ8zTS

# Commands
**Note:** "From GitHub" usually refers to repositories within this project. "Script" refers to programs **and** libraries.
## add
- `<name>`: Downloads a program from GitHub. Programs always have the suffix `-prog` ([Naming Conventions](https://github.com/mc-cc-scripts/.github/blob/master/profile/README.md#naming-conventions)). The suffix should not be added to the name.
- `<name>@<pastebin code>`: Downloads a program from Pastebin.
## require
- `<name>`: Downloads a library from GitHub. Libraries always have the suffix `-lib` ([Naming Conventions](https://github.com/mc-cc-scripts/.github/blob/master/profile/README.md#naming-conventions)). The suffix should not be added to the name.
- `<name>@<pastebin code>`: Downloads a library from Pastebin.
## update
By default, without parameters, `update` updates the SCM script.
- `<name>`: Removes and downloads an installed script by name.
- `all`: Removes and downloads all installed scripts.
- `<name> <sourceName>`: Removes and downloads an installed script from a specific source. Sources can be added via the `source` command.
## source
**`source` commands have not yet been implemented.**
Feel free to do so [here](https://github.com/mc-cc-scripts/script-manager/issues/2).
- `add <scriptName> <sourceName> <source>`: Adds a source (URL, Pastebin Code, ...) with a name to a script.
- `get <scriptName>`: Shows all sources of a script.
- `remove <scriptName> <sourceName>`: Removes a source from a script.
- `default <scriptName> <sourceName>`: Sets a specific source to the default of a script. The previous default script gets a generated name.
- `rename <scriptName> <sourceName> <newSourceName>`: Updates the name of a source.
## remove
- `<name>`: Deletes a script by name.
- `all`: Deletes all scripts.
## list
Shows all installed scripts.
## config
Shows all available configurations.
- `<name>`: Shows the value of a specific configuration.
- `<name> <value>`: Updates the value of a specific configuration.
## refresh
Downloads the names of all programs and libraries of the official repository.
Refreshes autocomplete.
## help
Shows all available commands and their description.
- `<name>`: Shows the description of a command by name.
## Configuration
There are various configurations you can change. If you want to use your own repository, you can easily change it in the [configuration](https://github.com/mc-cc-scripts/script-manager/wiki/Configuration).

## Commands
You can find a complete list of all commands [here](https://github.com/mc-cc-scripts/script-manager/wiki/Commands).

# Example
## Requires
If you want to load a library within a program and keep it updated through SCM, then you can do that with the following notation:
## Download a program
You can either download a program from GitHub with
```
scm add testProgram
```
or from Pastebin with
```
scm add testProgram@7ByR3NYn
```

## Build scripts
### Program
To add libraries to your programs, you will have to require **SCM** first.
```lua
local scm = require("./scm")
```
Then you can load your libraries as follows:
```lua
scm:load("testLibrary")
```
If a library is missing, **SCM** will try to install it.

If the library is already called by a program using this SCM loader, SCM will check all libraries loaded for these comments:


### Libraries
Furthermore, **SCM** can also check nested sub-libraries within the loaded library. To do that, you will have to add a comment before requiring the library. This has the advantage of the libraries still being usable without **SCM**, as a comment does not interfer with the logic of the script.
```lua
--@requires subLibrary
require("./libs/subLibrary")

```
The comment tells SCM to look for the sub-library and, if it's not already installed, it will try to download it.
This prevents the program from crashing, should SCM not be installed.

### Pastebin

If there is a "@" after the library name, it will look for the library and install it from the Pastebin-Code instead of GitHub
You can also use libraries hosted on Pastebin. Just attach the Pastebin code at the end of the name, separated by an `@`.
```lua
--@requires subLibrary@z4VRj21Y
require("./libs/subLibrary")
```

Binary file added docs/favicons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/favicons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 149 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!DOCTYPE html>
<html lang="en" class="h-100">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="vdlcss-min.css">
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png">

<style>
:root {
--yellow: #DEDE6C;
--black: #121212;
--primary: var(--yellow);
--primary-dark: #bbbb5d;
--primary-light: #f3f39c;
}

h1 {
font-size: 32px;
color: var(--white);
}

h2 {
color: var(--white);
}

body {
color: var(--white);
min-height: 100%;
}

#script-wrapper {
max-width: 960px;
}
</style>

<title>SCM - Script Manager</title>
</head>
<body class="bg-yellow p-05 column between md:h-100">
<div class="h-100 w-100 bg-black column center">
<div class="column center md:mb-5 w-100">
<h1 class="yellow">Script Manager</h1>
<p class="m-0">Manage your ComputerCraft scripts with ease.</p>
<div class="grid mt-2 px-1">
<div class="cell-12 md:cell-4">
<div class="bg-yellow p-1 rounded shadow">
<h2 class="my-0 black">Install</h2>
<pre class="mt-1"><code>pastebin run 1kKZ8zTS</code></pre>
</div>
</div>
<div class="cell-12 md:cell-8 px-1">
<h2 class="mt-0 mb-05">Features</h2>
<ul>
<li class="mb-05">Download scripts from Pastebin or GitHub.</li>
<li class="mb-05">Update your scripts with a simple command.</li>
<li class="mb-05">Auto-install missing libraries.</li>
<li>
<a target="_blank" href="https://github.com/mc-cc-scripts/script-manager/wiki">And more...</a>
</li>
</ul>
</div>
</div>
<div class="row mt-1">
<a target="_blank" href="https://github.com/mc-cc-scripts/script-manager" class="black button mr-1">Source</a>
<a target="_blank" href="https://github.com/mc-cc-scripts/script-manager/wiki" class="black button">Documentation</a>
</div>
<div class="mt-1 px-1 w-100 md:w-auto">
<h2 class="my-0">Programs</h2>
<p>Installing programs can be as easy as <code class="yellow">scm add testProgram</code>.</p>
<p>Don't want to use our official GitHub repository? No Problem! You can change it to your own with a single command: <code class="yellow">scm config user &lt;your-name&gt;</code>.</p>
<p>Or, if you would rather install a program from pastebin, <code class="yellow">scm add testProgram@7ByR3NYn</code>.</p>
<p class="mt-2"><strong>Some of our scripts...</strong></p>
<div id="script-wrapper" class="scroll-x-snap row pt-05 pb-1 mb-1">
</div>
</div>
</div>
</div>
<template id="script-template">
<div
class="inline-flex bg-yellow black rounded shadow p-1 mr-05 column between h-100"
style="min-width: 200px; max-width: 200px; width: 100%; min-height: 200px; height: 100%; white-space: normal;"
>
<div>
<div class="mb-05 link">
<a href="#" class="black" target="_blank"><strong class="name"></strong></a>
</div>
<div class="mb-1">
<em class="type"></em>
</div>
<div class="description"></div>
</div>
<div class="code">
<code class="black"></code>
</div>
</div>
</template>
<script>
let scriptWrapper = document.querySelector('#script-wrapper')
let template = document.querySelector('#script-template')

function addCards (data) {
let installScript = {}
installScript['Library'] = 'require'
installScript['Program'] = 'add'

for (let i = 0; i < data.length; ++i) {
let tmpElement = template.content.cloneNode(true)
let tmpName = data[i].name
if (!tmpName.endsWith('-prog') && !tmpName.endsWith('-lib')) continue
let tmpType = tmpName.endsWith('-prog') ? 'Program' : 'Library'
tmpName = tmpName.substring(0, tmpName.lastIndexOf('-'))
tmpElement.querySelector('.name').innerHTML = tmpName
tmpElement.querySelector('.type').innerHTML = tmpType
tmpElement.querySelector('.description').innerHTML = data[i].description
tmpElement.querySelector('.link a').href = 'https://github.com/' + data[i].full_name
tmpElement.querySelector('.code code').innerHTML = 'scm ' + installScript[tmpType] + ' ' + tmpName

scriptWrapper.appendChild(tmpElement)
}
}

async function getData () {
// check localStorage first
let localStorageData = localStorage.getItem('data')
if (localStorageData !== null && localStorageData !== 'null') return JSON.parse(localStorageData)

// call github api to get info about our scripts
let response = await fetch('https://api.github.com/orgs/mc-cc-scripts/repos?type=all&per_page=100&page=1')
let data = await response.json()

// store data in localStorage to avoid too many api calls
let cleanData = []
for (let i = 0; i < data.length; ++i) {
cleanData[i] = {}
cleanData[i].name = data[i].name
cleanData[i].description = data[i].description
cleanData[i].full_name = data[i].full_name
}
localStorage.setItem('data', JSON.stringify(cleanData))

return cleanData
}

getData().then(data => addCards(data))
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions docs/vdlcss-min.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions scm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ scm.config = {
["programSuffix"] = "-prog",
["librarySuffix"] = "-lib",
["infoFile"] = "files.txt", -- provides the structure of a git repo (paths to all files)
["apiGithubGetRepos"] = "https://api.github.com/orgs/mc-cc-scripts/repos?type=all&per_page=100&page=1",
-- Local Settings
["apiGithubURL"] = "https://api.github.com/orgs/",
["apiGithubGetRepos"] = "/repos?type=all&per_page=100&page=1",
["installScript"] = "1kKZ8zTS",
["rootDirectory"] = "",
-- Local Settings
["programDirectory"] = "progs/",
["libraryDirectory"] = "libs/",
["configDirectory"] = "config/",
Expand Down Expand Up @@ -173,7 +173,7 @@ function scm:refreshRepoScripts ()
local programs = {}
local libraries = {}

local request = http.get(self.config["apiGithubGetRepos"])
local request = http.get(self.config["apiGithubURL"] .. self.config["user"] .. self.config["apiGithubGetRepos"])
if request then
local response = request.readAll()
request.close()
Expand Down Expand Up @@ -503,7 +503,7 @@ function scm:downloadURL (sourceObject, targetDirectory, updateObj)
request.close()

if content then
local file = fs.open(self.config["rootDirectory"] .. targetDirectory .. sourceObject.name, "w")
local file = fs.open(targetDirectory .. sourceObject.name, "w")
file.write(content)
file.close()
return sourceObject, true
Expand Down