sandstone-cli 0.5.4 → 0.6.0
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/README.md +5 -5
- package/bin/run +0 -0
- package/lib/{buildProject.d.ts → build/buildProject.d.ts} +4 -2
- package/lib/{buildProject.js → build/buildProject.js} +126 -31
- package/lib/build/graph.d.ts +49 -0
- package/lib/build/graph.js +197 -0
- package/lib/commands/build.js +3 -3
- package/lib/commands/create.js +15 -15
- package/lib/commands/update.js +18 -18
- package/lib/commands/watch.js +19 -9
- package/lib/utils.js +3 -3
- package/oclif.manifest.json +1 -1
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ $ npm install -g sandstone-cli
|
|
|
19
19
|
$ sand COMMAND
|
|
20
20
|
running command...
|
|
21
21
|
$ sand (-v|--version|version)
|
|
22
|
-
sandstone-cli/0.
|
|
22
|
+
sandstone-cli/0.6.0 linux-x64 node-v16.19.0
|
|
23
23
|
$ sand --help [COMMAND]
|
|
24
24
|
USAGE
|
|
25
25
|
$ sand COMMAND
|
|
@@ -84,7 +84,7 @@ EXAMPLES
|
|
|
84
84
|
$ sand build --verbose --dry
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
_See code: [src/commands/build.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.
|
|
87
|
+
_See code: [src/commands/build.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.6.0/src/commands/build.ts)_
|
|
88
88
|
|
|
89
89
|
## `sand create PROJECT-NAME`
|
|
90
90
|
|
|
@@ -117,7 +117,7 @@ EXAMPLE
|
|
|
117
117
|
$ sand create my-datapack
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
_See code: [src/commands/create.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.
|
|
120
|
+
_See code: [src/commands/create.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.6.0/src/commands/create.ts)_
|
|
121
121
|
|
|
122
122
|
## `sand help [COMMAND]`
|
|
123
123
|
|
|
@@ -159,7 +159,7 @@ EXAMPLES
|
|
|
159
159
|
$ sand update --cli --sandstone --skip
|
|
160
160
|
```
|
|
161
161
|
|
|
162
|
-
_See code: [src/commands/update.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.
|
|
162
|
+
_See code: [src/commands/update.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.6.0/src/commands/update.ts)_
|
|
163
163
|
|
|
164
164
|
## `sand watch PATH CONFIG-PATH`
|
|
165
165
|
|
|
@@ -211,5 +211,5 @@ EXAMPLES
|
|
|
211
211
|
$ sand watch --verbose --dry
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
-
_See code: [src/commands/watch.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.
|
|
214
|
+
_See code: [src/commands/watch.ts](https://github.com/TheMrZZ/sandstone-cli/blob/v0.6.0/src/commands/watch.ts)_
|
|
215
215
|
<!-- commandsstop -->
|
package/bin/run
CHANGED
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProjectFolders } from '
|
|
1
|
+
import { ProjectFolders } from '../utils';
|
|
2
2
|
export declare type BuildOptions = {
|
|
3
3
|
world?: string;
|
|
4
4
|
root?: boolean;
|
|
@@ -19,5 +19,7 @@ export declare type BuildOptions = {
|
|
|
19
19
|
* @param options The options to build the project with.
|
|
20
20
|
*
|
|
21
21
|
* @param projectFolder The folder of the project. It needs a sandstone.config.ts, and it or one of its parent needs a package.json.
|
|
22
|
+
*
|
|
23
|
+
* @param changedFiles The files that changed since the last build.
|
|
22
24
|
*/
|
|
23
|
-
export declare function buildProject(options: BuildOptions, folders: ProjectFolders): Promise<void>;
|
|
25
|
+
export declare function buildProject(options: BuildOptions, folders: ProjectFolders, changedFiles?: string[]): Promise<void>;
|
|
@@ -10,6 +10,9 @@ const util_1 = require("util");
|
|
|
10
10
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
11
|
const pretty_error_1 = __importDefault(require("pretty-error"));
|
|
12
12
|
const klaw_1 = __importDefault(require("klaw"));
|
|
13
|
+
const madge_1 = __importDefault(require("madge"));
|
|
14
|
+
const graph_1 = require("./graph");
|
|
15
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
13
16
|
const pe = new pretty_error_1.default();
|
|
14
17
|
// Return the hash of a string
|
|
15
18
|
function hash(stringToHash) {
|
|
@@ -30,6 +33,9 @@ async function mkDir(dirPath) {
|
|
|
30
33
|
// Directory already exists
|
|
31
34
|
}
|
|
32
35
|
}
|
|
36
|
+
const cache = {};
|
|
37
|
+
const dependenciesCache = new graph_1.DependencyGraph({});
|
|
38
|
+
const fileResources = new Map();
|
|
33
39
|
/**
|
|
34
40
|
* Recursively removes empty directories from the given directory.
|
|
35
41
|
*
|
|
@@ -57,8 +63,30 @@ async function removeEmptyDirectories(directory) {
|
|
|
57
63
|
await fs_extra_1.default.rmdir(directory);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
const
|
|
66
|
+
function getNewModules(dependenciesGraph, rawFiles, projectFolder) {
|
|
67
|
+
const rawFilesPath = rawFiles.map(({ path }) => path);
|
|
68
|
+
// Get only the new modules
|
|
69
|
+
const newModules = [...dependenciesGraph.nodes.values()].filter((node) => rawFilesPath.includes(path_1.default.join(projectFolder, node.name)));
|
|
70
|
+
// Get their dependants, as a set to avoid duplicates
|
|
71
|
+
const newModulesDependencies = new Set(newModules.flatMap((node) => [...node.getDependsOn({ recursive: true, includeSelf: true })]));
|
|
72
|
+
// Sort them by number of dependencies, and return them
|
|
73
|
+
return [...newModulesDependencies].sort((a, b) => a.getDependencies({ recursive: true }).size - b.getDependencies({ recursive: true }).size);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns a set of all values present in set1 and not present in set2.
|
|
77
|
+
*/
|
|
78
|
+
function diffSet(set1, set2) {
|
|
79
|
+
return [...set1].filter((element) => !set2.has(element));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns a map of all key/value present in map1 and not present in map2.
|
|
83
|
+
*/
|
|
84
|
+
function diffMap(map1, map2) {
|
|
85
|
+
return new Map([...map1.entries()].filter(([key, value]) => !map2.has(key)));
|
|
86
|
+
}
|
|
87
|
+
function diffResources(tree1, tree2) {
|
|
88
|
+
return tree1.diff(tree2);
|
|
89
|
+
}
|
|
62
90
|
/**
|
|
63
91
|
* Build the project, but might throw errors.
|
|
64
92
|
*
|
|
@@ -66,7 +94,7 @@ const sandstoneCacheFileName = 'cache.json';
|
|
|
66
94
|
*
|
|
67
95
|
* @param projectFolder The folder of the project. It needs a sandstone.config.ts, and it or one of its parent needs a package.json.
|
|
68
96
|
*/
|
|
69
|
-
async function _buildProject(options, { absProjectFolder, rootFolder, sandstoneConfigFolder }) {
|
|
97
|
+
async function _buildProject(options, { absProjectFolder, rootFolder, sandstoneConfigFolder }, changedFiles) {
|
|
70
98
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
71
99
|
const sandstoneLocation = path_1.default.join(rootFolder, 'node_modules/sandstone/');
|
|
72
100
|
// First, read sandstone.config.ts to get all properties
|
|
@@ -129,50 +157,113 @@ async function _buildProject(options, { absProjectFolder, rootFolder, sandstoneC
|
|
|
129
157
|
}));
|
|
130
158
|
// Finally, let's import all .ts & .js files under ./src.
|
|
131
159
|
let error = false;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
160
|
+
// Get the list of all files
|
|
161
|
+
const rawFiles = [];
|
|
162
|
+
for await (const file of (0, klaw_1.default)(absProjectFolder)) {
|
|
163
|
+
rawFiles.push(file);
|
|
164
|
+
}
|
|
165
|
+
const changedFilesPaths = changedFiles === null || changedFiles === void 0 ? void 0 : changedFiles.map(file => ({ path: file }));
|
|
166
|
+
/**
|
|
167
|
+
* 1. Update dependency graphs
|
|
168
|
+
* 2. Delete all cache & resources for files dependent from the changed files
|
|
169
|
+
* 3. Import all changed files, & their dependents
|
|
170
|
+
* 4. Save only newly created resources
|
|
171
|
+
*/
|
|
172
|
+
const graph = await (0, madge_1.default)(rawFiles.map(f => f.path).filter(f => !f.endsWith('.json')), {
|
|
173
|
+
fileExtensions: ['.ts', '.cts', '.mts', '.tsx', '.js', '.jsx', '.cjs', '.mjs', '.json'],
|
|
174
|
+
includeNpm: false,
|
|
175
|
+
baseDir: absProjectFolder,
|
|
176
|
+
detectiveOptions: {
|
|
177
|
+
es6: {
|
|
178
|
+
skipTypeImports: true,
|
|
179
|
+
},
|
|
180
|
+
ts: {
|
|
181
|
+
skipTypeImports: true,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
// This dependencies graph is only partial.
|
|
186
|
+
const dependenciesGraph = new graph_1.DependencyGraph(graph.obj());
|
|
187
|
+
// Update the global dependency graph by merging it with the new one.
|
|
188
|
+
dependenciesCache.merge(dependenciesGraph);
|
|
189
|
+
// Transform resolved dependents into a flat list of files, and sort them by their number of dependencies
|
|
190
|
+
const newModules = getNewModules(dependenciesCache, changedFilesPaths !== null && changedFilesPaths !== void 0 ? changedFilesPaths : rawFiles, absProjectFolder);
|
|
191
|
+
const { savePack } = require(sandstoneLocation);
|
|
192
|
+
const { dataPack } = require(sandstoneLocation + '/init');
|
|
193
|
+
// If files changed, we need to clean the cache & delete the related resources
|
|
194
|
+
if (changedFiles) {
|
|
195
|
+
for (const node of newModules) {
|
|
196
|
+
// For eached changed file, we need to reset the require cache
|
|
197
|
+
delete require.cache[path_1.default.join(absProjectFolder, node.name)];
|
|
198
|
+
// Then we need to delete all resources the file created
|
|
199
|
+
const oldResources = fileResources.get(node.name);
|
|
200
|
+
if (oldResources) {
|
|
201
|
+
const { resources, customResources, objectives, rootFunctions } = oldResources;
|
|
202
|
+
for (const resource of resources) {
|
|
203
|
+
dataPack.resources.deleteResource(resource.path, resource.resourceType);
|
|
204
|
+
}
|
|
205
|
+
for (const resource of customResources) {
|
|
206
|
+
dataPack.customResources.delete(resource);
|
|
207
|
+
}
|
|
208
|
+
for (const objective of objectives.keys()) {
|
|
209
|
+
dataPack.objectives.delete(objective);
|
|
210
|
+
}
|
|
211
|
+
for (const rootFunction of rootFunctions) {
|
|
212
|
+
dataPack.rootFunctions.delete(rootFunction);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
136
215
|
}
|
|
216
|
+
}
|
|
217
|
+
// Now, let's build the file & its dependents. First files to be built are the ones with less dependencies.
|
|
218
|
+
for (const node of newModules) {
|
|
219
|
+
const modulePath = path_1.default.join(absProjectFolder, node.name);
|
|
220
|
+
const currentResources = {
|
|
221
|
+
resources: dataPack.resources.clone(),
|
|
222
|
+
objectives: new Map([...dataPack.objectives.entries()]),
|
|
223
|
+
rootFunctions: new Set([...dataPack.rootFunctions]),
|
|
224
|
+
customResources: new Set([...dataPack.customResources]),
|
|
225
|
+
};
|
|
137
226
|
// We have a module, let's require it!
|
|
227
|
+
const filePath = path_1.default.resolve(modulePath);
|
|
138
228
|
try {
|
|
139
|
-
|
|
229
|
+
// Sometimes, a file might not exist because it has been deleted.
|
|
230
|
+
if (await fs_extra_1.default.pathExists(filePath)) {
|
|
231
|
+
require(filePath);
|
|
232
|
+
}
|
|
233
|
+
// Generate the mcfunctions
|
|
234
|
+
for (const mcfunction of dataPack.rootFunctions) {
|
|
235
|
+
await mcfunction.generate();
|
|
236
|
+
}
|
|
140
237
|
}
|
|
141
238
|
catch (e) {
|
|
142
|
-
logError(e);
|
|
239
|
+
logError(e, node.name);
|
|
143
240
|
error = true;
|
|
144
241
|
}
|
|
242
|
+
// Now, find the resources that were added by this file & store them.
|
|
243
|
+
// This will be used if those files are changed later.
|
|
244
|
+
const newResources = {
|
|
245
|
+
resources: diffResources(dataPack.resources, currentResources.resources),
|
|
246
|
+
customResources: diffSet(dataPack.customResources, currentResources.customResources),
|
|
247
|
+
rootFunctions: diffSet(dataPack.rootFunctions, currentResources.rootFunctions),
|
|
248
|
+
objectives: diffMap(dataPack.objectives, currentResources.objectives),
|
|
249
|
+
};
|
|
250
|
+
fileResources.set(node.name, newResources);
|
|
145
251
|
}
|
|
146
252
|
if (error) {
|
|
147
253
|
return;
|
|
148
254
|
}
|
|
149
255
|
/// SAVING RESULTS ///
|
|
150
|
-
|
|
151
|
-
//
|
|
152
|
-
const sandstoneMiscFolder = path_1.default.join(rootFolder, sandstoneMiscFolderName);
|
|
153
|
-
const sandstoneCacheFile = path_1.default.join(sandstoneMiscFolder, sandstoneCacheFileName);
|
|
154
|
-
mkDir(sandstoneMiscFolder);
|
|
155
|
-
// Try loading the cache
|
|
156
|
-
let cache = {};
|
|
256
|
+
// Setup the cache if it doesn't exist.
|
|
257
|
+
// This cache is here to avoid writing files on disk when they did not change.
|
|
157
258
|
const newCache = {
|
|
158
259
|
files: {}
|
|
159
260
|
};
|
|
160
|
-
try {
|
|
161
|
-
// Load the cache
|
|
162
|
-
cache = JSON.parse((await fs_extra_1.default.readFile(sandstoneCacheFile)).toString());
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
// Either the file does not exists, or the cache isn't a proper JSON.
|
|
166
|
-
// In that case, reset it.
|
|
167
|
-
await fs_extra_1.default.writeFile(sandstoneCacheFile, JSON.stringify(cache));
|
|
168
|
-
}
|
|
169
261
|
if (cache[absProjectFolder] === undefined) {
|
|
170
262
|
cache[absProjectFolder] = {
|
|
171
263
|
files: {},
|
|
172
264
|
};
|
|
173
265
|
}
|
|
174
266
|
// Save the pack
|
|
175
|
-
const { savePack } = require(sandstoneLocation);
|
|
176
267
|
// Run the beforeSave script
|
|
177
268
|
await ((_d = scripts === null || scripts === void 0 ? void 0 : scripts.beforeSave) === null || _d === void 0 ? void 0 : _d.call(scripts, {
|
|
178
269
|
dataPackName,
|
|
@@ -213,7 +304,7 @@ async function _buildProject(options, { absProjectFolder, rootFolder, sandstoneC
|
|
|
213
304
|
const oldFilesNames = new Set(Object.keys(cache[absProjectFolder].files));
|
|
214
305
|
Object.keys(newCache.files).forEach(name => oldFilesNames.delete(name));
|
|
215
306
|
const previousResultFolder = (_h = cache === null || cache === void 0 ? void 0 : cache[absProjectFolder]) === null || _h === void 0 ? void 0 : _h.resultFolder;
|
|
216
|
-
await Promise.allSettled([...oldFilesNames.values()].map(name => util_1.promisify(fs_extra_1.default.rm)(path_1.default.join(previousResultFolder !== null && previousResultFolder !== void 0 ? previousResultFolder : '', name))));
|
|
307
|
+
await Promise.allSettled([...oldFilesNames.values()].map(name => (0, util_1.promisify)(fs_extra_1.default.rm)(path_1.default.join(previousResultFolder !== null && previousResultFolder !== void 0 ? previousResultFolder : '', name))));
|
|
217
308
|
// Delete all empty folders of previous directory
|
|
218
309
|
if (previousResultFolder !== undefined) {
|
|
219
310
|
try {
|
|
@@ -225,7 +316,6 @@ async function _buildProject(options, { absProjectFolder, rootFolder, sandstoneC
|
|
|
225
316
|
}
|
|
226
317
|
// Override old cache
|
|
227
318
|
cache[absProjectFolder] = newCache;
|
|
228
|
-
await fs_extra_1.default.writeFile(sandstoneCacheFile, JSON.stringify(cache, null, 2));
|
|
229
319
|
// Run the afterAll script
|
|
230
320
|
await ((_j = scripts === null || scripts === void 0 ? void 0 : scripts.afterAll) === null || _j === void 0 ? void 0 : _j.call(scripts, {
|
|
231
321
|
dataPackName,
|
|
@@ -238,18 +328,23 @@ async function _buildProject(options, { absProjectFolder, rootFolder, sandstoneC
|
|
|
238
328
|
* @param options The options to build the project with.
|
|
239
329
|
*
|
|
240
330
|
* @param projectFolder The folder of the project. It needs a sandstone.config.ts, and it or one of its parent needs a package.json.
|
|
331
|
+
*
|
|
332
|
+
* @param changedFiles The files that changed since the last build.
|
|
241
333
|
*/
|
|
242
|
-
async function buildProject(options, folders) {
|
|
334
|
+
async function buildProject(options, folders, changedFiles) {
|
|
243
335
|
try {
|
|
244
|
-
await _buildProject(options, folders);
|
|
336
|
+
await _buildProject(options, folders, changedFiles);
|
|
245
337
|
}
|
|
246
338
|
catch (err) {
|
|
247
339
|
logError(err);
|
|
248
340
|
}
|
|
249
341
|
}
|
|
250
342
|
exports.buildProject = buildProject;
|
|
251
|
-
function logError(err) {
|
|
343
|
+
function logError(err, file) {
|
|
252
344
|
if (err) {
|
|
345
|
+
if (file) {
|
|
346
|
+
console.error(' ' + chalk_1.default.bgRed.white('BuildError') + chalk_1.default.gray(':'), `While loading "${file}", the following error happened:\n`);
|
|
347
|
+
}
|
|
253
348
|
console.error(pe.render(err));
|
|
254
349
|
}
|
|
255
350
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MadgeModuleDependencyGraph } from "madge";
|
|
2
|
+
export declare function findAllDependencies(graph: Map<string, Set<string>>, name: string, oldGraph: Map<string, Set<string>>): Map<string, Set<string>>;
|
|
3
|
+
export declare class DependencyGraph {
|
|
4
|
+
nodes: Map<string, Node>;
|
|
5
|
+
constructor(madgeGraph: MadgeModuleDependencyGraph);
|
|
6
|
+
/**
|
|
7
|
+
* Get a node from the graph.
|
|
8
|
+
*
|
|
9
|
+
* @param name The name of the node to get.
|
|
10
|
+
* @returns The node.
|
|
11
|
+
* @throws If the node doesn't exist.
|
|
12
|
+
*/
|
|
13
|
+
getNode(name: string): Node;
|
|
14
|
+
/**
|
|
15
|
+
* Merge two dependency graphs.
|
|
16
|
+
* Changes the current graph.
|
|
17
|
+
*
|
|
18
|
+
* @param graph The graph to merge with.
|
|
19
|
+
*
|
|
20
|
+
* @returns The current graph, modified.
|
|
21
|
+
*/
|
|
22
|
+
merge(graph: DependencyGraph): DependencyGraph;
|
|
23
|
+
/**
|
|
24
|
+
* Delete a node from the graph.
|
|
25
|
+
*
|
|
26
|
+
* @param name The name of the node to delete.
|
|
27
|
+
*/
|
|
28
|
+
delete(name: string): void;
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
31
|
+
declare class Node {
|
|
32
|
+
name: string;
|
|
33
|
+
dependencies: Set<Node>;
|
|
34
|
+
dependsOn: Set<Node>;
|
|
35
|
+
protected traversed: boolean;
|
|
36
|
+
constructor(name: string);
|
|
37
|
+
addDependencies(...nodes: Node[]): void;
|
|
38
|
+
addDependsOn(...nodes: Node[]): void;
|
|
39
|
+
getDependencies(opts: {
|
|
40
|
+
recursive?: boolean;
|
|
41
|
+
includeSelf?: boolean;
|
|
42
|
+
}): Set<Node>;
|
|
43
|
+
getDependsOn(opts: {
|
|
44
|
+
recursive?: boolean;
|
|
45
|
+
includeSelf?: boolean;
|
|
46
|
+
}): Set<Node>;
|
|
47
|
+
toString(): string;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DependencyGraph = exports.findAllDependencies = void 0;
|
|
4
|
+
function findAllDependencies(graph, name, oldGraph) {
|
|
5
|
+
const result = new Map(graph.entries());
|
|
6
|
+
const resolveOneDependency = (dep) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (result.get(dep)) {
|
|
9
|
+
return result.get(dep);
|
|
10
|
+
}
|
|
11
|
+
if (!graph.get(dep)) {
|
|
12
|
+
return (_a = oldGraph.get(dep)) !== null && _a !== void 0 ? _a : new Set();
|
|
13
|
+
}
|
|
14
|
+
const dependencies = new Set([dep]);
|
|
15
|
+
for (const dependency of graph.get(dep)) {
|
|
16
|
+
for (const res of resolveOneDependency(dependency)) {
|
|
17
|
+
dependencies.add(res);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return dependencies;
|
|
21
|
+
};
|
|
22
|
+
resolveOneDependency(name);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
exports.findAllDependencies = findAllDependencies;
|
|
26
|
+
function madgeToMap(graph) {
|
|
27
|
+
return new Map(Object.entries(graph).map(([key, value]) => [key, new Set(value)]));
|
|
28
|
+
}
|
|
29
|
+
class DependencyGraph {
|
|
30
|
+
constructor(madgeGraph) {
|
|
31
|
+
const graph = madgeToMap(madgeGraph);
|
|
32
|
+
this.nodes = new Map();
|
|
33
|
+
// Creates nodes
|
|
34
|
+
for (const name of graph.keys()) {
|
|
35
|
+
this.nodes.set(name, new Node(name));
|
|
36
|
+
}
|
|
37
|
+
// Creates dependsOn & dependencies
|
|
38
|
+
for (const [name, dependencies] of graph.entries()) {
|
|
39
|
+
const node = this.getNode(name);
|
|
40
|
+
node.addDependencies(...[...dependencies].map(dep => this.getNode(dep)));
|
|
41
|
+
for (const dependency of dependencies) {
|
|
42
|
+
this.nodes.get(dependency).dependsOn.add(node);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get a node from the graph.
|
|
48
|
+
*
|
|
49
|
+
* @param name The name of the node to get.
|
|
50
|
+
* @returns The node.
|
|
51
|
+
* @throws If the node doesn't exist.
|
|
52
|
+
*/
|
|
53
|
+
getNode(name) {
|
|
54
|
+
const node = this.nodes.get(name);
|
|
55
|
+
if (!node) {
|
|
56
|
+
throw new Error(`Node ${name} not found`);
|
|
57
|
+
}
|
|
58
|
+
return node;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Merge two dependency graphs.
|
|
62
|
+
* Changes the current graph.
|
|
63
|
+
*
|
|
64
|
+
* @param graph The graph to merge with.
|
|
65
|
+
*
|
|
66
|
+
* @returns The current graph, modified.
|
|
67
|
+
*/
|
|
68
|
+
merge(graph) {
|
|
69
|
+
// Merge nodes
|
|
70
|
+
for (const [name, node] of this.nodes.entries()) {
|
|
71
|
+
try {
|
|
72
|
+
const newNode = graph.getNode(name);
|
|
73
|
+
// Set the current node's dependencies to the new node's dependencies
|
|
74
|
+
node.dependencies.clear();
|
|
75
|
+
for (const dependency of newNode.dependencies) {
|
|
76
|
+
node.dependencies.add(this.getNode(dependency.name));
|
|
77
|
+
}
|
|
78
|
+
// Set the current node's dependsOn to the new node's dependsOn
|
|
79
|
+
node.dependsOn.clear();
|
|
80
|
+
for (const dependsOn of newNode.dependsOn) {
|
|
81
|
+
node.dependsOn.add(this.getNode(dependsOn.name));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
// Nothing to do: the new graph does not have this node. It's fine, because the new graph is a subset of entire graph.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Add nodes that don't exist yet
|
|
89
|
+
const newNodes = [];
|
|
90
|
+
for (const [name, node] of graph.nodes.entries()) {
|
|
91
|
+
if (!this.nodes.has(name)) {
|
|
92
|
+
this.nodes.set(name, node);
|
|
93
|
+
newNodes.push(node);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Update dependencies/dependsOn to reference old nodes
|
|
97
|
+
for (const node of newNodes) {
|
|
98
|
+
const dependencies = [...node.dependencies];
|
|
99
|
+
node.dependencies.clear();
|
|
100
|
+
for (const dependency of dependencies) {
|
|
101
|
+
node.dependencies.add(this.getNode(dependency.name));
|
|
102
|
+
}
|
|
103
|
+
const dependsOn = [...node.dependsOn];
|
|
104
|
+
node.dependsOn.clear();
|
|
105
|
+
for (const dependsOnNode of dependsOn) {
|
|
106
|
+
node.dependsOn.add(this.getNode(dependsOnNode.name));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return graph;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Delete a node from the graph.
|
|
113
|
+
*
|
|
114
|
+
* @param name The name of the node to delete.
|
|
115
|
+
*/
|
|
116
|
+
delete(name) {
|
|
117
|
+
const node = this.getNode(name);
|
|
118
|
+
for (const dependency of node.dependencies) {
|
|
119
|
+
dependency.dependsOn.delete(node);
|
|
120
|
+
}
|
|
121
|
+
for (const dependsOn of node.dependsOn) {
|
|
122
|
+
dependsOn.dependencies.delete(node);
|
|
123
|
+
}
|
|
124
|
+
this.nodes.delete(name);
|
|
125
|
+
}
|
|
126
|
+
toString() {
|
|
127
|
+
let result = '';
|
|
128
|
+
for (const [name, node] of this.nodes.entries()) {
|
|
129
|
+
result += name + '\n';
|
|
130
|
+
result += `Depends on : ${[...node.getDependencies({ recursive: true })].map(n => `"${n.toString()}`)}\n`;
|
|
131
|
+
result += `Dependency of: ${[...node.getDependsOn({ recursive: true })].map(n => `"${n.toString()}"`)}\n\n`;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.DependencyGraph = DependencyGraph;
|
|
137
|
+
class Node {
|
|
138
|
+
constructor(name) {
|
|
139
|
+
this.name = name;
|
|
140
|
+
this.dependencies = new Set();
|
|
141
|
+
this.dependsOn = new Set();
|
|
142
|
+
this.traversed = false;
|
|
143
|
+
}
|
|
144
|
+
addDependencies(...nodes) {
|
|
145
|
+
for (const node of nodes) {
|
|
146
|
+
this.dependencies.add(node);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
addDependsOn(...nodes) {
|
|
150
|
+
for (const node of nodes) {
|
|
151
|
+
this.dependsOn.add(node);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
getDependencies(opts) {
|
|
155
|
+
const result = new Set();
|
|
156
|
+
if (opts.includeSelf) {
|
|
157
|
+
result.add(this);
|
|
158
|
+
}
|
|
159
|
+
if (this.traversed) {
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
this.traversed = true;
|
|
163
|
+
// Recursively get all dependencies if recursive is true
|
|
164
|
+
if (opts.recursive) {
|
|
165
|
+
for (const dependency of this.dependencies) {
|
|
166
|
+
for (const dep of dependency.getDependencies({ recursive: true, includeSelf: true })) {
|
|
167
|
+
result.add(dep);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.traversed = false;
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
getDependsOn(opts) {
|
|
175
|
+
const result = new Set();
|
|
176
|
+
if (opts.includeSelf) {
|
|
177
|
+
result.add(this);
|
|
178
|
+
}
|
|
179
|
+
if (this.traversed) {
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
this.traversed = true;
|
|
183
|
+
// Recursively get all dependencies if recursive is true
|
|
184
|
+
if (opts.recursive) {
|
|
185
|
+
for (const parent of this.dependsOn) {
|
|
186
|
+
for (const dep of parent.getDependsOn({ recursive: true, includeSelf: true })) {
|
|
187
|
+
result.add(dep);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
this.traversed = false;
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
toString() {
|
|
195
|
+
return this.name;
|
|
196
|
+
}
|
|
197
|
+
}
|
package/lib/commands/build.js
CHANGED
|
@@ -4,21 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const command_1 = require("@oclif/command");
|
|
7
|
-
const buildProject_1 = require("../buildProject");
|
|
7
|
+
const buildProject_1 = require("../build/buildProject");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const watch_1 = __importDefault(require("./watch"));
|
|
11
11
|
class Build extends command_1.Command {
|
|
12
12
|
async run() {
|
|
13
13
|
const { args, flags } = this.parse(Build);
|
|
14
|
-
const folders = utils_1.getProjectFolders(args.path);
|
|
14
|
+
const folders = (0, utils_1.getProjectFolders)(args.path);
|
|
15
15
|
// Register ts-node
|
|
16
16
|
const tsConfigPath = path_1.default.join(folders.rootFolder, 'tsconfig.json');
|
|
17
17
|
require('ts-node').register({
|
|
18
18
|
transpileOnly: !flags.strictErrors,
|
|
19
19
|
project: tsConfigPath,
|
|
20
20
|
});
|
|
21
|
-
buildProject_1.buildProject(flags, folders);
|
|
21
|
+
(0, buildProject_1.buildProject)(flags, folders);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.default = Build;
|
package/lib/commands/create.js
CHANGED
|
@@ -28,7 +28,7 @@ class Create extends command_1.Command {
|
|
|
28
28
|
const { args, flags } = this.parse(Create);
|
|
29
29
|
const projectPath = path_1.default.resolve(args['project-name']);
|
|
30
30
|
const projectName = path_1.default.basename(projectPath);
|
|
31
|
-
const datapackName = await utils_1.getFlagOrPrompt(flags, 'datapack-name', {
|
|
31
|
+
const datapackName = await (0, utils_1.getFlagOrPrompt)(flags, 'datapack-name', {
|
|
32
32
|
message: 'Name of your data pack (can be changed later) >',
|
|
33
33
|
type: 'input',
|
|
34
34
|
default: projectName,
|
|
@@ -85,12 +85,12 @@ class Create extends command_1.Command {
|
|
|
85
85
|
saveOptions.path = path;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
const namespace = await utils_1.getFlagOrPrompt(flags, 'namespace', {
|
|
88
|
+
const namespace = await (0, utils_1.getFlagOrPrompt)(flags, 'namespace', {
|
|
89
89
|
message: 'Default namespace (can be changed later) >',
|
|
90
90
|
default: 'default',
|
|
91
91
|
});
|
|
92
92
|
let useYarn = flags.yarn;
|
|
93
|
-
if (!flags.yarn && !flags.npm && utils_1.hasYarn()) {
|
|
93
|
+
if (!flags.yarn && !flags.npm && (0, utils_1.hasYarn)()) {
|
|
94
94
|
useYarn = (await inquirer_1.default.prompt({
|
|
95
95
|
name: 'useYarn',
|
|
96
96
|
message: 'What package manager do you want to use? >',
|
|
@@ -100,20 +100,20 @@ class Create extends command_1.Command {
|
|
|
100
100
|
}
|
|
101
101
|
fs_1.default.mkdirSync(projectPath);
|
|
102
102
|
// Create project & install dependencies
|
|
103
|
-
this.log(chalk_1.default `Installing {rgb(229,193,0) sandstone}, {rgb(229,193,0) sandstone-cli} and {cyan typescript} using {cyan ${useYarn ? 'yarn' : 'npm'}}.`);
|
|
103
|
+
this.log((0, chalk_1.default) `Installing {rgb(229,193,0) sandstone}, {rgb(229,193,0) sandstone-cli} and {cyan typescript} using {cyan ${useYarn ? 'yarn' : 'npm'}}.`);
|
|
104
104
|
if (useYarn) {
|
|
105
105
|
/** Init the package, skipping the interactive prompt */
|
|
106
|
-
child_process_1.execSync('yarn init --yes', { cwd: projectPath });
|
|
106
|
+
(0, child_process_1.execSync)('yarn init --yes', { cwd: projectPath });
|
|
107
107
|
/** Install dependencies */
|
|
108
|
-
child_process_1.execSync('yarn add sandstone', { cwd: projectPath });
|
|
109
|
-
child_process_1.execSync('yarn add --dev typescript @types/node sandstone-cli', { cwd: projectPath });
|
|
108
|
+
(0, child_process_1.execSync)('yarn add sandstone', { cwd: projectPath });
|
|
109
|
+
(0, child_process_1.execSync)('yarn add --dev typescript @types/node sandstone-cli', { cwd: projectPath });
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
112
|
/** Init the package, skipping the interactive prompt */
|
|
113
|
-
child_process_1.execSync('npm init --yes', { cwd: projectPath });
|
|
113
|
+
(0, child_process_1.execSync)('npm init --yes', { cwd: projectPath });
|
|
114
114
|
/** Install dependencies */
|
|
115
|
-
child_process_1.execSync('npm install sandstone', { cwd: projectPath });
|
|
116
|
-
child_process_1.execSync('npm install --save-dev typescript @types/node sandstone-cli', { cwd: projectPath });
|
|
115
|
+
(0, child_process_1.execSync)('npm install sandstone', { cwd: projectPath });
|
|
116
|
+
(0, child_process_1.execSync)('npm install --save-dev typescript @types/node sandstone-cli', { cwd: projectPath });
|
|
117
117
|
}
|
|
118
118
|
// Merge with the package.json template
|
|
119
119
|
const generatedPackage = JSON.parse(fs_1.default.readFileSync(path_1.default.join(projectPath, 'package.json')).toString());
|
|
@@ -132,7 +132,7 @@ export default {
|
|
|
132
132
|
description: ${toJson(['A ', { text: 'Sandstone', color: 'gold' }, ' data pack.'])},
|
|
133
133
|
formatVersion: ${7},
|
|
134
134
|
namespace: ${toJson(namespace)},
|
|
135
|
-
packUid: ${toJson(nanoid_1.nanoid(8))},
|
|
135
|
+
packUid: ${toJson((0, nanoid_1.nanoid)(8))},
|
|
136
136
|
saveOptions: ${toJson(Object.fromEntries(Object.entries(saveOptions).filter(([_, value]) => value !== undefined)))},
|
|
137
137
|
onConflict: {
|
|
138
138
|
default: 'warn',
|
|
@@ -140,12 +140,12 @@ export default {
|
|
|
140
140
|
} as SandstoneConfig
|
|
141
141
|
`);
|
|
142
142
|
const prefix = useYarn ? 'yarn' : 'npm run';
|
|
143
|
-
this.log(chalk_1.default `{green Success!} Created "${projectName}" at "${projectPath}"`);
|
|
143
|
+
this.log((0, chalk_1.default) `{green Success!} Created "${projectName}" at "${projectPath}"`);
|
|
144
144
|
this.log('Inside that directory, you can run several commands:\n');
|
|
145
|
-
this.log(chalk_1.default ` {cyan ${prefix} build}:\n Builds the data pack. {cyan ⛏}\n`);
|
|
146
|
-
this.log(chalk_1.default ` {cyan ${prefix} watch}:\n Builds the data pack, and rebuild on each file change. {cyan ⛏}\n`);
|
|
145
|
+
this.log((0, chalk_1.default) ` {cyan ${prefix} build}:\n Builds the data pack. {cyan ⛏}\n`);
|
|
146
|
+
this.log((0, chalk_1.default) ` {cyan ${prefix} watch}:\n Builds the data pack, and rebuild on each file change. {cyan ⛏}\n`);
|
|
147
147
|
this.log('We suggest that you begin by typing:\n');
|
|
148
|
-
this.log(chalk_1.default ` {cyan cd} ${projectName}\n {cyan ${prefix} watch}`);
|
|
148
|
+
this.log((0, chalk_1.default) ` {cyan cd} ${projectName}\n {cyan ${prefix} watch}`);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
exports.default = Create;
|
package/lib/commands/update.js
CHANGED
|
@@ -17,14 +17,14 @@ class Watch extends command_1.Command {
|
|
|
17
17
|
const { args, flags } = this.parse(Watch);
|
|
18
18
|
// First, check if there are any update
|
|
19
19
|
console.log('Checking for updates...');
|
|
20
|
-
const rootFolder = utils_1.getFileFolder('package.json', '.');
|
|
20
|
+
const rootFolder = (0, utils_1.getFileFolder)('package.json', '.');
|
|
21
21
|
if (!rootFolder) {
|
|
22
|
-
console.error(chalk_1.default `{red Failed to find {bold package.json} in ${path_1.default.resolve()}, or in any parent folder.}`);
|
|
22
|
+
console.error((0, chalk_1.default) `{red Failed to find {bold package.json} in ${path_1.default.resolve()}, or in any parent folder.}`);
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
let npmListReturn;
|
|
26
26
|
try {
|
|
27
|
-
npmListReturn = child_process_1.execSync('npm list --depth 0 --json --silent', {
|
|
27
|
+
npmListReturn = (0, child_process_1.execSync)('npm list --depth 0 --json --silent', {
|
|
28
28
|
cwd: rootFolder,
|
|
29
29
|
}).toString();
|
|
30
30
|
}
|
|
@@ -34,27 +34,27 @@ class Watch extends command_1.Command {
|
|
|
34
34
|
const { dependencies } = JSON.parse(npmListReturn);
|
|
35
35
|
const sandstoneOldVersion = (_b = (_a = dependencies === null || dependencies === void 0 ? void 0 : dependencies.sandstone) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : (_d = (_c = dependencies === null || dependencies === void 0 ? void 0 : dependencies.sandstone) === null || _c === void 0 ? void 0 : _c.required) === null || _d === void 0 ? void 0 : _d.version;
|
|
36
36
|
const cliOldVersion = (_f = (_e = dependencies === null || dependencies === void 0 ? void 0 : dependencies['sandstone-cli']) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : (_h = (_g = dependencies === null || dependencies === void 0 ? void 0 : dependencies['sandstone-cli']) === null || _g === void 0 ? void 0 : _g.required) === null || _h === void 0 ? void 0 : _h.version;
|
|
37
|
-
const sandstoneNewVersion = child_process_1.execSync('npm view sandstone version').toString().trim();
|
|
38
|
-
const cliNewVersion = child_process_1.execSync('npm view sandstone-cli version').toString().trim();
|
|
37
|
+
const sandstoneNewVersion = (0, child_process_1.execSync)('npm view sandstone version').toString().trim();
|
|
38
|
+
const cliNewVersion = (0, child_process_1.execSync)('npm view sandstone-cli version').toString().trim();
|
|
39
39
|
const sandstoneNeedsUpdate = sandstoneOldVersion && semver_1.default.lt(sandstoneOldVersion, sandstoneNewVersion);
|
|
40
40
|
const cliNeedsUpdate = cliOldVersion && semver_1.default.lt(cliOldVersion, cliNewVersion);
|
|
41
41
|
if (sandstoneNeedsUpdate) {
|
|
42
|
-
console.log(chalk_1.default `{rgb(229,193,0) Sandstone} has a new version available: {greenBright ${sandstoneNewVersion}} {gray (current: ${sandstoneOldVersion})}`);
|
|
42
|
+
console.log((0, chalk_1.default) `{rgb(229,193,0) Sandstone} has a new version available: {greenBright ${sandstoneNewVersion}} {gray (current: ${sandstoneOldVersion})}`);
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
console.log(chalk_1.default `{rgb(229,193,0) Sandstone} is already up to date!`);
|
|
45
|
+
console.log((0, chalk_1.default) `{rgb(229,193,0) Sandstone} is already up to date!`);
|
|
46
46
|
}
|
|
47
47
|
if (cliNeedsUpdate) {
|
|
48
|
-
console.log(chalk_1.default `{rgb(229,193,0) Sandstone-CLI} has a new version available: {greenBright ${cliNewVersion}} {gray (current: ${cliOldVersion})}`);
|
|
48
|
+
console.log((0, chalk_1.default) `{rgb(229,193,0) Sandstone-CLI} has a new version available: {greenBright ${cliNewVersion}} {gray (current: ${cliOldVersion})}`);
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
console.log(chalk_1.default `{rgb(229,193,0) Sandstone-CLI} is already up to date!`);
|
|
51
|
+
console.log((0, chalk_1.default) `{rgb(229,193,0) Sandstone-CLI} is already up to date!`);
|
|
52
52
|
}
|
|
53
53
|
let updateSandstone = flags.sandstone && sandstoneNeedsUpdate;
|
|
54
54
|
if (sandstoneNeedsUpdate && !updateSandstone && !flags.skip) {
|
|
55
55
|
updateSandstone = (await inquirer_1.default.prompt({
|
|
56
56
|
name: 'updateSandstone',
|
|
57
|
-
message: chalk_1.default `Update Sandstone to {greenBright ${sandstoneNewVersion}}? >`,
|
|
57
|
+
message: (0, chalk_1.default) `Update Sandstone to {greenBright ${sandstoneNewVersion}}? >`,
|
|
58
58
|
type: 'confirm',
|
|
59
59
|
})).updateSandstone;
|
|
60
60
|
}
|
|
@@ -62,15 +62,15 @@ class Watch extends command_1.Command {
|
|
|
62
62
|
if (cliNeedsUpdate && !updateCli && !flags.skip) {
|
|
63
63
|
updateCli = (await inquirer_1.default.prompt({
|
|
64
64
|
name: 'updateCli',
|
|
65
|
-
message: chalk_1.default `Update CLI to {greenBright ${cliNewVersion}}? >`,
|
|
65
|
+
message: (0, chalk_1.default) `Update CLI to {greenBright ${cliNewVersion}}? >`,
|
|
66
66
|
type: 'confirm',
|
|
67
67
|
})).updateCli;
|
|
68
68
|
}
|
|
69
69
|
if (!updateSandstone && !updateCli) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
let useYarn = flags.yarn || (fs_extra_1.default.existsSync('yarn.lock') && utils_1.hasYarn() && !flags.npm);
|
|
73
|
-
if (!useYarn && !flags.npm && utils_1.hasYarn() && !fs_extra_1.default.existsSync('package-lock.json')) {
|
|
72
|
+
let useYarn = flags.yarn || (fs_extra_1.default.existsSync('yarn.lock') && (0, utils_1.hasYarn)() && !flags.npm);
|
|
73
|
+
if (!useYarn && !flags.npm && (0, utils_1.hasYarn)() && !fs_extra_1.default.existsSync('package-lock.json')) {
|
|
74
74
|
useYarn = (await inquirer_1.default.prompt({
|
|
75
75
|
name: 'useYarn',
|
|
76
76
|
message: 'What package manager do you want to use? >',
|
|
@@ -84,23 +84,23 @@ class Watch extends command_1.Command {
|
|
|
84
84
|
].filter(msg => msg !== null)
|
|
85
85
|
.map(msg => chalk_1.default.rgb(299, 193, 0)(msg))
|
|
86
86
|
.join(', ');
|
|
87
|
-
this.log(chalk_1.default `Installing ${installationMessage} using {cyan ${useYarn ? 'yarn' : 'npm'}}.`);
|
|
87
|
+
this.log((0, chalk_1.default) `Installing ${installationMessage} using {cyan ${useYarn ? 'yarn' : 'npm'}}.`);
|
|
88
88
|
if (updateCli) {
|
|
89
89
|
if (useYarn) {
|
|
90
|
-
child_process_1.execSync('yarn add --dev sandstone-cli@latest');
|
|
90
|
+
(0, child_process_1.execSync)('yarn add --dev sandstone-cli@latest');
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
|
-
child_process_1.execSync('npm install --save-dev sandstone-cli@latest');
|
|
93
|
+
(0, child_process_1.execSync)('npm install --save-dev sandstone-cli@latest');
|
|
94
94
|
}
|
|
95
95
|
const { onSandstoneUpdate } = require('../onUpdate');
|
|
96
96
|
onSandstoneUpdate(sandstoneOldVersion, sandstoneNewVersion);
|
|
97
97
|
}
|
|
98
98
|
if (updateSandstone) {
|
|
99
99
|
if (useYarn) {
|
|
100
|
-
child_process_1.execSync('yarn add sandstone@latest');
|
|
100
|
+
(0, child_process_1.execSync)('yarn add sandstone@latest');
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
|
-
child_process_1.execSync('npm install sandstone@latest');
|
|
103
|
+
(0, child_process_1.execSync)('npm install sandstone@latest');
|
|
104
104
|
}
|
|
105
105
|
const { onCliUpdate } = require('../onUpdate');
|
|
106
106
|
onCliUpdate(cliOldVersion, cliNewVersion);
|
package/lib/commands/watch.js
CHANGED
|
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const command_1 = require("@oclif/command");
|
|
7
7
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
8
|
-
const
|
|
9
|
-
const buildProject_1 = require("../buildProject");
|
|
8
|
+
const buildProject_1 = require("../build/buildProject");
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const utils_1 = require("../utils");
|
|
12
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -28,8 +27,8 @@ class Watch extends command_1.Command {
|
|
|
28
27
|
console.log(chalk_1.default.rgb(255, 204, 0) `Failed to connect to localhost:${flags.autoReload}. The data pack won't be auto reloaded.`);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
const folders = utils_1.getProjectFolders(args.path);
|
|
32
|
-
async function
|
|
30
|
+
const folders = (0, utils_1.getProjectFolders)(args.path);
|
|
31
|
+
async function onFilesChange(paths) {
|
|
33
32
|
if (alreadyBuilding) {
|
|
34
33
|
// If the pack is already being built & another change was made,
|
|
35
34
|
// notify that a rebuild is needed & stop there
|
|
@@ -37,14 +36,12 @@ class Watch extends command_1.Command {
|
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
alreadyBuilding = true;
|
|
40
|
-
|
|
41
|
-
Object.keys(require.cache).forEach(key => delete require.cache[key]);
|
|
42
|
-
await buildProject_1.buildProject(flags, folders);
|
|
39
|
+
await (0, buildProject_1.buildProject)(flags, folders, paths);
|
|
43
40
|
client === null || client === void 0 ? void 0 : client.write('chat', { message: '/reload' });
|
|
44
41
|
alreadyBuilding = false;
|
|
45
42
|
if (needRebuild) {
|
|
46
43
|
needRebuild = false;
|
|
47
|
-
await
|
|
44
|
+
await onFilesChange(paths);
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
// Register ts-node
|
|
@@ -53,12 +50,25 @@ class Watch extends command_1.Command {
|
|
|
53
50
|
transpileOnly: !flags.strictErrors,
|
|
54
51
|
project: tsConfigPath,
|
|
55
52
|
});
|
|
53
|
+
let timeout = null;
|
|
54
|
+
let files = [];
|
|
56
55
|
chokidar_1.default.watch([
|
|
57
56
|
path_1.default.join(folders.absProjectFolder, '/**/*'),
|
|
58
57
|
path_1.default.join(folders.sandstoneConfigFolder, 'sandstone.config.ts'),
|
|
59
58
|
path_1.default.join(folders.rootFolder, 'package.json'),
|
|
60
59
|
path_1.default.join(folders.rootFolder, 'tsconfig.json'),
|
|
61
|
-
]).on('all',
|
|
60
|
+
]).on('all', (event, path) => {
|
|
61
|
+
if (event === 'addDir') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
files.push(path);
|
|
65
|
+
if (timeout)
|
|
66
|
+
clearTimeout(timeout);
|
|
67
|
+
timeout = setTimeout(() => {
|
|
68
|
+
onFilesChange(files.length === 0 ? undefined : files);
|
|
69
|
+
files = [];
|
|
70
|
+
}, 200);
|
|
71
|
+
});
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
exports.default = Watch;
|
package/lib/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ async function getFlagOrPrompt(flags, name, inquirerProps) {
|
|
|
20
20
|
exports.getFlagOrPrompt = getFlagOrPrompt;
|
|
21
21
|
function hasYarn() {
|
|
22
22
|
try {
|
|
23
|
-
child_process_1.execSync('yarn --version');
|
|
23
|
+
(0, child_process_1.execSync)('yarn --version');
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
catch (error) {
|
|
@@ -107,12 +107,12 @@ function getProjectFolders(projectFolder) {
|
|
|
107
107
|
// Resolve the location of package.json, in order to get the node_modules folder.
|
|
108
108
|
const rootFolder = getFileFolder('package.json', projectFolder);
|
|
109
109
|
if (!rootFolder) {
|
|
110
|
-
throw new Error(chalk_1.default `{red Failed to find {bold package.json} in the "${absProjectFolder}" folder, or in any parent folder.}`);
|
|
110
|
+
throw new Error((0, chalk_1.default) `{red Failed to find {bold package.json} in the "${absProjectFolder}" folder, or in any parent folder.}`);
|
|
111
111
|
}
|
|
112
112
|
// Resolve the location of sandstone.config.ts
|
|
113
113
|
const sandstoneConfigFolder = getFileFolder('sandstone.config.ts', projectFolder);
|
|
114
114
|
if (!sandstoneConfigFolder) {
|
|
115
|
-
throw new Error(chalk_1.default `{red Failed to find {bold sandstone.config.ts} in the "${absProjectFolder}" folder, or in any parent folder.}`);
|
|
115
|
+
throw new Error((0, chalk_1.default) `{red Failed to find {bold sandstone.config.ts} in the "${absProjectFolder}" folder, or in any parent folder.}`);
|
|
116
116
|
}
|
|
117
117
|
return {
|
|
118
118
|
absProjectFolder, rootFolder, sandstoneConfigFolder
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.6.0","commands":{"build":{"id":"build","description":"Build the datapack. ⛏","pluginName":"sandstone-cli","pluginType":"core","aliases":[],"examples":["$ sand build","$ sand build --verbose","$ sand build --verbose --dry"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"dry":{"name":"dry","type":"boolean","char":"d","description":"Do not save the datapack. Mostly useful with `verbose`.","allowNo":false},"verbose":{"name":"verbose","type":"boolean","char":"v","description":"Log all resulting resources: functions, advancements...","allowNo":false},"namespace":{"name":"namespace","type":"option","description":"The default namespace. Override the value specified in the configuration file."},"world":{"name":"world","type":"option","description":"The world to save the data pack in. Override the value specified in the configuration file."},"root":{"name":"root","type":"boolean","description":"Save the data pack in the `.minecraft/datapacks` folder. Override the value specified in the configuration file.","allowNo":false},"path":{"name":"path","type":"option","description":"The path to save the data pack at. Override the value specified in the configuration file."},"minecraftPath":{"name":"minecraftPath","type":"option","description":"Path of the .minecraft folder. Override the value specified in the configuration file."},"name":{"name":"name","type":"option","description":"Name of the data pack. Override the value specified in the configuration file."},"description":{"name":"description","type":"option","description":"Description of the data pack. Override the value specified in the configuration file."},"formatVersion":{"name":"formatVersion","type":"option","description":"Pack format version. Override the value specified in the configuration file."},"fullTrace":{"name":"fullTrace","type":"boolean","description":"Show the full stack trace on errors.","allowNo":false},"strictErrors":{"name":"strictErrors","type":"boolean","description":"Stop data pack compilation on type errors.","allowNo":false},"production":{"name":"production","type":"boolean","char":"p","description":"Runs Sandstone in production mode. This sets process.env.SANDSTONE_ENV to \"production\".","allowNo":false},"autoReload":{"name":"autoReload","type":"option","description":"Automatically reload your data pack in-game. Requires to open the world to LAN with cheats enabled, and to specify the port.","helpValue":"port"}},"args":[{"name":"path","description":"Path of the folder containing source files.","required":true,"default":"./src"},{"name":"config-path","description":"Path of the sandstone.config.ts folder.","required":true,"default":"."}]},"create":{"id":"create","description":"Create a new Sandstone project.","pluginName":"sandstone-cli","pluginType":"core","aliases":[],"examples":["$ sand create my-datapack"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"yarn":{"name":"yarn","type":"boolean","description":"Use yarn instead of npm.","allowNo":false},"npm":{"name":"npm","type":"boolean","description":"Use npm.","allowNo":false},"datapack-name":{"name":"datapack-name","type":"option","char":"d","description":"The name of the data pack."},"namespace":{"name":"namespace","type":"option","char":"n","description":"The default namespace that will be used."},"save-root":{"name":"save-root","type":"boolean","char":"r","description":"Save the data pack in the .minecraft/datapacks folder. Not compatible with --world and --custom-path.","allowNo":false},"world":{"name":"world","type":"option","char":"w","description":"The world to save the data pack in. Not compatible with --save-root and --custom-path."},"custom-path":{"name":"custom-path","type":"option","char":"p","description":"The path to save the data pack at. Not compatible with --save-root and --world."}},"args":[{"name":"project-name","description":"Name of the project folder. This is not the name of the data pack.","required":true}]},"update":{"id":"update","description":"Update Sandstone & Sandstone-CLI.","pluginName":"sandstone-cli","pluginType":"core","aliases":[],"examples":["$ sand update","$ sand update --cli","$ sand update --sandstone","$ sand update --cli --sandstone --skip"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"cli":{"name":"cli","type":"boolean","description":"Update the Sandstone CLI without asking.","allowNo":false},"sandstone":{"name":"sandstone","type":"boolean","description":"Update the current Sandstone version without asking.","allowNo":false},"skip":{"name":"skip","type":"boolean","description":"Skip all interactive prompts and refuse them.","allowNo":false},"yarn":{"name":"yarn","type":"boolean","description":"Use yarn to install the updates.","allowNo":false},"npm":{"name":"npm","type":"boolean","description":"Use npm to install the updates.","allowNo":false}},"args":[]},"watch":{"id":"watch","description":"Build the datapack, and rebuild it on file change. ⛏","pluginName":"sandstone-cli","pluginType":"core","aliases":[],"examples":["$ sand watch","$ sand watch --verbose","$ sand watch --verbose --dry"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"dry":{"name":"dry","type":"boolean","char":"d","description":"Do not save the datapack. Mostly useful with `verbose`.","allowNo":false},"verbose":{"name":"verbose","type":"boolean","char":"v","description":"Log all resulting resources: functions, advancements...","allowNo":false},"namespace":{"name":"namespace","type":"option","description":"The default namespace. Override the value specified in the configuration file."},"world":{"name":"world","type":"option","description":"The world to save the data pack in. Override the value specified in the configuration file."},"root":{"name":"root","type":"boolean","description":"Save the data pack in the `.minecraft/datapacks` folder. Override the value specified in the configuration file.","allowNo":false},"path":{"name":"path","type":"option","description":"The path to save the data pack at. Override the value specified in the configuration file."},"minecraftPath":{"name":"minecraftPath","type":"option","description":"Path of the .minecraft folder. Override the value specified in the configuration file."},"name":{"name":"name","type":"option","description":"Name of the data pack. Override the value specified in the configuration file."},"description":{"name":"description","type":"option","description":"Description of the data pack. Override the value specified in the configuration file."},"formatVersion":{"name":"formatVersion","type":"option","description":"Pack format version. Override the value specified in the configuration file."},"fullTrace":{"name":"fullTrace","type":"boolean","description":"Show the full stack trace on errors.","allowNo":false},"strictErrors":{"name":"strictErrors","type":"boolean","description":"Stop data pack compilation on type errors.","allowNo":false},"production":{"name":"production","type":"boolean","char":"p","description":"Runs Sandstone in production mode. This sets process.env.SANDSTONE_ENV to \"production\".","allowNo":false},"autoReload":{"name":"autoReload","type":"option","description":"Automatically reload your data pack in-game. Requires to open the world to LAN with cheats enabled, and to specify the port.","helpValue":"port"}},"args":[{"name":"path","description":"Path of the folder containing source files.","required":true,"default":"./src"},{"name":"config-path","description":"Path of the sandstone.config.ts folder.","required":true,"default":"."}]}}}
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sandstone-cli",
|
|
3
3
|
"description": "The CLI for Sandstone - the data pack creation library.",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"
|
|
4
|
+
"version": "0.6.0",
|
|
5
|
+
"contributors": [
|
|
6
|
+
{
|
|
7
|
+
"name": "TheMrZZ - Florian ERNST",
|
|
8
|
+
"url": "https://github.com/TheMrZZ"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"email": "mulverin3@gmail.com",
|
|
12
|
+
"name": "MulverineX",
|
|
13
|
+
"url": "https://github.com/MulverineX"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
6
16
|
"bin": {
|
|
7
17
|
"sand": "./bin/run"
|
|
8
18
|
},
|
|
@@ -12,7 +22,7 @@
|
|
|
12
22
|
"@oclif/config": "^1",
|
|
13
23
|
"@oclif/plugin-help": "^3",
|
|
14
24
|
"@oclif/plugin-warn-if-update-available": "^1.7.0",
|
|
15
|
-
"@types/node": "^
|
|
25
|
+
"@types/node": "^18.11.18",
|
|
16
26
|
"@types/semver": "^7.3.4",
|
|
17
27
|
"chalk": "^4.1.0",
|
|
18
28
|
"chokidar": "^3.4.3",
|
|
@@ -20,6 +30,7 @@
|
|
|
20
30
|
"inquirer": "^7.3.3",
|
|
21
31
|
"klaw": "^3.0.0",
|
|
22
32
|
"lodash.debounce": "^4.0.8",
|
|
33
|
+
"madge": "^5.0.1",
|
|
23
34
|
"minecraft-protocol": "^1.24.2",
|
|
24
35
|
"nanoid": "^3.1.20",
|
|
25
36
|
"pretty-error": "^2.1.2",
|
|
@@ -33,7 +44,9 @@
|
|
|
33
44
|
"@types/inquirer": "^7.3.1",
|
|
34
45
|
"@types/klaw": "^3.0.1",
|
|
35
46
|
"@types/lodash.debounce": "^4.0.6",
|
|
47
|
+
"@types/madge": "^5.0.0",
|
|
36
48
|
"@types/nodemon": "^1.19.0",
|
|
49
|
+
"chokidar-cli": "^3.0.0",
|
|
37
50
|
"eslint": "^5.13",
|
|
38
51
|
"eslint-config-oclif": "^3.1",
|
|
39
52
|
"eslint-config-oclif-typescript": "^0.1",
|
|
@@ -80,6 +93,7 @@
|
|
|
80
93
|
"posttest": "eslint . --ext .ts --config .eslintrc",
|
|
81
94
|
"prepack": "npm run build",
|
|
82
95
|
"build": "rimraf lib && tsc -b && node ./copyTemplate.js && oclif-dev manifest && oclif-dev readme",
|
|
96
|
+
"watch": "npm run build && chokidar \"src/**/*\" -c \"npm run build\"",
|
|
83
97
|
"test": "echo NO TESTS",
|
|
84
98
|
"version": "oclif-dev readme && git add README.md"
|
|
85
99
|
},
|