sandstone-cli 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/.env.sand +1 -0
- package/bin/run +1 -0
- package/lib/build/index.d.ts +1 -0
- package/lib/build/index.js +7 -0
- package/lib/commands/build.d.ts +1 -0
- package/lib/commands/dependency.d.ts +5 -0
- package/lib/commands/dependency.js +182 -0
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +1 -1
- package/lib/index.js +27 -5
- package/package.json +4 -2
- package/src/build/index.ts +13 -2
- package/src/commands/build.ts +2 -0
- package/src/commands/dependency.ts +230 -0
- package/src/commands/index.ts +1 -1
- package/src/index.ts +29 -5
- package/tsconfig.json +1 -0
package/bin/.env.sand
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NODE_OPTIONS=--loader ts-node/esm
|
package/bin/run
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node ./node_modules/dotenv-cli/cli.js -e ./node_modules/sandstone-cli/bin/.env.sand node ./node_modules/sandstone-cli/lib/index.js $1
|
package/lib/build/index.d.ts
CHANGED
package/lib/build/index.js
CHANGED
|
@@ -182,6 +182,12 @@ async function _buildProject(cliOptions, { absProjectFolder, projectFolder, root
|
|
|
182
182
|
if (error) {
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
|
+
/// Add new dependencies ///
|
|
186
|
+
if (cliOptions.dependencies) {
|
|
187
|
+
for (const dependency of cliOptions.dependencies) {
|
|
188
|
+
sandstonePack.core.depend(...dependency);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
185
191
|
/// SAVING RESULTS ///
|
|
186
192
|
// Setup the cache if it doesn't exist.
|
|
187
193
|
// This cache is here to avoid writing files on disk when they did not change.
|
|
@@ -418,6 +424,7 @@ async function _buildProject(cliOptions, { absProjectFolder, projectFolder, root
|
|
|
418
424
|
await fs.writeFile(cacheFile, JSON.stringify(cache));
|
|
419
425
|
// Run the afterAll script
|
|
420
426
|
await ((_g = scripts === null || scripts === void 0 ? void 0 : scripts.afterAll) === null || _g === void 0 ? void 0 : _g.call(scripts));
|
|
427
|
+
console.log(`Pack(s) compiled! View output in ./.sandstone/output/`);
|
|
421
428
|
}
|
|
422
429
|
/**
|
|
423
430
|
* Build the project. Will log errors and never throw any.
|
package/lib/commands/build.d.ts
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function installNativeCommand(): Promise<void>;
|
|
2
|
+
export declare function installVanillaCommand(_libraries: string[]): Promise<void>;
|
|
3
|
+
export declare function uninstallNativeCommand(): Promise<void>;
|
|
4
|
+
export declare function uninstallVanillaCommand(_libraries: string[]): Promise<void>;
|
|
5
|
+
export declare function refreshCommand(): Promise<void>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { buildCommand } from './build.js';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
const _fetch = import('node-fetch');
|
|
6
|
+
export async function installNativeCommand() {
|
|
7
|
+
console.log('unimplemented');
|
|
8
|
+
}
|
|
9
|
+
export async function installVanillaCommand(_libraries) {
|
|
10
|
+
let libraries = _libraries.map((lib) => [lib, false]);
|
|
11
|
+
let count = (libraries === null || libraries === void 0 ? void 0 : libraries.length) || 0;
|
|
12
|
+
let manifest = false;
|
|
13
|
+
try {
|
|
14
|
+
manifest = JSON.parse(await fs.readFile(path.resolve('./resources/smithed.json'), 'utf-8'));
|
|
15
|
+
}
|
|
16
|
+
catch (e) { }
|
|
17
|
+
const fetch = (await _fetch).default;
|
|
18
|
+
const base = 'https://api.smithed.dev/v2';
|
|
19
|
+
const search = async (term) => {
|
|
20
|
+
const options = [];
|
|
21
|
+
const optionColumn = [0, 0, 0];
|
|
22
|
+
for await (const { id, displayName } of await (await fetch(`${base}/packs?category=Library&sort=downloads${term ? `&search=${term}` : ''}`)).json()) {
|
|
23
|
+
const meta = await (await fetch(`${base}/packs/${id}/meta`)).json();
|
|
24
|
+
const owner = await (await fetch(`${base}/users/${meta.owner}`)).json();
|
|
25
|
+
const { display: { description } } = await (await fetch(`${base}/packs/${id}`)).json();
|
|
26
|
+
const option = {
|
|
27
|
+
id: meta.rawId,
|
|
28
|
+
name: displayName,
|
|
29
|
+
owner: owner.displayName,
|
|
30
|
+
downloads: `${meta.stats.downloads.total}`,
|
|
31
|
+
description: description,
|
|
32
|
+
};
|
|
33
|
+
if (manifest && !manifest[id] && !manifest[meta.rawId]) {
|
|
34
|
+
if (option.name.length > optionColumn[0])
|
|
35
|
+
optionColumn[0] = option.name.length;
|
|
36
|
+
if (option.owner.length > optionColumn[1])
|
|
37
|
+
optionColumn[1] = option.owner.length;
|
|
38
|
+
if (option.downloads.length > optionColumn[2])
|
|
39
|
+
optionColumn[2] = option.downloads.length;
|
|
40
|
+
options.push(option);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const space = (index, option) => {
|
|
44
|
+
const length = optionColumn[index] - option.length;
|
|
45
|
+
let _space = '';
|
|
46
|
+
for (let i = 0; i < length; i++) {
|
|
47
|
+
_space += ' ';
|
|
48
|
+
}
|
|
49
|
+
return `${_space} - `;
|
|
50
|
+
};
|
|
51
|
+
if (options.length === 0) {
|
|
52
|
+
console.log('No results found!');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const { selected } = await inquirer.prompt({
|
|
56
|
+
name: 'selected',
|
|
57
|
+
type: 'checkbox',
|
|
58
|
+
message: 'Which libraries to add?',
|
|
59
|
+
choices: options.map((option) => ({
|
|
60
|
+
name: `${option.name}${space(0, option.name)}by ${option.owner}${space(1, option.owner)}${option.downloads} downloads${space(2, option.downloads)}${option.description}`,
|
|
61
|
+
short: `${option.name} - by ${option.owner} - ${option.downloads} downloads - ${option.description}`,
|
|
62
|
+
value: [option.id, true],
|
|
63
|
+
})),
|
|
64
|
+
});
|
|
65
|
+
if (selected && selected.length !== 0) {
|
|
66
|
+
libraries.push(...selected);
|
|
67
|
+
count += selected.length;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
73
|
+
if (count === 0) {
|
|
74
|
+
await search();
|
|
75
|
+
}
|
|
76
|
+
if (count > 0) {
|
|
77
|
+
let adding = false;
|
|
78
|
+
for await (const [library, searched] of libraries) {
|
|
79
|
+
const version = library.includes('@') ? library.split('@')[1] : 'latest';
|
|
80
|
+
if (!manifest || !(manifest[library] || manifest[library] === version)) {
|
|
81
|
+
if (searched) {
|
|
82
|
+
if (!adding)
|
|
83
|
+
adding = [];
|
|
84
|
+
adding.push([library, version]);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
let exists = false;
|
|
88
|
+
try {
|
|
89
|
+
/* @ts-ignore */
|
|
90
|
+
exists = (await (await fetch(`${base}/packs/${library}/meta`)).json()).statusCode !== 404;
|
|
91
|
+
}
|
|
92
|
+
catch (e) { }
|
|
93
|
+
if (exists) {
|
|
94
|
+
if (!adding)
|
|
95
|
+
adding = [];
|
|
96
|
+
adding.push([library, version]);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
count--;
|
|
100
|
+
console.log(`${library} doesn't exist! Searching...`);
|
|
101
|
+
if (await search(library)) {
|
|
102
|
+
if (!adding)
|
|
103
|
+
adding = [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
count--;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (adding) {
|
|
113
|
+
await buildCommand({
|
|
114
|
+
path: './src',
|
|
115
|
+
configPath: './',
|
|
116
|
+
dependencies: adding
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
console.log;
|
|
121
|
+
console.log(`${count} libraries added`);
|
|
122
|
+
}
|
|
123
|
+
export async function uninstallNativeCommand() {
|
|
124
|
+
console.log('unimplemented');
|
|
125
|
+
}
|
|
126
|
+
export async function uninstallVanillaCommand(_libraries) {
|
|
127
|
+
const libraries = _libraries || [];
|
|
128
|
+
let count = (libraries === null || libraries === void 0 ? void 0 : libraries.length) || 0;
|
|
129
|
+
let manifestPath = path.resolve('./resources/smithed.json');
|
|
130
|
+
let manifest = false;
|
|
131
|
+
let lockFilePath = path.resolve('./resources/cache/lock-smithed.json');
|
|
132
|
+
let lockFile = false;
|
|
133
|
+
try {
|
|
134
|
+
manifest = JSON.parse(await fs.readFile(manifestPath, 'utf-8'));
|
|
135
|
+
lockFile = JSON.parse(await fs.readFile(lockFilePath, 'utf-8'));
|
|
136
|
+
}
|
|
137
|
+
catch (e) { }
|
|
138
|
+
if (manifest) {
|
|
139
|
+
if (count === 0) {
|
|
140
|
+
const { selected } = await inquirer.prompt({
|
|
141
|
+
name: 'selected',
|
|
142
|
+
type: 'checkbox',
|
|
143
|
+
message: 'Which libraries to remove?',
|
|
144
|
+
choices: Object.entries(manifest).map(([name]) => ({
|
|
145
|
+
short: name,
|
|
146
|
+
value: name,
|
|
147
|
+
})),
|
|
148
|
+
});
|
|
149
|
+
if (selected && selected.length !== 0) {
|
|
150
|
+
count = selected.length;
|
|
151
|
+
libraries.push(...selected);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (count > 0) {
|
|
155
|
+
for await (const library of libraries) {
|
|
156
|
+
if (manifest[library]) {
|
|
157
|
+
delete manifest[library];
|
|
158
|
+
await fs.remove(path.resolve(`./resources/cache/smithed/${library}`));
|
|
159
|
+
if (lockFile) {
|
|
160
|
+
delete lockFile[library];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
count--;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
await fs.writeFile(manifestPath, JSON.stringify(manifest));
|
|
168
|
+
if (lockFile) {
|
|
169
|
+
await fs.writeFile(lockFilePath, JSON.stringify(lockFile));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.error('error: no dependency manifest');
|
|
175
|
+
}
|
|
176
|
+
if (count === 0 && manifest) {
|
|
177
|
+
console.log('Libraries not found, installed libraries:');
|
|
178
|
+
Object.entries(manifest).forEach(([lib]) => console.log(lib));
|
|
179
|
+
}
|
|
180
|
+
console.log(`${count} libraries removed`);
|
|
181
|
+
}
|
|
182
|
+
export async function refreshCommand() { }
|
package/lib/commands/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { buildCommand } from './build.js';
|
|
2
2
|
export { createCommand } from './create.js';
|
|
3
|
+
export { installNativeCommand, installVanillaCommand, uninstallNativeCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js';
|
|
3
4
|
export { watchCommand } from './watch.js';
|
package/lib/commands/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { buildCommand } from './build.js';
|
|
2
2
|
export { createCommand } from './create.js';
|
|
3
|
-
|
|
3
|
+
export { installNativeCommand, installVanillaCommand, uninstallNativeCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js';
|
|
4
4
|
export { watchCommand } from './watch.js';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Argument, Command } from 'commander';
|
|
3
3
|
import figlet from 'figlet';
|
|
4
|
-
import { buildCommand, createCommand, watchCommand } from './commands/index.js';
|
|
4
|
+
import { buildCommand, createCommand, watchCommand, installNativeCommand, installVanillaCommand, uninstallVanillaCommand, refreshCommand } from './commands/index.js';
|
|
5
5
|
const commander = new Command();
|
|
6
6
|
console.log(figlet.textSync('Sandstone'));
|
|
7
7
|
const CLI = commander
|
|
@@ -70,8 +70,30 @@ create.option.apply(create, BuildDeclares.name)
|
|
|
70
70
|
.option.apply(create, BuildDeclares.clientPath)
|
|
71
71
|
.option.apply(create, BuildDeclares.serverPath);
|
|
72
72
|
// TODO
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
const install = CLI
|
|
74
|
+
.command('install')
|
|
75
|
+
.alias('add')
|
|
76
|
+
.alias('i')
|
|
77
|
+
.description('Install Native Sandstone or Vanilla Smithed libraries. ⛏');
|
|
78
|
+
install
|
|
79
|
+
.command('native')
|
|
80
|
+
.description('Install Native Sandstone libraries. ⛏')
|
|
81
|
+
.action(installNativeCommand)
|
|
82
|
+
.addArgument(new Argument('[libraries...]', 'Optional. Libraries to install. When unlisted, a selector will appear.'));
|
|
83
|
+
install
|
|
84
|
+
.command('vanilla')
|
|
85
|
+
.alias('smithed')
|
|
86
|
+
.description('Install Vanilla Smithed libraries. ⛏')
|
|
87
|
+
.action(installVanillaCommand)
|
|
88
|
+
.addArgument(new Argument('[libraries...]', 'Optional. Libraries to install. When unlisted, a selector will appear.'));
|
|
89
|
+
CLI
|
|
90
|
+
.command('uninstall')
|
|
91
|
+
.alias('remove')
|
|
92
|
+
.description('Uninstall Vanilla Smithed libraries. ⛏')
|
|
93
|
+
.action(uninstallVanillaCommand)
|
|
94
|
+
.addArgument(new Argument('[libraries...]', 'Optional. Libraries to uninstall. When unlisted, a selector will appear.'));
|
|
95
|
+
CLI
|
|
96
|
+
.command('refresh')
|
|
97
|
+
.description('Clear & update cached Smithed libraries. ⛏')
|
|
98
|
+
.action(refreshCommand);
|
|
77
99
|
CLI.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sandstone-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "The CLI for Sandstone - the minecraft pack creation library.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"sand": "./
|
|
8
|
+
"sand": "./bin/run"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo NO TESTS",
|
|
@@ -48,11 +48,13 @@
|
|
|
48
48
|
"chokidar": "^3.5.3",
|
|
49
49
|
"commander": "^10.0.1",
|
|
50
50
|
"delete-empty": "^3.0.0",
|
|
51
|
+
"dotenv-cli": "^7.3.0",
|
|
51
52
|
"figlet": "^1.6.0",
|
|
52
53
|
"fs-extra": "^11.1.1",
|
|
53
54
|
"inquirer": "^9.2.11",
|
|
54
55
|
"klaw": "^4.1.0",
|
|
55
56
|
"nanoid": "^4.0.2",
|
|
57
|
+
"node-fetch": "^3.3.2",
|
|
56
58
|
"pretty-error": "^4.0.0",
|
|
57
59
|
"semver": "^7.5.4",
|
|
58
60
|
"ts-node": "^10.9.1"
|
package/src/build/index.ts
CHANGED
|
@@ -21,8 +21,8 @@ type BuildOptions = {
|
|
|
21
21
|
production?: boolean
|
|
22
22
|
|
|
23
23
|
// Values
|
|
24
|
-
path: string
|
|
25
|
-
configPath: string
|
|
24
|
+
path: string
|
|
25
|
+
configPath: string
|
|
26
26
|
name?: string
|
|
27
27
|
namespace?: string
|
|
28
28
|
world?: string
|
|
@@ -31,6 +31,8 @@ type BuildOptions = {
|
|
|
31
31
|
|
|
32
32
|
// TODO: implement ssh
|
|
33
33
|
ssh?: any
|
|
34
|
+
|
|
35
|
+
dependencies?: [string, string][]
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
const pe = new PrettyError()
|
|
@@ -254,6 +256,13 @@ async function _buildProject(cliOptions: BuildOptions, { absProjectFolder, proje
|
|
|
254
256
|
return
|
|
255
257
|
}
|
|
256
258
|
|
|
259
|
+
/// Add new dependencies ///
|
|
260
|
+
if (cliOptions.dependencies) {
|
|
261
|
+
for (const dependency of cliOptions.dependencies) {
|
|
262
|
+
sandstonePack.core.depend(...dependency)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
257
266
|
/// SAVING RESULTS ///
|
|
258
267
|
// Setup the cache if it doesn't exist.
|
|
259
268
|
// This cache is here to avoid writing files on disk when they did not change.
|
|
@@ -538,6 +547,8 @@ async function _buildProject(cliOptions: BuildOptions, { absProjectFolder, proje
|
|
|
538
547
|
|
|
539
548
|
// Run the afterAll script
|
|
540
549
|
await scripts?.afterAll?.()
|
|
550
|
+
|
|
551
|
+
console.log(`Pack(s) compiled! View output in ./.sandstone/output/`)
|
|
541
552
|
}
|
|
542
553
|
|
|
543
554
|
/**
|
package/src/commands/build.ts
CHANGED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import fs from 'fs-extra'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { buildCommand } from './build.js'
|
|
4
|
+
import inquirer from 'inquirer'
|
|
5
|
+
|
|
6
|
+
const _fetch = import('node-fetch')
|
|
7
|
+
|
|
8
|
+
export async function installNativeCommand() {
|
|
9
|
+
console.log('unimplemented')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type SmithedSearch = { id: string, displayName: string }[]
|
|
13
|
+
|
|
14
|
+
type SmithedMeta = { rawId: string, stats: { downloads: { total: number } }, owner: string }
|
|
15
|
+
|
|
16
|
+
type SmithedUser = { displayName: string }
|
|
17
|
+
|
|
18
|
+
type SmithedPack = { display: { description: string } }
|
|
19
|
+
|
|
20
|
+
export async function installVanillaCommand(_libraries: string[]) {
|
|
21
|
+
let libraries: [string, boolean][] = _libraries.map((lib) => [lib, false])
|
|
22
|
+
|
|
23
|
+
let count = libraries?.length || 0
|
|
24
|
+
|
|
25
|
+
let manifest: Record<string, string> | false = false
|
|
26
|
+
try {
|
|
27
|
+
manifest = JSON.parse(await fs.readFile(path.resolve('./resources/smithed.json'), 'utf-8'))
|
|
28
|
+
} catch (e) {}
|
|
29
|
+
|
|
30
|
+
const fetch = (await _fetch).default
|
|
31
|
+
const base = 'https://api.smithed.dev/v2'
|
|
32
|
+
|
|
33
|
+
const search = async (term?: string) => {
|
|
34
|
+
const options = []
|
|
35
|
+
|
|
36
|
+
const optionColumn = [0, 0, 0]
|
|
37
|
+
|
|
38
|
+
for await (const { id, displayName } of (await (await fetch(`${base}/packs?category=Library&sort=downloads${term ? `&search=${term}` : ''}`)).json() as SmithedSearch)) {
|
|
39
|
+
|
|
40
|
+
const meta = await (await fetch(`${base}/packs/${id}/meta`)).json() as SmithedMeta
|
|
41
|
+
const owner = await(await fetch(`${base}/users/${meta.owner}`)).json() as SmithedUser
|
|
42
|
+
const { display: { description }} = await(await fetch(`${base}/packs/${id}`)).json() as SmithedPack
|
|
43
|
+
|
|
44
|
+
const option = {
|
|
45
|
+
id: meta.rawId,
|
|
46
|
+
name: displayName,
|
|
47
|
+
owner: owner.displayName,
|
|
48
|
+
downloads: `${meta.stats.downloads.total}`,
|
|
49
|
+
description: description,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (manifest && !manifest[id] && !manifest[meta.rawId]) {
|
|
53
|
+
|
|
54
|
+
if (option.name.length > optionColumn[0]) optionColumn[0] = option.name.length
|
|
55
|
+
|
|
56
|
+
if (option.owner.length > optionColumn[1]) optionColumn[1] = option.owner.length
|
|
57
|
+
|
|
58
|
+
if (option.downloads.length > optionColumn[2]) optionColumn[2] = option.downloads.length
|
|
59
|
+
|
|
60
|
+
options.push(option)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const space = (index: number, option: string) => {
|
|
65
|
+
const length = optionColumn[index] - option.length
|
|
66
|
+
|
|
67
|
+
let _space = ''
|
|
68
|
+
|
|
69
|
+
for (let i = 0; i < length; i++) {
|
|
70
|
+
_space += ' '
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return `${_space} - `
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (options.length === 0) {
|
|
77
|
+
console.log('No results found!')
|
|
78
|
+
} else {
|
|
79
|
+
const { selected } = await inquirer.prompt({
|
|
80
|
+
name: 'selected',
|
|
81
|
+
type: 'checkbox',
|
|
82
|
+
message: 'Which libraries to add?',
|
|
83
|
+
choices: options.map((option) => ({
|
|
84
|
+
name: `${option.name}${space(0, option.name)}by ${option.owner}${space(1, option.owner)}${option.downloads} downloads${space(2, option.downloads)}${option.description}`,
|
|
85
|
+
short: `${option.name} - by ${option.owner} - ${option.downloads} downloads - ${option.description}`,
|
|
86
|
+
value: [option.id, true],
|
|
87
|
+
})),
|
|
88
|
+
}) as {
|
|
89
|
+
selected: [string, true][]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (selected && selected.length !== 0) {
|
|
93
|
+
libraries.push(...selected)
|
|
94
|
+
|
|
95
|
+
count += selected.length
|
|
96
|
+
|
|
97
|
+
return true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (count === 0) {
|
|
104
|
+
await search()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (count > 0) {
|
|
108
|
+
|
|
109
|
+
let adding: [string, string][] | false = false
|
|
110
|
+
|
|
111
|
+
for await (const [library, searched] of libraries) {
|
|
112
|
+
const version = library.includes('@') ? library.split('@')[1] : 'latest'
|
|
113
|
+
|
|
114
|
+
if (!manifest || !(manifest[library] || manifest[library] === version)) {
|
|
115
|
+
if (searched) {
|
|
116
|
+
if (!adding) adding = []
|
|
117
|
+
adding.push([library, version])
|
|
118
|
+
} else {
|
|
119
|
+
let exists = false
|
|
120
|
+
try {
|
|
121
|
+
/* @ts-ignore */
|
|
122
|
+
exists = (await (await fetch(`${base}/packs/${library}/meta`)).json()).statusCode !== 404
|
|
123
|
+
} catch (e) {}
|
|
124
|
+
|
|
125
|
+
if (exists) {
|
|
126
|
+
if (!adding) adding = []
|
|
127
|
+
adding.push([library, version])
|
|
128
|
+
} else {
|
|
129
|
+
count--
|
|
130
|
+
|
|
131
|
+
console.log(`${library} doesn't exist! Searching...`)
|
|
132
|
+
|
|
133
|
+
if (await search(library)) {
|
|
134
|
+
if (!adding) adding = []
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
count--
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (adding) {
|
|
143
|
+
await buildCommand({
|
|
144
|
+
path: './src',
|
|
145
|
+
configPath: './',
|
|
146
|
+
dependencies: adding
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log
|
|
152
|
+
console.log(`${count} libraries added`)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function uninstallNativeCommand() {
|
|
156
|
+
console.log('unimplemented')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function uninstallVanillaCommand(_libraries: string[]) {
|
|
160
|
+
const libraries = _libraries || []
|
|
161
|
+
|
|
162
|
+
let count = libraries?.length || 0
|
|
163
|
+
|
|
164
|
+
let manifestPath = path.resolve('./resources/smithed.json')
|
|
165
|
+
|
|
166
|
+
let manifest: Record<string, string> | false = false
|
|
167
|
+
|
|
168
|
+
let lockFilePath = path.resolve('./resources/cache/lock-smithed.json')
|
|
169
|
+
|
|
170
|
+
let lockFile: Record<string, {}> | false = false
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
manifest = JSON.parse(await fs.readFile(manifestPath, 'utf-8'))
|
|
174
|
+
lockFile = JSON.parse(await fs.readFile(lockFilePath, 'utf-8'))
|
|
175
|
+
} catch (e) {}
|
|
176
|
+
|
|
177
|
+
if (manifest) {
|
|
178
|
+
if (count === 0) {
|
|
179
|
+
const { selected } = await inquirer.prompt({
|
|
180
|
+
name: 'selected',
|
|
181
|
+
type: 'checkbox',
|
|
182
|
+
message: 'Which libraries to remove?',
|
|
183
|
+
choices: Object.entries(manifest).map(([name]) => ({
|
|
184
|
+
short: name,
|
|
185
|
+
value: name,
|
|
186
|
+
})),
|
|
187
|
+
}) as {
|
|
188
|
+
selected: string[]
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (selected && selected.length !== 0) {
|
|
192
|
+
count = selected.length
|
|
193
|
+
|
|
194
|
+
libraries.push(...selected)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (count > 0) {
|
|
199
|
+
for await (const library of libraries) {
|
|
200
|
+
if (manifest[library]) {
|
|
201
|
+
delete manifest[library]
|
|
202
|
+
|
|
203
|
+
await fs.remove(path.resolve(`./resources/cache/smithed/${library}`))
|
|
204
|
+
|
|
205
|
+
if (lockFile) {
|
|
206
|
+
delete lockFile[library]
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
count--
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
await fs.writeFile(manifestPath, JSON.stringify(manifest))
|
|
213
|
+
|
|
214
|
+
if (lockFile) {
|
|
215
|
+
await fs.writeFile(lockFilePath, JSON.stringify(lockFile))
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
console.error('error: no dependency manifest')
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (count === 0 && manifest) {
|
|
223
|
+
console.log('Libraries not found, installed libraries:')
|
|
224
|
+
Object.entries(manifest).forEach(([lib]) => console.log(lib))
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
console.log(`${count} libraries removed`)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export async function refreshCommand() {}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { buildCommand } from './build.js';
|
|
2
2
|
export { createCommand } from './create.js';
|
|
3
|
-
|
|
3
|
+
export { installNativeCommand, installVanillaCommand, uninstallNativeCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js'
|
|
4
4
|
export { watchCommand } from './watch.js';
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Argument, Command } from 'commander';
|
|
3
3
|
import figlet from 'figlet';
|
|
4
|
-
import { buildCommand, createCommand, watchCommand } from './commands/index.js';
|
|
4
|
+
import { buildCommand, createCommand, watchCommand, installNativeCommand, installVanillaCommand, uninstallNativeCommand, uninstallVanillaCommand, refreshCommand } from './commands/index.js';
|
|
5
5
|
|
|
6
6
|
const commander = new Command()
|
|
7
7
|
|
|
@@ -84,10 +84,34 @@ create.option.apply(create, BuildDeclares.name)
|
|
|
84
84
|
.option.apply(create, BuildDeclares.serverPath)
|
|
85
85
|
|
|
86
86
|
// TODO
|
|
87
|
-
|
|
88
|
-
.command('
|
|
89
|
-
.
|
|
90
|
-
.
|
|
87
|
+
const install = CLI
|
|
88
|
+
.command('install')
|
|
89
|
+
.alias('add')
|
|
90
|
+
.alias('i')
|
|
91
|
+
.description('Install Native Sandstone or Vanilla Smithed libraries. ⛏')
|
|
92
|
+
install
|
|
93
|
+
.command('native')
|
|
94
|
+
.description('Install Native Sandstone libraries. ⛏')
|
|
95
|
+
.action(installNativeCommand)
|
|
96
|
+
.addArgument(new Argument('[libraries...]', 'Optional. Libraries to install. When unlisted, a selector will appear.'))
|
|
97
|
+
install
|
|
98
|
+
.command('vanilla')
|
|
99
|
+
.alias('smithed')
|
|
100
|
+
.description('Install Vanilla Smithed libraries. ⛏')
|
|
101
|
+
.action(installVanillaCommand)
|
|
102
|
+
.addArgument(new Argument('[libraries...]', 'Optional. Libraries to install. When unlisted, a selector will appear.'))
|
|
103
|
+
|
|
104
|
+
CLI
|
|
105
|
+
.command('uninstall')
|
|
106
|
+
.alias('remove')
|
|
107
|
+
.description('Uninstall Vanilla Smithed libraries. ⛏')
|
|
108
|
+
.action(uninstallVanillaCommand)
|
|
109
|
+
.addArgument(new Argument('[libraries...]', 'Optional. Libraries to uninstall. When unlisted, a selector will appear.'))
|
|
110
|
+
|
|
111
|
+
CLI
|
|
112
|
+
.command('refresh')
|
|
113
|
+
.description('Clear & update cached Smithed libraries. ⛏')
|
|
114
|
+
.action(refreshCommand)
|
|
91
115
|
|
|
92
116
|
|
|
93
117
|
CLI.parse(process.argv)
|