sandstone-cli 0.6.6 → 1.0.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/lib/index.js CHANGED
@@ -1,5 +1,77 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var command_1 = require("@oclif/command");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
1
+ #!/usr/bin/env node
2
+ import { Argument, Command } from 'commander';
3
+ import figlet from 'figlet';
4
+ import { buildCommand, createCommand, watchCommand } from './commands/index.js';
5
+ const commander = new Command();
6
+ console.log(figlet.textSync('Sandstone'));
7
+ const CLI = commander
8
+ .version('1.0.0')
9
+ .description('The CLI for Sandstone - the minecraft pack creation library.');
10
+ const BuildDeclares = {
11
+ // Flags
12
+ dry: ['-d, --dry', 'Do not save the pack. Mostly useful with `verbose`.'],
13
+ verbose: ['-v, --verbose', 'Log all resulting resources: functions, advancements...'],
14
+ root: ['-r, --root', 'Save the pack & resource pack in the .minecraft/datapacks & .minecraft/resource_packs folders. Override the value specified in the configuration file.'],
15
+ fullTrace: ['-t, --full-trace', 'Show the full stack trace on errors.'],
16
+ strictErrors: ['-s, --strict-errors', 'Stop pack compilation on type errors.'],
17
+ production: ['-p, --production', 'Runs Sandstone in production mode. This sets process.env.SANDSTONE_ENV to "production".'],
18
+ // Values
19
+ path: ['--path <path>', 'Path of the folder containing source files.', './src'],
20
+ config: ['--config-path', 'Path of the sandstone.config.ts folder.', './'],
21
+ name: ['-n, --name <name>', 'Name of the datapack. Override the value specified in the configuration file.'],
22
+ namespace: ['-ns, --namespace <namespace>', 'The default namespace. Override the value specified in the configuration file.'],
23
+ world: ['-w, --world <name>', 'The name of the world to save the packs in. Override the value specified in the configuration file.'],
24
+ clientPath: ['-c, --client-path <path>', 'Path of the client folder. Override the value specified in the configuration file.'],
25
+ serverPath: ['--server-path <path>', 'Path of the server folder. Override the value specified in the configuration file.'],
26
+ // TODO: ssh
27
+ // TODO: reimplement auto reload
28
+ }; // Haha TypeScript funny
29
+ const build = CLI
30
+ .command('build')
31
+ .description('Build the pack(s). ⛏');
32
+ build.option.apply(build, BuildDeclares.dry)
33
+ .option.apply(build, BuildDeclares.verbose)
34
+ .option.apply(build, BuildDeclares.root)
35
+ .option.apply(build, BuildDeclares.fullTrace)
36
+ .option.apply(build, BuildDeclares.strictErrors)
37
+ .option.apply(build, BuildDeclares.production)
38
+ .option.apply(build, BuildDeclares.path)
39
+ .option.apply(build, BuildDeclares.config)
40
+ .option.apply(build, BuildDeclares.name)
41
+ .option.apply(build, BuildDeclares.namespace)
42
+ .option.apply(build, BuildDeclares.world)
43
+ .option.apply(build, BuildDeclares.clientPath)
44
+ .option.apply(build, BuildDeclares.serverPath)
45
+ .action(buildCommand);
46
+ const watch = CLI
47
+ .command('watch')
48
+ .description('Build the packs, and rebuild them on file change. ⛏')
49
+ .action(watchCommand);
50
+ watch.option.apply(watch, BuildDeclares.dry)
51
+ .option.apply(watch, BuildDeclares.verbose)
52
+ .option.apply(watch, BuildDeclares.root)
53
+ .option.apply(watch, BuildDeclares.fullTrace)
54
+ .option.apply(watch, BuildDeclares.strictErrors)
55
+ .option.apply(watch, BuildDeclares.path)
56
+ .option.apply(watch, BuildDeclares.config)
57
+ .option.apply(watch, BuildDeclares.name)
58
+ .option.apply(watch, BuildDeclares.namespace)
59
+ .option.apply(watch, BuildDeclares.world)
60
+ .option.apply(watch, BuildDeclares.clientPath)
61
+ .option.apply(watch, BuildDeclares.serverPath);
62
+ const create = CLI
63
+ .command('create')
64
+ .description('Create a new Sandstone project. ⛏')
65
+ .action(createCommand)
66
+ .addArgument(new Argument('<projectName>', 'Not the name of the output pack'));
67
+ create.option.apply(create, BuildDeclares.name)
68
+ .option.apply(create, BuildDeclares.namespace)
69
+ .option.apply(create, BuildDeclares.world)
70
+ .option.apply(create, BuildDeclares.clientPath)
71
+ .option.apply(create, BuildDeclares.serverPath);
72
+ // TODO
73
+ /*CLI
74
+ .command('update')
75
+ .description('Update Sandstone & Sandstone-CLI.. ⛏')
76
+ .action(updateCommand)*/
77
+ CLI.parse(process.argv);
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { InputQuestion, Answers } from 'inquirer';
2
- export declare function getFlagOrPrompt<T extends Answers = Answers>(flags: Record<string, string | undefined | void | boolean>, name: string, inquirerProps: Omit<InputQuestion<T>, 'name'>): Promise<string>;
3
1
  export declare function hasYarn(): boolean;
2
+ export declare function hasPnpm(): boolean;
4
3
  /**
5
4
  * Get the .minecraft path
6
5
  */
@@ -22,9 +21,10 @@ export declare function getWorldPath(worldName: string, minecraftPath?: string |
22
21
  * @return The path on success, `null` if no the file is found in any parent.
23
22
  */
24
23
  export declare function getFileFolder(filename: string, from?: string): string | null;
25
- export declare type ProjectFolders = {
24
+ export type ProjectFolders = {
26
25
  absProjectFolder: string;
27
26
  rootFolder: string;
28
27
  sandstoneConfigFolder: string;
29
28
  };
30
29
  export declare function getProjectFolders(projectFolder: string): ProjectFolders;
30
+ export declare const capitalize: (s: string) => string;
package/lib/utils.js CHANGED
@@ -1,67 +1,58 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getProjectFolders = exports.getFileFolder = exports.getWorldPath = exports.getWorldsList = exports.getMinecraftPath = exports.hasYarn = exports.getFlagOrPrompt = void 0;
7
- const inquirer_1 = __importDefault(require("inquirer"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const os_1 = __importDefault(require("os"));
10
- const path_1 = __importDefault(require("path"));
11
- const child_process_1 = require("child_process");
12
- const chalk_1 = __importDefault(require("chalk"));
13
- async function getFlagOrPrompt(flags, name, inquirerProps) {
14
- const flagValue = flags[name];
15
- if (typeof flagValue === 'string') {
16
- return flagValue;
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import { execSync } from 'child_process';
5
+ import chalk from 'chalk';
6
+ export function hasYarn() {
7
+ try {
8
+ execSync('yarn --version');
9
+ return true;
10
+ }
11
+ catch (error) {
12
+ return false;
17
13
  }
18
- return (await inquirer_1.default.prompt({ name, ...inquirerProps }))[name];
19
14
  }
20
- exports.getFlagOrPrompt = getFlagOrPrompt;
21
- function hasYarn() {
15
+ export function hasPnpm() {
22
16
  try {
23
- (0, child_process_1.execSync)('yarn --version');
17
+ execSync('pnpm --version');
24
18
  return true;
25
19
  }
26
20
  catch (error) {
27
21
  return false;
28
22
  }
29
23
  }
30
- exports.hasYarn = hasYarn;
31
24
  /**
32
25
  * Get the .minecraft path
33
26
  */
34
- function getMinecraftPath() {
27
+ export function getMinecraftPath() {
35
28
  function getMCPath() {
36
- switch (os_1.default.platform()) {
29
+ switch (os.platform()) {
37
30
  case 'win32':
38
- return path_1.default.join(os_1.default.homedir(), 'AppData/Roaming/.minecraft');
31
+ return path.join(os.homedir(), 'AppData/Roaming/.minecraft');
39
32
  case 'darwin':
40
- return path_1.default.join(os_1.default.homedir(), 'Library/Application Support/minecraft');
33
+ return path.join(os.homedir(), 'Library/Application Support/minecraft');
41
34
  case 'linux':
42
35
  default:
43
- return path_1.default.join(os_1.default.homedir(), '.minecraft');
36
+ return path.join(os.homedir(), '.minecraft');
44
37
  }
45
38
  }
46
39
  const mcPath = getMCPath();
47
- if (!fs_1.default.existsSync(mcPath)) {
40
+ if (!fs.existsSync(mcPath)) {
48
41
  throw new Error('Unable to locate the .minecraft folder. Please specify it manually.');
49
42
  }
50
43
  return mcPath;
51
44
  }
52
- exports.getMinecraftPath = getMinecraftPath;
53
- function getWorldsList() {
45
+ export function getWorldsList() {
54
46
  const mcPath = getMinecraftPath();
55
- const savesPath = path_1.default.join(mcPath, 'saves');
56
- return fs_1.default.readdirSync(savesPath, { withFileTypes: true }).filter((f) => f.isDirectory).map((f) => f.name);
47
+ const savesPath = path.join(mcPath, 'saves');
48
+ return fs.readdirSync(savesPath, { withFileTypes: true }).filter((f) => f.isDirectory).map((f) => f.name);
57
49
  }
58
- exports.getWorldsList = getWorldsList;
59
50
  /**
60
51
  * @param worldName The name of the world
61
52
  * @param minecraftPath The optional location of the .minecraft folder.
62
53
  * If left unspecified, the .minecraft will be found automatically.
63
54
  */
64
- function getWorldPath(worldName, minecraftPath = undefined) {
55
+ export function getWorldPath(worldName, minecraftPath = undefined) {
65
56
  let mcPath;
66
57
  if (minecraftPath) {
67
58
  mcPath = minecraftPath;
@@ -69,15 +60,14 @@ function getWorldPath(worldName, minecraftPath = undefined) {
69
60
  else {
70
61
  mcPath = getMinecraftPath();
71
62
  }
72
- const savesPath = path_1.default.join(mcPath, 'saves');
73
- const worldPath = path_1.default.join(savesPath, worldName);
74
- if (!fs_1.default.existsSync(worldPath)) {
75
- const existingWorlds = fs_1.default.readdirSync(savesPath, { withFileTypes: true }).filter((f) => f.isDirectory).map((f) => f.name);
63
+ const savesPath = path.join(mcPath, 'saves');
64
+ const worldPath = path.join(savesPath, worldName);
65
+ if (!fs.existsSync(worldPath)) {
66
+ const existingWorlds = fs.readdirSync(savesPath, { withFileTypes: true }).filter((f) => f.isDirectory).map((f) => f.name);
76
67
  throw new Error(`Unable to locate the "${worldPath}" folder. Word ${worldName} does not exists. List of existing worlds: ${JSON.stringify(existingWorlds, null, 2)}`);
77
68
  }
78
69
  return worldPath;
79
70
  }
80
- exports.getWorldPath = getWorldPath;
81
71
  /**
82
72
  * Recursively search for a file.
83
73
  * Starts in the current folder, and go to the parent, recursively.
@@ -87,11 +77,11 @@ exports.getWorldPath = getWorldPath;
87
77
  *
88
78
  * @return The path on success, `null` if no the file is found in any parent.
89
79
  */
90
- function getFileFolder(filename, from = '.') {
91
- let fileFolder = path_1.default.resolve(from);
92
- while (!fs_1.default.existsSync(path_1.default.join(fileFolder, filename))) {
80
+ export function getFileFolder(filename, from = '.') {
81
+ let fileFolder = path.resolve(from);
82
+ while (!fs.existsSync(path.join(fileFolder, filename))) {
93
83
  // Go up 1 folder
94
- const newFileFolder = path_1.default.dirname(fileFolder);
84
+ const newFileFolder = path.dirname(fileFolder);
95
85
  if (newFileFolder == fileFolder) {
96
86
  // If we arrived to the root folder, give up.
97
87
  return null;
@@ -100,22 +90,21 @@ function getFileFolder(filename, from = '.') {
100
90
  }
101
91
  return fileFolder;
102
92
  }
103
- exports.getFileFolder = getFileFolder;
104
- function getProjectFolders(projectFolder) {
105
- const absProjectFolder = path_1.default.resolve(projectFolder);
93
+ export function getProjectFolders(projectFolder) {
94
+ const absProjectFolder = path.resolve(projectFolder);
106
95
  /// GETTING ALL MANDATORY FILES ///
107
96
  // Resolve the location of package.json, in order to get the node_modules folder.
108
97
  const rootFolder = getFileFolder('package.json', projectFolder);
109
98
  if (!rootFolder) {
110
- throw new Error((0, chalk_1.default) `{red Failed to find {bold package.json} in the "${absProjectFolder}" folder, or in any parent folder.}`);
99
+ throw new Error(chalk `{red Failed to find {bold package.json} in the "${absProjectFolder}" folder, or in any parent folder.}`);
111
100
  }
112
101
  // Resolve the location of sandstone.config.ts
113
102
  const sandstoneConfigFolder = getFileFolder('sandstone.config.ts', projectFolder);
114
103
  if (!sandstoneConfigFolder) {
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.}`);
104
+ throw new Error(chalk `{red Failed to find {bold sandstone.config.ts} in the "${absProjectFolder}" folder, or in any parent folder.}`);
116
105
  }
117
106
  return {
118
107
  absProjectFolder, rootFolder, sandstoneConfigFolder
119
108
  };
120
109
  }
121
- exports.getProjectFolders = getProjectFolders;
110
+ export const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
package/package.json CHANGED
@@ -1,7 +1,29 @@
1
1
  {
2
2
  "name": "sandstone-cli",
3
- "description": "The CLI for Sandstone - the datapack creation library.",
4
- "version": "0.6.6",
3
+ "version": "1.0.0",
4
+ "description": "The CLI for Sandstone - the minecraft pack creation library.",
5
+ "type": "module",
6
+ "exports": "./lib/index.js",
7
+ "bin": {
8
+ "sand": "./lib/index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "echo NO TESTS",
12
+ "build": "tsc"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/sandstone-mc/sandstone-cli.git"
17
+ },
18
+ "keywords": [
19
+ "sandstone",
20
+ "cli",
21
+ "command",
22
+ "line",
23
+ "interface",
24
+ "datapack",
25
+ "minecraft"
26
+ ],
5
27
  "contributors": [
6
28
  {
7
29
  "name": "TheMrZZ - Florian ERNST",
@@ -13,93 +35,35 @@
13
35
  "url": "https://github.com/MulverineX"
14
36
  }
15
37
  ],
16
- "bin": {
17
- "sand": "./bin/run"
38
+ "license": "MIT",
39
+ "bugs": {
40
+ "url": "https://github.com/sandstone-mc/sandstone-cli/issues"
18
41
  },
19
- "bugs": "https://github.com/TheMrZZ/sandstone-cli/issues",
42
+ "homepage": "https://github.com/sandstone-mc/sandstone-cli#readme",
20
43
  "dependencies": {
21
- "@oclif/command": "^1",
22
- "@oclif/config": "^1",
23
- "@oclif/plugin-help": "^3",
24
- "@oclif/plugin-warn-if-update-available": "^1.7.0",
25
- "@types/adm-zip": "^0.5.0",
26
- "@types/delete-empty": "^3.0.2",
27
- "@types/node": "^18.15.0",
28
- "@types/semver": "^7.3.4",
44
+ "@types/node": "^20.8.6",
29
45
  "adm-zip": "^0.5.10",
30
- "chalk": "^4.1.0",
31
- "chokidar": "^3.4.3",
46
+ "chalk": "^5.3.0",
47
+ "chokidar": "^3.5.3",
48
+ "commander": "^10.0.1",
32
49
  "delete-empty": "^3.0.0",
33
- "fs-extra": "^9.0.1",
34
- "inquirer": "^7.3.3",
35
- "klaw": "^3.0.0",
36
- "lodash.debounce": "^4.0.8",
37
- "madge": "^5.0.1",
38
- "minecraft-protocol": "^1.24.2",
39
- "nanoid": "^3.1.20",
40
- "pretty-error": "^2.1.2",
41
- "remove": "^0.1.5",
42
- "semver": "^7.3.4",
43
- "ts-node": "^9.0.0"
50
+ "figlet": "^1.6.0",
51
+ "fs-extra": "^11.1.1",
52
+ "inquirer": "^9.2.9",
53
+ "klaw": "^4.1.0",
54
+ "nanoid": "^4.0.2",
55
+ "pretty-error": "^4.0.0",
56
+ "semver": "^7.5.4",
57
+ "ts-node": "^10.9.1"
44
58
  },
45
59
  "devDependencies": {
46
- "@oclif/dev-cli": "^1",
47
- "@types/fs-extra": "^9.0.4",
48
- "@types/inquirer": "^7.3.1",
60
+ "@types/adm-zip": "^0.5.0",
61
+ "@types/delete-empty": "^3.0.2",
62
+ "@types/figlet": "^1.5.6",
63
+ "@types/fs-extra": "^11.0.1",
64
+ "@types/inquirer": "^9.0.3",
49
65
  "@types/klaw": "^3.0.3",
50
- "@types/lodash.debounce": "^4.0.6",
51
- "@types/madge": "^5.0.0",
52
- "@types/nodemon": "^1.19.0",
53
- "chokidar-cli": "^3.0.0",
54
- "eslint": "^5.13",
55
- "eslint-config-oclif": "^3.1",
56
- "eslint-config-oclif-typescript": "^0.1",
57
- "globby": "^10",
58
- "rimraf": "^3.0.2",
59
- "typescript": "^4.3.2"
60
- },
61
- "engines": {
62
- "node": ">=14.0.0"
63
- },
64
- "files": [
65
- "/bin",
66
- "/lib",
67
- "/npm-shrinkwrap.json",
68
- "/oclif.manifest.json"
69
- ],
70
- "homepage": "https://github.com/TheMrZZ/sandstone-cli",
71
- "keywords": [
72
- "sandstone",
73
- "cli",
74
- "command",
75
- "line",
76
- "interface",
77
- "datapack",
78
- "minecraft"
79
- ],
80
- "license": "MIT",
81
- "main": "lib/index.js",
82
- "oclif": {
83
- "commands": "./lib/commands",
84
- "bin": "sand",
85
- "plugins": [
86
- "@oclif/plugin-help",
87
- "@oclif/plugin-warn-if-update-available"
88
- ],
89
- "warn-if-update-available": {
90
- "timeoutInDays": 7,
91
- "message": "<%= chalk.rgb(229,193,0)(config.name) %> has a new update available: <%= chalk.greenBright(latest) %> (current version: <%= chalk.greenBright(config.version) %>).\nUpdate with <%= chalk.gray('npm run update') %> or <%= chalk.gray('yarn update') %>."
92
- }
93
- },
94
- "repository": "TheMrZZ/sandstone-cli",
95
- "scripts": {
96
- "postpack": "rimraf oclif.manifest.json",
97
- "posttest": "eslint . --ext .ts --config .eslintrc",
98
- "prepack": "npm run build",
99
- "build": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
100
- "watch": "npm run build && chokidar \"src/**/*\" -c \"npm run build\"",
101
- "test": "echo NO TESTS",
102
- "version": "oclif-dev readme && git add README.md"
103
- },
104
- "types": "lib/index.d.ts"
66
+ "@types/semver": "^7.5.0",
67
+ "typescript": "^5.1.6"
68
+ }
105
69
  }