Skip to content

Commit 8925334

Browse files
authored
Merge pull request #13 from mc-cc-scripts/issue-5/documentation
Issue 5/documentation
2 parents ac9499a + b52e323 commit 8925334

File tree

6 files changed

+197
-57
lines changed

6 files changed

+197
-57
lines changed

README.md

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,57 @@
1-
# script-manager
1+
# Script Manager
22

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

5-
# Install
6-
Download SCM with the following command:
5+
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.
6+
7+
**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>`.
8+
9+
[Documentation](https://github.com/mc-cc-scripts/script-manager/wiki) | [MIT License](https://github.com/mc-cc-scripts/script-manager/blob/master/LICENSE)
10+
11+
# Quickstart
12+
## Installation
13+
Download **SCM** with the following command:
714

815
pastebin run 1kKZ8zTS
916

10-
# Commands
11-
**Note:** "From GitHub" usually refers to repositories within this project. "Script" refers to programs **and** libraries.
12-
## add
13-
- `<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.
14-
- `<name>@<pastebin code>`: Downloads a program from Pastebin.
15-
## require
16-
- `<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.
17-
- `<name>@<pastebin code>`: Downloads a library from Pastebin.
18-
## update
19-
By default, without parameters, `update` updates the SCM script.
20-
- `<name>`: Removes and downloads an installed script by name.
21-
- `all`: Removes and downloads all installed scripts.
22-
- `<name> <sourceName>`: Removes and downloads an installed script from a specific source. Sources can be added via the `source` command.
23-
## source
24-
**`source` commands have not yet been implemented.**
25-
Feel free to do so [here](https://github.com/mc-cc-scripts/script-manager/issues/2).
26-
- `add <scriptName> <sourceName> <source>`: Adds a source (URL, Pastebin Code, ...) with a name to a script.
27-
- `get <scriptName>`: Shows all sources of a script.
28-
- `remove <scriptName> <sourceName>`: Removes a source from a script.
29-
- `default <scriptName> <sourceName>`: Sets a specific source to the default of a script. The previous default script gets a generated name.
30-
- `rename <scriptName> <sourceName> <newSourceName>`: Updates the name of a source.
31-
## remove
32-
- `<name>`: Deletes a script by name.
33-
- `all`: Deletes all scripts.
34-
## list
35-
Shows all installed scripts.
36-
## config
37-
Shows all available configurations.
38-
- `<name>`: Shows the value of a specific configuration.
39-
- `<name> <value>`: Updates the value of a specific configuration.
40-
## refresh
41-
Downloads the names of all programs and libraries of the official repository.
42-
Refreshes autocomplete.
43-
## help
44-
Shows all available commands and their description.
45-
- `<name>`: Shows the description of a command by name.
17+
## Configuration
18+
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).
19+
20+
## Commands
21+
You can find a complete list of all commands [here](https://github.com/mc-cc-scripts/script-manager/wiki/Commands).
4622

47-
# Example
48-
## Requires
49-
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:
23+
## Download a program
24+
You can either download a program from GitHub with
25+
```
26+
scm add testProgram
27+
```
28+
or from Pastebin with
29+
```
30+
scm add testProgram@7ByR3NYn
31+
```
5032

33+
## Build scripts
34+
### Program
35+
To add libraries to your programs, you will have to require **SCM** first.
5136
```lua
5237
local scm = require("./scm")
38+
```
39+
Then you can load your libraries as follows:
40+
```lua
5341
scm:load("testLibrary")
5442
```
43+
If a library is missing, **SCM** will try to install it.
5544

56-
If the library is already called by a program using this SCM loader, SCM will check all libraries loaded for these comments:
57-
58-
45+
### Libraries
46+
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.
5947
```lua
6048
--@requires subLibrary
6149
require("./libs/subLibrary")
62-
6350
```
64-
The comment tells SCM to look for the sub-library and, if it's not already installed, it will try to download it.
65-
This prevents the program from crashing, should SCM not be installed.
66-
6751
### Pastebin
68-
69-
If there is a "@" after the library name, it will look for the library and install it from the Pastebin-Code instead of GitHub
52+
You can also use libraries hosted on Pastebin. Just attach the Pastebin code at the end of the name, separated by an `@`.
7053
```lua
7154
--@requires subLibrary@z4VRj21Y
55+
require("./libs/subLibrary")
7256
```
7357

docs/favicons/favicon-16x16.png

359 Bytes
Loading

docs/favicons/favicon-32x32.png

687 Bytes
Loading

docs/index.html

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<!DOCTYPE html>
2+
<html lang="en" class="h-100">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" type="text/css" href="vdlcss-min.css">
8+
<link rel="icon" type="image/png" sizes="32x32" href="favicons/favicon-32x32.png">
9+
<link rel="icon" type="image/png" sizes="16x16" href="favicons/favicon-16x16.png">
10+
11+
<style>
12+
:root {
13+
--yellow: #DEDE6C;
14+
--black: #121212;
15+
--primary: var(--yellow);
16+
--primary-dark: #bbbb5d;
17+
--primary-light: #f3f39c;
18+
}
19+
20+
h1 {
21+
font-size: 32px;
22+
color: var(--white);
23+
}
24+
25+
h2 {
26+
color: var(--white);
27+
}
28+
29+
body {
30+
color: var(--white);
31+
min-height: 100%;
32+
}
33+
34+
#script-wrapper {
35+
max-width: 960px;
36+
}
37+
</style>
38+
39+
<title>SCM - Script Manager</title>
40+
</head>
41+
<body class="bg-yellow p-05 column between md:h-100">
42+
<div class="h-100 w-100 bg-black column center">
43+
<div class="column center md:mb-5 w-100">
44+
<h1 class="yellow">Script Manager</h1>
45+
<p class="m-0">Manage your ComputerCraft scripts with ease.</p>
46+
<div class="grid mt-2 px-1">
47+
<div class="cell-12 md:cell-4">
48+
<div class="bg-yellow p-1 rounded shadow">
49+
<h2 class="my-0 black">Install</h2>
50+
<pre class="mt-1"><code>pastebin run 1kKZ8zTS</code></pre>
51+
</div>
52+
</div>
53+
<div class="cell-12 md:cell-8 px-1">
54+
<h2 class="mt-0 mb-05">Features</h2>
55+
<ul>
56+
<li class="mb-05">Download scripts from Pastebin or GitHub.</li>
57+
<li class="mb-05">Update your scripts with a simple command.</li>
58+
<li class="mb-05">Auto-install missing libraries.</li>
59+
<li>
60+
<a target="_blank" href="https://github.com/mc-cc-scripts/script-manager/wiki">And more...</a>
61+
</li>
62+
</ul>
63+
</div>
64+
</div>
65+
<div class="row mt-1">
66+
<a target="_blank" href="https://github.com/mc-cc-scripts/script-manager" class="black button mr-1">Source</a>
67+
<a target="_blank" href="https://github.com/mc-cc-scripts/script-manager/wiki" class="black button">Documentation</a>
68+
</div>
69+
<div class="mt-1 px-1 w-100 md:w-auto">
70+
<h2 class="my-0">Programs</h2>
71+
<p>Installing programs can be as easy as <code class="yellow">scm add testProgram</code>.</p>
72+
<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>
73+
<p>Or, if you would rather install a program from pastebin, <code class="yellow">scm add testProgram@7ByR3NYn</code>.</p>
74+
<p class="mt-2"><strong>Some of our scripts...</strong></p>
75+
<div id="script-wrapper" class="scroll-x-snap row pt-05 pb-1 mb-1">
76+
</div>
77+
</div>
78+
</div>
79+
</div>
80+
<template id="script-template">
81+
<div
82+
class="inline-flex bg-yellow black rounded shadow p-1 mr-05 column between h-100"
83+
style="min-width: 200px; max-width: 200px; width: 100%; min-height: 200px; height: 100%; white-space: normal;"
84+
>
85+
<div>
86+
<div class="mb-05 link">
87+
<a href="#" class="black" target="_blank"><strong class="name"></strong></a>
88+
</div>
89+
<div class="mb-1">
90+
<em class="type"></em>
91+
</div>
92+
<div class="description"></div>
93+
</div>
94+
<div class="code">
95+
<code class="black"></code>
96+
</div>
97+
</div>
98+
</template>
99+
<script>
100+
let scriptWrapper = document.querySelector('#script-wrapper')
101+
let template = document.querySelector('#script-template')
102+
103+
function addCards (data) {
104+
let installScript = {}
105+
installScript['Library'] = 'require'
106+
installScript['Program'] = 'add'
107+
108+
for (let i = 0; i < data.length; ++i) {
109+
let tmpElement = template.content.cloneNode(true)
110+
let tmpName = data[i].name
111+
if (!tmpName.endsWith('-prog') && !tmpName.endsWith('-lib')) continue
112+
let tmpType = tmpName.endsWith('-prog') ? 'Program' : 'Library'
113+
tmpName = tmpName.substring(0, tmpName.lastIndexOf('-'))
114+
tmpElement.querySelector('.name').innerHTML = tmpName
115+
tmpElement.querySelector('.type').innerHTML = tmpType
116+
tmpElement.querySelector('.description').innerHTML = data[i].description
117+
tmpElement.querySelector('.link a').href = 'https://github.com/' + data[i].full_name
118+
tmpElement.querySelector('.code code').innerHTML = 'scm ' + installScript[tmpType] + ' ' + tmpName
119+
120+
scriptWrapper.appendChild(tmpElement)
121+
}
122+
}
123+
124+
async function getData () {
125+
// check localStorage first
126+
let localStorageData = localStorage.getItem('data')
127+
if (localStorageData !== null && localStorageData !== 'null') return JSON.parse(localStorageData)
128+
129+
// call github api to get info about our scripts
130+
let response = await fetch('https://api.github.com/orgs/mc-cc-scripts/repos?type=all&per_page=100&page=1')
131+
let data = await response.json()
132+
133+
// store data in localStorage to avoid too many api calls
134+
let cleanData = []
135+
for (let i = 0; i < data.length; ++i) {
136+
cleanData[i] = {}
137+
cleanData[i].name = data[i].name
138+
cleanData[i].description = data[i].description
139+
cleanData[i].full_name = data[i].full_name
140+
}
141+
localStorage.setItem('data', JSON.stringify(cleanData))
142+
143+
return cleanData
144+
}
145+
146+
getData().then(data => addCards(data))
147+
</script>
148+
</body>
149+
</html>

docs/vdlcss-min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scm.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ scm.config = {
1212
["programSuffix"] = "-prog",
1313
["librarySuffix"] = "-lib",
1414
["infoFile"] = "files.txt", -- provides the structure of a git repo (paths to all files)
15-
["apiGithubGetRepos"] = "https://api.github.com/orgs/mc-cc-scripts/repos?type=all&per_page=100&page=1",
16-
-- Local Settings
15+
["apiGithubURL"] = "https://api.github.com/orgs/",
16+
["apiGithubGetRepos"] = "/repos?type=all&per_page=100&page=1",
1717
["installScript"] = "1kKZ8zTS",
18-
["rootDirectory"] = "",
18+
-- Local Settings
1919
["programDirectory"] = "progs/",
2020
["libraryDirectory"] = "libs/",
2121
["configDirectory"] = "config/",
@@ -173,7 +173,7 @@ function scm:refreshRepoScripts ()
173173
local programs = {}
174174
local libraries = {}
175175

176-
local request = http.get(self.config["apiGithubGetRepos"])
176+
local request = http.get(self.config["apiGithubURL"] .. self.config["user"] .. self.config["apiGithubGetRepos"])
177177
if request then
178178
local response = request.readAll()
179179
request.close()
@@ -503,7 +503,7 @@ function scm:downloadURL (sourceObject, targetDirectory, updateObj)
503503
request.close()
504504

505505
if content then
506-
local file = fs.open(self.config["rootDirectory"] .. targetDirectory .. sourceObject.name, "w")
506+
local file = fs.open(targetDirectory .. sourceObject.name, "w")
507507
file.write(content)
508508
file.close()
509509
return sourceObject, true

0 commit comments

Comments
 (0)