sandstone-cli 2.0.5 → 2.0.7
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/lib/commands/build.js +49 -8
- package/lib/commands/create.js +1 -1
- package/lib/create.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/commands/build.ts +50 -8
- package/src/commands/create.ts +1 -1
- package/src/create.ts +1 -1
- package/src/index.ts +1 -1
package/lib/commands/build.js
CHANGED
|
@@ -116,23 +116,64 @@ function countResources(sandstonePack) {
|
|
|
116
116
|
}
|
|
117
117
|
return { functions, other };
|
|
118
118
|
}
|
|
119
|
+
function splitPath(split) {
|
|
120
|
+
let parts = [];
|
|
121
|
+
let current = split;
|
|
122
|
+
while (current !== 'C:') {
|
|
123
|
+
let dirname = path.dirname(current);
|
|
124
|
+
if (dirname.endsWith('\\')) {
|
|
125
|
+
dirname = dirname.slice(0, -1);
|
|
126
|
+
}
|
|
127
|
+
parts.unshift(current.replace(`${dirname}${path.sep}`, ''));
|
|
128
|
+
current = dirname;
|
|
129
|
+
}
|
|
130
|
+
parts.unshift('C:');
|
|
131
|
+
return parts;
|
|
132
|
+
}
|
|
119
133
|
async function handleSymlink(folder, packName, cache, minecraftPath, targetPath, linkPath) {
|
|
120
|
-
|
|
134
|
+
let rawPath = path.resolve(path.join(folder));
|
|
135
|
+
let sep = path.sep;
|
|
136
|
+
if (os.platform() === 'win32') {
|
|
137
|
+
sep = `${path.sep}${path.sep}`;
|
|
138
|
+
rawPath = splitPath(rawPath).join(sep);
|
|
139
|
+
}
|
|
140
|
+
const allowPath = `[glob]${rawPath}${sep}**${sep}*`;
|
|
121
141
|
const allowedList = path.join(minecraftPath, 'allowed_symlinks.txt');
|
|
122
142
|
const comment = `# Sandstone Pack: ${packName}\n`;
|
|
123
143
|
try {
|
|
124
|
-
const currentlyAllowed = await fs.readFile(allowedList);
|
|
144
|
+
const currentlyAllowed = await fs.readFile(allowedList, 'utf-8');
|
|
125
145
|
if (!currentlyAllowed.includes(allowPath)) {
|
|
146
|
+
log('[handleSymlink] Adding workspace to allowed_symlinks.txt at minecraft path. If the game is running please restart it.');
|
|
126
147
|
await fs.writeFile(allowedList, `${currentlyAllowed}\n#\n${comment}${allowPath}`);
|
|
127
148
|
}
|
|
149
|
+
else {
|
|
150
|
+
log('[handleSymlink] Workspace is already in allowed_symlinks.txt at minecraft path, skipping...');
|
|
151
|
+
}
|
|
128
152
|
}
|
|
129
153
|
catch (e) {
|
|
154
|
+
log('[handleSymlink] Creating allowed_symlinks.txt at minecraft path. If the game is running please restart it.');
|
|
130
155
|
await fs.writeFile(allowedList, `${comment}${allowPath}`);
|
|
131
156
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
157
|
+
let skip = false;
|
|
158
|
+
let errored = false;
|
|
159
|
+
try {
|
|
160
|
+
const stats = await fs.lstat(linkPath);
|
|
161
|
+
if (stats.isSymbolicLink() && await fs.readlink(linkPath) === path.resolve(targetPath)) {
|
|
162
|
+
log('[handleSymlink] Symlink already created, skipping...');
|
|
163
|
+
skip = true;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
errored = true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch { }
|
|
170
|
+
if (errored) {
|
|
171
|
+
throw new Error(`Tried to add a symlink at "${linkPath}",\n encountered an existing FS entry.`);
|
|
172
|
+
}
|
|
173
|
+
if (!skip) {
|
|
174
|
+
log(`[handleSymlink] Creating symlink for ${targetPath.replace(`${path.dirname(targetPath)}${path.sep}`, '')}`);
|
|
175
|
+
await fs.symlink(path.resolve(targetPath), linkPath);
|
|
176
|
+
}
|
|
136
177
|
cache.symlinks ??= [];
|
|
137
178
|
cache.symlinks.push(linkPath);
|
|
138
179
|
}
|
|
@@ -456,7 +497,7 @@ async function _buildProject(cliOptions, folder, silent = false, existingContext
|
|
|
456
497
|
}
|
|
457
498
|
else if (symlinksAvailable) {
|
|
458
499
|
if (cache.symlinks === undefined || !cache.symlinks.includes(fullClientPath)) {
|
|
459
|
-
handleSymlink(folder, packName, newCache, clientPath, outputPath, fullClientPath);
|
|
500
|
+
await handleSymlink(folder, packName, newCache, clientPath, outputPath, fullClientPath);
|
|
460
501
|
}
|
|
461
502
|
}
|
|
462
503
|
else {
|
|
@@ -473,7 +514,7 @@ async function _buildProject(cliOptions, folder, silent = false, existingContext
|
|
|
473
514
|
}
|
|
474
515
|
else if (symlinksAvailable) {
|
|
475
516
|
if (cache.symlinks === undefined || !cache.symlinks.includes(fullServerPath)) {
|
|
476
|
-
handleSymlink(folder, packName, newCache, serverPath, outputPath, fullServerPath);
|
|
517
|
+
await handleSymlink(folder, packName, newCache, serverPath, outputPath, fullServerPath);
|
|
477
518
|
}
|
|
478
519
|
}
|
|
479
520
|
else {
|
package/lib/commands/create.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function createCommand(_project, opts) {
|
|
|
24
24
|
default: false,
|
|
25
25
|
})) === true ? 'library' : 'pack';
|
|
26
26
|
const sv = (v) => new SemVer(v);
|
|
27
|
-
const versions = [[sv('1.0.0-beta.1'), sv('2.0.
|
|
27
|
+
const versions = [[sv('1.0.0-beta.1'), sv('2.0.7')]];
|
|
28
28
|
const version = await select({
|
|
29
29
|
message: 'Which version of Sandstone do you want to use? These are the only supported versions for new projects.',
|
|
30
30
|
choices: versions.map((v) => {
|
package/lib/create.js
CHANGED
|
@@ -6,7 +6,7 @@ import { BuildDeclares } from './shared.js';
|
|
|
6
6
|
const commander = new Command();
|
|
7
7
|
console.log(figlet.textSync('Sandstone'));
|
|
8
8
|
const createCLI = commander
|
|
9
|
-
.version('2.0.
|
|
9
|
+
.version('2.0.7')
|
|
10
10
|
.description('Create a new Sandstone project. ⛏')
|
|
11
11
|
.action(createCommand)
|
|
12
12
|
.addArgument(new Argument('<projectName>', 'Not the name of the output pack'));
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { BuildDeclares } from './shared.js';
|
|
|
6
6
|
const commander = new Command();
|
|
7
7
|
console.log(figlet.textSync('Sandstone'));
|
|
8
8
|
const CLI = commander
|
|
9
|
-
.version('2.0.
|
|
9
|
+
.version('2.0.7', '-v, --version')
|
|
10
10
|
.description('The CLI for Sandstone - the minecraft pack creation library.');
|
|
11
11
|
const build = CLI
|
|
12
12
|
.command('build')
|
package/package.json
CHANGED
package/src/commands/build.ts
CHANGED
|
@@ -187,26 +187,68 @@ function countResources(sandstonePack: { core: { resourceNodes: Iterable<{ resou
|
|
|
187
187
|
return { functions, other }
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
function splitPath(split: string) {
|
|
191
|
+
let parts: string[] = []
|
|
192
|
+
let current = split
|
|
193
|
+
|
|
194
|
+
while (current !== 'C:') {
|
|
195
|
+
let dirname = path.dirname(current)
|
|
196
|
+
if (dirname.endsWith('\\')) {
|
|
197
|
+
dirname = dirname.slice(0, -1)
|
|
198
|
+
}
|
|
199
|
+
parts.unshift(current.replace(`${dirname}${path.sep}`, ''))
|
|
200
|
+
current = dirname
|
|
201
|
+
}
|
|
202
|
+
parts.unshift('C:')
|
|
203
|
+
return parts
|
|
204
|
+
}
|
|
205
|
+
|
|
190
206
|
async function handleSymlink(folder: string, packName: string, cache: SandstoneCache, minecraftPath: string, targetPath: string, linkPath: string) {
|
|
191
|
-
|
|
207
|
+
let rawPath = path.resolve(path.join(folder))
|
|
208
|
+
let sep: string = path.sep
|
|
209
|
+
if (os.platform() === 'win32') {
|
|
210
|
+
sep = `${path.sep}${path.sep}`
|
|
211
|
+
|
|
212
|
+
rawPath = splitPath(rawPath).join(sep)
|
|
213
|
+
}
|
|
214
|
+
const allowPath = `[glob]${rawPath}${sep}**${sep}*`
|
|
192
215
|
|
|
193
216
|
const allowedList = path.join(minecraftPath, 'allowed_symlinks.txt')
|
|
194
217
|
|
|
195
218
|
const comment = `# Sandstone Pack: ${packName}\n`
|
|
196
219
|
try {
|
|
197
|
-
const currentlyAllowed = await fs.readFile(allowedList)
|
|
220
|
+
const currentlyAllowed = await fs.readFile(allowedList, 'utf-8')
|
|
198
221
|
|
|
199
222
|
if (!currentlyAllowed.includes(allowPath)) {
|
|
223
|
+
log('[handleSymlink] Adding workspace to allowed_symlinks.txt at minecraft path. If the game is running please restart it.')
|
|
200
224
|
await fs.writeFile(allowedList, `${currentlyAllowed}\n#\n${comment}${allowPath}`)
|
|
225
|
+
} else {
|
|
226
|
+
log('[handleSymlink] Workspace is already in allowed_symlinks.txt at minecraft path, skipping...')
|
|
201
227
|
}
|
|
202
228
|
} catch (e) {
|
|
229
|
+
log('[handleSymlink] Creating allowed_symlinks.txt at minecraft path. If the game is running please restart it.')
|
|
203
230
|
await fs.writeFile(allowedList, `${comment}${allowPath}`)
|
|
204
231
|
}
|
|
205
232
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
233
|
+
let skip = false
|
|
234
|
+
let errored = false
|
|
235
|
+
try {
|
|
236
|
+
const stats = await fs.lstat(linkPath)
|
|
237
|
+
if (stats.isSymbolicLink() && await fs.readlink(linkPath) === path.resolve(targetPath)) {
|
|
238
|
+
log('[handleSymlink] Symlink already created, skipping...')
|
|
239
|
+
skip = true
|
|
240
|
+
} else {
|
|
241
|
+
errored = true
|
|
242
|
+
}
|
|
243
|
+
} catch {}
|
|
244
|
+
if (errored) {
|
|
245
|
+
throw new Error(`Tried to add a symlink at "${linkPath}",\n encountered an existing FS entry.`)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (!skip) {
|
|
249
|
+
log(`[handleSymlink] Creating symlink for ${targetPath.replace(`${path.dirname(targetPath)}${path.sep}`, '')}`)
|
|
250
|
+
await fs.symlink(path.resolve(targetPath), linkPath)
|
|
251
|
+
}
|
|
210
252
|
cache.symlinks ??= []
|
|
211
253
|
cache.symlinks.push(linkPath)
|
|
212
254
|
}
|
|
@@ -609,7 +651,7 @@ async function _buildProject(
|
|
|
609
651
|
await fs.copyFile(archivePath, `${fullClientPath}.zip`)
|
|
610
652
|
} else if (symlinksAvailable) {
|
|
611
653
|
if (cache.symlinks === undefined || !cache.symlinks.includes(fullClientPath)) {
|
|
612
|
-
handleSymlink(
|
|
654
|
+
await handleSymlink(
|
|
613
655
|
folder,
|
|
614
656
|
packName,
|
|
615
657
|
newCache,
|
|
@@ -633,7 +675,7 @@ async function _buildProject(
|
|
|
633
675
|
await fs.copyFile(archivePath, `${fullServerPath}.zip`)
|
|
634
676
|
} else if (symlinksAvailable) {
|
|
635
677
|
if (cache.symlinks === undefined || !cache.symlinks.includes(fullServerPath)) {
|
|
636
|
-
handleSymlink(
|
|
678
|
+
await handleSymlink(
|
|
637
679
|
folder,
|
|
638
680
|
packName,
|
|
639
681
|
newCache,
|
package/src/commands/create.ts
CHANGED
|
@@ -42,7 +42,7 @@ export async function createCommand(_project: string, opts: CreateOptions) {
|
|
|
42
42
|
|
|
43
43
|
const sv = (v: string) => new SemVer(v)
|
|
44
44
|
|
|
45
|
-
const versions = [[sv('1.0.0-beta.1'), sv('2.0.
|
|
45
|
+
const versions = [[sv('1.0.0-beta.1'), sv('2.0.7')]] as const
|
|
46
46
|
|
|
47
47
|
const version = await select({
|
|
48
48
|
message: 'Which version of Sandstone do you want to use? These are the only supported versions for new projects.',
|
package/src/create.ts
CHANGED
|
@@ -9,7 +9,7 @@ const commander = new Command()
|
|
|
9
9
|
console.log(figlet.textSync('Sandstone'));
|
|
10
10
|
|
|
11
11
|
const createCLI = commander
|
|
12
|
-
.version('2.0.
|
|
12
|
+
.version('2.0.7')
|
|
13
13
|
.description('Create a new Sandstone project. ⛏')
|
|
14
14
|
.action(createCommand)
|
|
15
15
|
.addArgument(new Argument('<projectName>', 'Not the name of the output pack'))
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ const commander = new Command()
|
|
|
9
9
|
console.log(figlet.textSync('Sandstone'));
|
|
10
10
|
|
|
11
11
|
const CLI = commander
|
|
12
|
-
.version('2.0.
|
|
12
|
+
.version('2.0.7', '-v, --version')
|
|
13
13
|
.description('The CLI for Sandstone - the minecraft pack creation library.')
|
|
14
14
|
|
|
15
15
|
const build = CLI
|