@twin.org/move-to-json 0.0.1-next.13 → 0.0.1-next.15

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.
@@ -55,14 +55,24 @@ async function actionCommandMoveToJson(inputGlob, outputJson, opts) {
55
55
  try {
56
56
  // Verify the SDK before we do anything else
57
57
  await verifyPlatformSDK(opts.platform ?? PlatformTypes.Iota);
58
+ // Normalize paths and get working directory
59
+ const { normalizedGlob, normalizedOutput, executionDir } = normalizePathsAndWorkingDir(inputGlob, outputJson);
58
60
  cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.move-to-json.section.start"));
59
61
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.inputGlob"), inputGlob);
60
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.outputJson"), outputJson);
62
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.outputJson"), normalizedOutput);
61
63
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.platform"), opts.platform ?? PlatformTypes.Iota);
62
64
  cliCore.CLIDisplay.break();
63
65
  // Find matching .move files
64
66
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.move-to-json.progress.searchingFiles"));
65
- const matchedFiles = await FastGlob(inputGlob.replace(/\\/g, "/"));
67
+ const matchedFiles = await FastGlob([normalizedGlob, "!**/build/**/*.move", "!**/dependencies/**/*.move"], {
68
+ cwd: executionDir,
69
+ absolute: true,
70
+ dot: true,
71
+ followSymbolicLinks: false,
72
+ caseSensitiveMatch: false, // Important for Windows
73
+ onlyFiles: true,
74
+ stats: false
75
+ });
66
76
  if (matchedFiles.length === 0) {
67
77
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.warnings.noMoveFilesFound", {
68
78
  inputGlob
@@ -71,14 +81,14 @@ async function actionCommandMoveToJson(inputGlob, outputJson, opts) {
71
81
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.matchedFilesCount"), matchedFiles.length.toString());
72
82
  cliCore.CLIDisplay.break();
73
83
  let finalJson = {};
74
- if (await cliCore.CLIUtils.fileExists(outputJson)) {
84
+ if (await cliCore.CLIUtils.fileExists(normalizedOutput)) {
75
85
  try {
76
- const existingData = await node_fs.promises.readFile(outputJson, "utf8");
86
+ const existingData = await node_fs.promises.readFile(normalizedOutput, "utf8");
77
87
  finalJson = JSON.parse(existingData);
78
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.mergingWithExistingJson"), outputJson);
88
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.move-to-json.labels.mergingWithExistingJson"), normalizedOutput);
79
89
  }
80
90
  catch (err) {
81
- throw new core.GeneralError("commands", "commands.move-to-json.failedReadingOutputJson", { file: outputJson }, err);
91
+ throw new core.GeneralError("commands", "commands.move-to-json.failedReadingOutputJson", { file: normalizedOutput }, err);
82
92
  }
83
93
  }
84
94
  else {
@@ -102,15 +112,15 @@ async function actionCommandMoveToJson(inputGlob, outputJson, opts) {
102
112
  }
103
113
  // Ensure the output directory exists
104
114
  try {
105
- await node_fs.promises.mkdir(path.dirname(outputJson), { recursive: true });
115
+ await node_fs.promises.mkdir(path.dirname(normalizedOutput), { recursive: true });
106
116
  }
107
117
  catch (err) {
108
118
  throw new core.GeneralError("commands", "commands.move-to-json.mkdirFailed", {
109
- dir: path.dirname(outputJson)
119
+ dir: path.dirname(normalizedOutput)
110
120
  }, err);
111
121
  }
112
122
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.move-to-json.progress.writingJsonFile"));
113
- await cliCore.CLIUtils.writeJsonFile(outputJson, finalJson, true);
123
+ await cliCore.CLIUtils.writeJsonFile(normalizedOutput, finalJson, true);
114
124
  cliCore.CLIDisplay.break();
115
125
  cliCore.CLIDisplay.done();
116
126
  }
@@ -208,6 +218,24 @@ async function verifyPlatformSDK(platform) {
208
218
  throw new core.GeneralError("commands", "commands.move-to-json.sdkNotInstalled", { platform }, err);
209
219
  }
210
220
  }
221
+ /**
222
+ * Normalize paths and resolve working directory for cross-platform compatibility.
223
+ * @param inputGlob The input glob pattern
224
+ * @param outputJson The output JSON file path
225
+ * @returns Normalized paths and working directory
226
+ */
227
+ function normalizePathsAndWorkingDir(inputGlob, outputJson) {
228
+ // Get the directory where the command was run
229
+ const executionDir = process.cwd();
230
+ // Normalize paths for cross-platform compatibility
231
+ const normalizedGlob = path.resolve(inputGlob).replace(/\\/g, "/");
232
+ const normalizedOutput = path.resolve(outputJson);
233
+ return {
234
+ normalizedGlob,
235
+ normalizedOutput,
236
+ executionDir
237
+ };
238
+ }
211
239
 
212
240
  // Copyright 2024 IOTA Stiftung.
213
241
  // SPDX-License-Identifier: Apache-2.0.
@@ -227,7 +255,7 @@ class CLI extends cliCore.CLIBase {
227
255
  return this.execute({
228
256
  title: "TWIN Move to JSON",
229
257
  appName: "move-to-json",
230
- version: "0.0.1-next.13",
258
+ version: "0.0.1-next.15",
231
259
  icon: "⚙️ ",
232
260
  supportsEnvFiles: false,
233
261
  overrideOutputWidth: options?.overrideOutputWidth
@@ -52,14 +52,24 @@ async function actionCommandMoveToJson(inputGlob, outputJson, opts) {
52
52
  try {
53
53
  // Verify the SDK before we do anything else
54
54
  await verifyPlatformSDK(opts.platform ?? PlatformTypes.Iota);
55
+ // Normalize paths and get working directory
56
+ const { normalizedGlob, normalizedOutput, executionDir } = normalizePathsAndWorkingDir(inputGlob, outputJson);
55
57
  CLIDisplay.section(I18n.formatMessage("commands.move-to-json.section.start"));
56
58
  CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.inputGlob"), inputGlob);
57
- CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.outputJson"), outputJson);
59
+ CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.outputJson"), normalizedOutput);
58
60
  CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.platform"), opts.platform ?? PlatformTypes.Iota);
59
61
  CLIDisplay.break();
60
62
  // Find matching .move files
61
63
  CLIDisplay.task(I18n.formatMessage("commands.move-to-json.progress.searchingFiles"));
62
- const matchedFiles = await FastGlob(inputGlob.replace(/\\/g, "/"));
64
+ const matchedFiles = await FastGlob([normalizedGlob, "!**/build/**/*.move", "!**/dependencies/**/*.move"], {
65
+ cwd: executionDir,
66
+ absolute: true,
67
+ dot: true,
68
+ followSymbolicLinks: false,
69
+ caseSensitiveMatch: false, // Important for Windows
70
+ onlyFiles: true,
71
+ stats: false
72
+ });
63
73
  if (matchedFiles.length === 0) {
64
74
  CLIDisplay.value(I18n.formatMessage("commands.move-to-json.warnings.noMoveFilesFound", {
65
75
  inputGlob
@@ -68,14 +78,14 @@ async function actionCommandMoveToJson(inputGlob, outputJson, opts) {
68
78
  CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.matchedFilesCount"), matchedFiles.length.toString());
69
79
  CLIDisplay.break();
70
80
  let finalJson = {};
71
- if (await CLIUtils.fileExists(outputJson)) {
81
+ if (await CLIUtils.fileExists(normalizedOutput)) {
72
82
  try {
73
- const existingData = await promises.readFile(outputJson, "utf8");
83
+ const existingData = await promises.readFile(normalizedOutput, "utf8");
74
84
  finalJson = JSON.parse(existingData);
75
- CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.mergingWithExistingJson"), outputJson);
85
+ CLIDisplay.value(I18n.formatMessage("commands.move-to-json.labels.mergingWithExistingJson"), normalizedOutput);
76
86
  }
77
87
  catch (err) {
78
- throw new GeneralError("commands", "commands.move-to-json.failedReadingOutputJson", { file: outputJson }, err);
88
+ throw new GeneralError("commands", "commands.move-to-json.failedReadingOutputJson", { file: normalizedOutput }, err);
79
89
  }
80
90
  }
81
91
  else {
@@ -99,15 +109,15 @@ async function actionCommandMoveToJson(inputGlob, outputJson, opts) {
99
109
  }
100
110
  // Ensure the output directory exists
101
111
  try {
102
- await promises.mkdir(path.dirname(outputJson), { recursive: true });
112
+ await promises.mkdir(path.dirname(normalizedOutput), { recursive: true });
103
113
  }
104
114
  catch (err) {
105
115
  throw new GeneralError("commands", "commands.move-to-json.mkdirFailed", {
106
- dir: path.dirname(outputJson)
116
+ dir: path.dirname(normalizedOutput)
107
117
  }, err);
108
118
  }
109
119
  CLIDisplay.task(I18n.formatMessage("commands.move-to-json.progress.writingJsonFile"));
110
- await CLIUtils.writeJsonFile(outputJson, finalJson, true);
120
+ await CLIUtils.writeJsonFile(normalizedOutput, finalJson, true);
111
121
  CLIDisplay.break();
112
122
  CLIDisplay.done();
113
123
  }
@@ -205,6 +215,24 @@ async function verifyPlatformSDK(platform) {
205
215
  throw new GeneralError("commands", "commands.move-to-json.sdkNotInstalled", { platform }, err);
206
216
  }
207
217
  }
218
+ /**
219
+ * Normalize paths and resolve working directory for cross-platform compatibility.
220
+ * @param inputGlob The input glob pattern
221
+ * @param outputJson The output JSON file path
222
+ * @returns Normalized paths and working directory
223
+ */
224
+ function normalizePathsAndWorkingDir(inputGlob, outputJson) {
225
+ // Get the directory where the command was run
226
+ const executionDir = process.cwd();
227
+ // Normalize paths for cross-platform compatibility
228
+ const normalizedGlob = path.resolve(inputGlob).replace(/\\/g, "/");
229
+ const normalizedOutput = path.resolve(outputJson);
230
+ return {
231
+ normalizedGlob,
232
+ normalizedOutput,
233
+ executionDir
234
+ };
235
+ }
208
236
 
209
237
  // Copyright 2024 IOTA Stiftung.
210
238
  // SPDX-License-Identifier: Apache-2.0.
@@ -224,7 +252,7 @@ class CLI extends CLIBase {
224
252
  return this.execute({
225
253
  title: "TWIN Move to JSON",
226
254
  appName: "move-to-json",
227
- version: "0.0.1-next.13",
255
+ version: "0.0.1-next.15",
228
256
  icon: "⚙️ ",
229
257
  supportsEnvFiles: false,
230
258
  overrideOutputWidth: options?.overrideOutputWidth
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/move-to-json - Changelog
2
2
 
3
- ## v0.0.1-next.13
3
+ ## v0.0.1-next.15
4
4
 
5
5
  - Initial Release
package/docs/examples.md CHANGED
@@ -59,10 +59,10 @@ myContract.move
59
59
  myOtherContract.move
60
60
  ```
61
61
 
62
- Where myProject is considered the project root”:
62
+ Where `myProject` is considered the `project root`:
63
63
 
64
- - The CLI runs iota move build or sui move build in the project root (the folder containing Move.toml).
65
- - The compiled .mv bytecode modules are placed under build/<snake_case_package_name>/bytecode_modules.
64
+ - The CLI runs `iota move build` or `sui move build` in the project root (the folder containing Move.toml).
65
+ - The compiled .mv bytecode modules are placed under `build/<snake_case_package_name>/bytecode_modules`.
66
66
  - The CLI loads these .mv files, computes a package ID (SHA3-256), and Base64-encodes them.
67
67
 
68
68
  However, you can pass any glob pattern that matches one or more .move files. For each file, the CLI will move up one directory from wherever that file is located until it finds the Move.toml. As long as each .move file resides in a standard Move project folder (meaning you do have a Move.toml in its parent directory or above), this tool can find and build the contract.
@@ -80,11 +80,11 @@ Then your glob might look like:
80
80
  move-to-json "./somewhere/nested/sources/*.move" ./build/contracts.json
81
81
  ```
82
82
 
83
- The CLI will automatically detect the project root as “./somewhere/nested and run the Move compiler there.
83
+ The CLI will automatically detect the project root as `./somewhere/nested` and run the Move compiler there.
84
84
 
85
85
  ## Output JSON Format
86
86
 
87
- The resulting JSON file (e.g. ./src/contracts/contracts.json) will be updated with an entry for each contract file. The key is the kebab-cased file name (e.g. myContract.move → my-contract).
87
+ The resulting JSON file (e.g. `./src/contracts/contracts.json`) will be updated with an entry for each contract file. The key is the kebab-cased file name (e.g. `myContract.move``my-contract`).
88
88
 
89
89
  Each entry has:
90
90
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/move-to-json",
3
- "version": "0.0.1-next.13",
4
- "description": "Tool to convert Move source files to JSON schemas",
3
+ "version": "0.0.1-next.15",
4
+ "description": "Tool to convert Move source files to JSON",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/dlt.git",