sandstone-cli 1.1.4 → 1.1.5

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.
@@ -1,3 +1,4 @@
1
+ import { ProjectFolders } from '../utils.js';
1
2
  type BuildOptions = {
2
3
  dry?: boolean;
3
4
  verbose?: boolean;
@@ -15,5 +16,5 @@ type BuildOptions = {
15
16
  ssh?: any;
16
17
  dependencies?: [string, string][];
17
18
  };
18
- export declare function buildCommand(opts: BuildOptions): Promise<void>;
19
+ export declare function buildCommand(opts: BuildOptions, _folders?: ProjectFolders): Promise<void>;
19
20
  export {};
@@ -1,12 +1,30 @@
1
- import { register as tsEval } from 'ts-node';
2
1
  import path from 'path';
2
+ import { fork } from 'child_process';
3
3
  import { getProjectFolders } from '../utils.js';
4
- import { buildProject } from '../build/index.js';
5
- export async function buildCommand(opts) {
6
- const folders = getProjectFolders(opts.path);
7
- tsEval({
8
- transpileOnly: !opts.strictErrors,
9
- project: path.join(folders.rootFolder, 'tsconfig.json'),
4
+ export function buildCommand(opts, _folders) {
5
+ var _a, _b;
6
+ const folders = (_folders === null || _folders === void 0 ? void 0 : _folders.projectFolder) ? _folders : getProjectFolders(opts.path);
7
+ console.log('Compiling source...\n');
8
+ const build = fork(path.join(folders.rootFolder, 'node_modules', 'sandstone-build', 'lib', 'index.js'), process.argv.slice(2), {
9
+ stdio: 'pipe',
10
+ env: {
11
+ NODE_OPTIONS: "--loader ts-node/esm",
12
+ CLI_OPTIONS: JSON.stringify(opts),
13
+ PROJECT_FOLDERS: JSON.stringify(folders),
14
+ }
15
+ });
16
+ let esmErrored = false;
17
+ (_a = build === null || build === void 0 ? void 0 : build.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => process.stdout.write(data));
18
+ (_b = build === null || build === void 0 ? void 0 : build.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
19
+ if (esmErrored) {
20
+ process.stderr.write(data);
21
+ }
22
+ else {
23
+ esmErrored = true;
24
+ }
25
+ });
26
+ return new Promise((resolve) => {
27
+ var _a;
28
+ (_a = build === null || build === void 0 ? void 0 : build.stdout) === null || _a === void 0 ? void 0 : _a.on('end', () => resolve());
10
29
  });
11
- buildProject(opts, folders);
12
30
  }
@@ -1,5 +1,4 @@
1
1
  export declare function installNativeCommand(): Promise<void>;
2
2
  export declare function installVanillaCommand(_libraries: string[]): Promise<void>;
3
- export declare function uninstallNativeCommand(): Promise<void>;
4
3
  export declare function uninstallVanillaCommand(_libraries: string[]): Promise<void>;
5
4
  export declare function refreshCommand(): Promise<void>;
@@ -8,7 +8,7 @@ export async function installNativeCommand() {
8
8
  }
9
9
  export async function installVanillaCommand(_libraries) {
10
10
  let libraries = _libraries.map((lib) => [lib, false]);
11
- let count = (libraries === null || libraries === void 0 ? void 0 : libraries.length) || 0;
11
+ let count = libraries.length || 0;
12
12
  let manifest = false;
13
13
  try {
14
14
  manifest = JSON.parse(await fs.readFile(path.resolve('./resources/smithed.json'), 'utf-8'));
@@ -120,12 +120,9 @@ export async function installVanillaCommand(_libraries) {
120
120
  console.log;
121
121
  console.log(`${count} libraries added`);
122
122
  }
123
- export async function uninstallNativeCommand() {
124
- console.log('unimplemented');
125
- }
126
123
  export async function uninstallVanillaCommand(_libraries) {
127
124
  const libraries = _libraries || [];
128
- let count = (libraries === null || libraries === void 0 ? void 0 : libraries.length) || 0;
125
+ let count = libraries.length || 0;
129
126
  let manifestPath = path.resolve('./resources/smithed.json');
130
127
  let manifest = false;
131
128
  let lockFilePath = path.resolve('./resources/cache/lock-smithed.json');
@@ -1,4 +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
+ export { installNativeCommand, installVanillaCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js';
4
4
  export { watchCommand } from './watch.js';
@@ -1,4 +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
+ export { installNativeCommand, installVanillaCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js';
4
4
  export { watchCommand } from './watch.js';
@@ -1,8 +1,7 @@
1
- import { register as tsEval } from 'ts-node';
2
1
  import chokidar from 'chokidar';
3
2
  import path from 'path';
4
- import { buildProject } from '../build/index.js';
5
3
  import { getProjectFolders } from '../utils.js';
4
+ import { buildCommand } from './build.js';
6
5
  export async function watchCommand(opts) {
7
6
  let alreadyBuilding = false;
8
7
  let needRebuild = false;
@@ -28,7 +27,7 @@ export async function watchCommand(opts) {
28
27
  return;
29
28
  }
30
29
  alreadyBuilding = true;
31
- await buildProject(opts, folders);
30
+ await buildCommand(opts, folders);
32
31
  //client?.write('chat', { message: '/reload' })
33
32
  alreadyBuilding = false;
34
33
  if (needRebuild) {
@@ -36,14 +35,9 @@ export async function watchCommand(opts) {
36
35
  await onFilesChange();
37
36
  }
38
37
  }
39
- // Register ts-node
40
- const tsConfigPath = path.join(folders.rootFolder, 'tsconfig.json');
41
- tsEval({
42
- transpileOnly: !opts.strictErrors,
43
- project: tsConfigPath,
44
- });
45
38
  let timeout = null;
46
39
  let files = [];
40
+ console.log('Watching source for changes. Press Ctrl+C to exit.\n');
47
41
  chokidar.watch([
48
42
  path.join(folders.absProjectFolder, '/**/*'),
49
43
  path.join(folders.sandstoneConfigFolder, 'sandstone.config.ts'),
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "sandstone-cli",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
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": "./bin/run.cjs"
8
+ "sand": "./lib/index.js"
9
9
  },
10
10
  "scripts": {
11
11
  "test": "echo NO TESTS",
@@ -41,31 +41,22 @@
41
41
  },
42
42
  "homepage": "https://github.com/sandstone-mc/sandstone-cli#readme",
43
43
  "dependencies": {
44
- "@types/node": "^20.8.7",
45
- "adm-zip": "^0.5.10",
44
+ "@types/node": "^20.8.8",
46
45
  "chalk": "^5.3.0",
47
46
  "chalk-template": "^1.1.0",
48
47
  "chokidar": "^3.5.3",
49
48
  "commander": "^10.0.1",
50
- "delete-empty": "^3.0.0",
51
- "dotenv-cli": "^7.3.0",
52
49
  "figlet": "^1.6.0",
53
50
  "fs-extra": "^11.1.1",
54
51
  "inquirer": "^9.2.11",
55
- "klaw": "^4.1.0",
56
52
  "nanoid": "^4.0.2",
57
53
  "node-fetch": "^3.3.2",
58
- "pretty-error": "^4.0.0",
59
- "semver": "^7.5.4",
60
- "ts-node": "^10.9.1"
54
+ "semver": "^7.5.4"
61
55
  },
62
56
  "devDependencies": {
63
- "@types/adm-zip": "^0.5.2",
64
- "@types/delete-empty": "^3.0.2",
65
57
  "@types/figlet": "^1.5.6",
66
58
  "@types/fs-extra": "^11.0.2",
67
59
  "@types/inquirer": "^9.0.4",
68
- "@types/klaw": "^3.0.4",
69
60
  "@types/semver": "^7.5.3",
70
61
  "typescript": "^5.2.2"
71
62
  }
@@ -1,9 +1,7 @@
1
1
 
2
- import { register as tsEval } from 'ts-node'
3
2
  import path from 'path'
4
-
5
- import { getProjectFolders } from '../utils.js'
6
- import { buildProject } from '../build/index.js'
3
+ import { fork } from 'child_process'
4
+ import { ProjectFolders, getProjectFolders } from '../utils.js'
7
5
 
8
6
  type BuildOptions = {
9
7
  // Flags
@@ -28,13 +26,33 @@ type BuildOptions = {
28
26
  dependencies?: [string, string][]
29
27
  }
30
28
 
31
- export async function buildCommand(opts: BuildOptions) {
32
- const folders = getProjectFolders(opts.path)
29
+ export function buildCommand(opts: BuildOptions, _folders?: ProjectFolders) {
30
+ const folders = _folders?.projectFolder ? _folders : getProjectFolders(opts.path)
31
+
32
+ console.log('Compiling source...\n')
33
+
34
+ const build = fork(path.join(folders.rootFolder, 'node_modules', 'sandstone-build', 'lib', 'index.js'), process.argv.slice(2), {
35
+ stdio: 'pipe',
36
+ env: {
37
+ NODE_OPTIONS: "--loader ts-node/esm",
38
+ CLI_OPTIONS: JSON.stringify(opts),
39
+ PROJECT_FOLDERS: JSON.stringify(folders),
40
+ }
41
+ })
42
+
43
+ let esmErrored = false
44
+
45
+ build?.stdout?.on('data', (data) => process.stdout.write(data))
33
46
 
34
- tsEval({
35
- transpileOnly: !opts.strictErrors,
36
- project: path.join(folders.rootFolder, 'tsconfig.json'),
37
- })
47
+ build?.stderr?.on('data', (data) => {
48
+ if (esmErrored) {
49
+ process.stderr.write(data)
50
+ } else {
51
+ esmErrored = true
52
+ }
53
+ })
38
54
 
39
- buildProject(opts, folders)
55
+ return new Promise<void>((resolve) => {
56
+ build?.stdout?.on('end', () => resolve())
57
+ })
40
58
  }
@@ -20,7 +20,7 @@ type SmithedPack = { display: { description: string } }
20
20
  export async function installVanillaCommand(_libraries: string[]) {
21
21
  let libraries: [string, boolean][] = _libraries.map((lib) => [lib, false])
22
22
 
23
- let count = libraries?.length || 0
23
+ let count = libraries.length || 0
24
24
 
25
25
  let manifest: Record<string, string> | false = false
26
26
  try {
@@ -152,14 +152,10 @@ export async function installVanillaCommand(_libraries: string[]) {
152
152
  console.log(`${count} libraries added`)
153
153
  }
154
154
 
155
- export async function uninstallNativeCommand() {
156
- console.log('unimplemented')
157
- }
158
-
159
155
  export async function uninstallVanillaCommand(_libraries: string[]) {
160
156
  const libraries = _libraries || []
161
157
 
162
- let count = libraries?.length || 0
158
+ let count = libraries.length || 0
163
159
 
164
160
  let manifestPath = path.resolve('./resources/smithed.json')
165
161
 
@@ -1,4 +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
+ export { installNativeCommand, installVanillaCommand, uninstallVanillaCommand, refreshCommand } from './dependency.js'
4
4
  export { watchCommand } from './watch.js';
@@ -1,9 +1,8 @@
1
- import { register as tsEval } from 'ts-node'
2
1
  import chokidar from 'chokidar'
3
2
  import path from 'path'
4
3
 
5
- import { buildProject } from '../build/index.js'
6
4
  import { getProjectFolders } from '../utils.js'
5
+ import { buildCommand } from './build.js'
7
6
 
8
7
  type WatchOptions = {
9
8
  // Flags
@@ -56,7 +55,7 @@ export async function watchCommand(opts: WatchOptions) {
56
55
 
57
56
  alreadyBuilding = true
58
57
 
59
- await buildProject(opts, folders)
58
+ await buildCommand(opts, folders)
60
59
  //client?.write('chat', { message: '/reload' })
61
60
  alreadyBuilding = false
62
61
 
@@ -66,17 +65,11 @@ export async function watchCommand(opts: WatchOptions) {
66
65
  }
67
66
  }
68
67
 
69
- // Register ts-node
70
- const tsConfigPath = path.join(folders.rootFolder, 'tsconfig.json')
71
-
72
- tsEval({
73
- transpileOnly: !opts.strictErrors,
74
- project: tsConfigPath,
75
- })
76
-
77
68
  let timeout: NodeJS.Timeout | null = null
78
69
  let files: string[] = []
79
70
 
71
+ console.log('Watching source for changes. Press Ctrl+C to exit.\n')
72
+
80
73
  chokidar.watch([
81
74
  path.join(folders.absProjectFolder, '/**/*'),
82
75
  path.join(folders.sandstoneConfigFolder, 'sandstone.config.ts'),
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, installNativeCommand, installVanillaCommand, uninstallNativeCommand, uninstallVanillaCommand, refreshCommand } from './commands/index.js';
4
+ import { buildCommand, createCommand, watchCommand, installNativeCommand, installVanillaCommand, uninstallVanillaCommand, refreshCommand } from './commands/index.js';
5
5
 
6
6
  const commander = new Command()
7
7
 
package/bin/.env.sand DELETED
@@ -1 +0,0 @@
1
- NODE_OPTIONS=--loader ts-node/esm
package/bin/run.cjs DELETED
@@ -1,25 +0,0 @@
1
- const { fork } = require('child_process')
2
- const path = require('path')
3
-
4
- console.log(process.argv)
5
- const foo = fork(path.join(__dirname, '..', 'lib', 'index.js'), process.argv.slice(2), {
6
- stdio: 'pipe',
7
- env: {
8
- NODE_OPTIONS: "--loader ts-node/esm"
9
- }
10
- })
11
-
12
- foo.stdout.on('data', (data) => process.stdout.write(data))
13
-
14
- foo.stderr.on('data', (data) => process.stderr.write(data))
15
-
16
- process.stdin.setRawMode(true)
17
-
18
- process.stdin.on('keypress', (str, key) => {
19
- // "Raw" mode so we must do our own kill switch
20
- if(key.sequence === '\u0003') {
21
- process.exit();
22
- } else {
23
- foo.stdin.write(str)
24
- }
25
- });
@@ -1,27 +0,0 @@
1
- import { ProjectFolders } from '../utils.js';
2
- type BuildOptions = {
3
- dry?: boolean;
4
- verbose?: boolean;
5
- root?: boolean;
6
- fullTrace?: boolean;
7
- strictErrors?: boolean;
8
- production?: boolean;
9
- path: string;
10
- configPath: string;
11
- name?: string;
12
- namespace?: string;
13
- world?: string;
14
- clientPath?: string;
15
- serverPath?: string;
16
- ssh?: any;
17
- dependencies?: [string, string][];
18
- };
19
- /**
20
- * Build the project. Will log errors and never throw any.
21
- *
22
- * @param options The options to build the project with.
23
- *
24
- * @param projectFolder The folder of the project. It needs a sandstone.config.ts, and it or one of its parent needs a package.json.
25
- */
26
- export declare function buildProject(options: BuildOptions, folders: ProjectFolders): Promise<void>;
27
- export {};