@apps-in-toss/cli 0.0.39 → 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.
Files changed (3) hide show
  1. package/dist/index.cjs +573 -40
  2. package/dist/index.js +573 -40
  3. package/package.json +9 -3
package/dist/index.js CHANGED
@@ -785,7 +785,7 @@ import assert from "assert";
785
785
  import fs2 from "fs";
786
786
  import path from "path";
787
787
  import * as p from "@clack/prompts";
788
- import { getPackageRoot, readZipContent } from "@react-native-bedrock/utils";
788
+ import { getPackageRoot, readZipContent } from "@granite-js/utils";
789
789
  import { Command, Option } from "clipanion";
790
790
 
791
791
  // src/utils/constants.ts
@@ -912,7 +912,7 @@ init_esm_shims();
912
912
  import fs3 from "fs";
913
913
  import path2 from "path";
914
914
  import * as p2 from "@clack/prompts";
915
- import { getPackageRoot as getPackageRoot2 } from "@react-native-bedrock/utils";
915
+ import { getPackageRoot as getPackageRoot2 } from "@granite-js/utils";
916
916
  import { Command as Command2, Option as Option2 } from "clipanion";
917
917
 
918
918
  // ../../.yarn/cache/es-toolkit-npm-1.32.0-019fc7c155-56ba965570.zip/node_modules/es-toolkit/dist/index.mjs
@@ -957,9 +957,10 @@ export default defineConfig({
957
957
  });
958
958
  `;
959
959
  var REACT_NATIVE_FRAMEWORK_CONFIG_TEMPLATE = `import { appsInToss } from '@apps-in-toss/framework/plugins';
960
- import { defineConfig } from 'react-native-bedrock/config';
960
+ import { defineConfig } from '@granite-js/react-native/config';
961
961
 
962
962
  export default defineConfig({
963
+ scheme: 'intoss',
963
964
  appName: '%%appName%%',
964
965
  plugins: [
965
966
  appsInToss({
@@ -976,7 +977,7 @@ export default defineConfig({
976
977
  `;
977
978
  var APP_TEMPLATE = `import { AppsInToss } from '@apps-in-toss/framework';
978
979
  import { PropsWithChildren } from 'react';
979
- import { InitialProps } from 'react-native-bedrock';
980
+ import { InitialProps } from '@granite-js/react-native';
980
981
  import { context } from '../require.context';
981
982
 
982
983
  function AppContainer({ children }: PropsWithChildren<InitialProps>) {
@@ -1019,17 +1020,17 @@ async function templateWebFramework({ appName, cwd, skipInput }) {
1019
1020
  dev: scripts?.scripts?.dev || scripts?.scripts?.start,
1020
1021
  build: scripts?.scripts?.build
1021
1022
  };
1022
- scripts.scripts.dev = "bedrock dev";
1023
- scripts.scripts.build = "bedrock build";
1023
+ scripts.scripts.dev = "granite dev";
1024
+ scripts.scripts.build = "granite build";
1024
1025
  scripts.scripts.deploy = "ait deploy";
1025
1026
  await fs3.promises.writeFile(path2.join(cwd, "package.json"), JSON.stringify(scripts, null, 2), {
1026
1027
  encoding: "utf-8"
1027
1028
  });
1028
1029
  p2.log.step(".gitignore \uD30C\uC77C\uC744 \uC5C5\uB370\uC774\uD2B8\uD558\uB294 \uC911...");
1029
- await fs3.promises.appendFile(path2.join(cwd, ".gitignore"), "\n.bedrock\n");
1030
+ await fs3.promises.appendFile(path2.join(cwd, ".gitignore"), "\n.granite\n");
1030
1031
  const placeholder = {
1031
- dev: originalScripts.dev === "bedrock dev" ? "" : originalScripts.dev,
1032
- build: originalScripts.build === "bedrock build" ? "" : originalScripts.build
1032
+ dev: originalScripts.dev === "granite dev" ? "" : originalScripts.dev,
1033
+ build: originalScripts.build === "granite build" ? "" : originalScripts.build
1033
1034
  };
1034
1035
  const scriptInputs = skipInput ? placeholder : await p2.group(
1035
1036
  {
@@ -1050,7 +1051,7 @@ async function templateWebFramework({ appName, cwd, skipInput }) {
1050
1051
  }
1051
1052
  }
1052
1053
  );
1053
- p2.log.step("bedrock.config.ts \uD30C\uC77C\uC744 \uC0DD\uC131\uD558\uB294 \uC911...");
1054
+ p2.log.step("granite.config.ts \uD30C\uC77C\uC744 \uC0DD\uC131\uD558\uB294 \uC911...");
1054
1055
  const webPort = skipInput ? "5173" : await p2.text({
1055
1056
  message: "Enter web port",
1056
1057
  placeholder: "5173",
@@ -1063,19 +1064,19 @@ async function templateWebFramework({ appName, cwd, skipInput }) {
1063
1064
  const config = transformTemplate(WEB_FRAMEWORK_CONFIG_TEMPLATE, {
1064
1065
  appName,
1065
1066
  webPort,
1066
- webDevCommand: scriptInputs.dev === "bedrock dev" ? "" : scriptInputs.dev,
1067
- webBuildCommand: scriptInputs.build === "bedrock build" ? "" : scriptInputs.build
1067
+ webDevCommand: scriptInputs.dev === "granite dev" ? "" : scriptInputs.dev,
1068
+ webBuildCommand: scriptInputs.build === "granite build" ? "" : scriptInputs.build
1068
1069
  });
1069
- await fs3.promises.writeFile(path2.join(cwd, "bedrock.config.ts"), config, {
1070
+ await fs3.promises.writeFile(path2.join(cwd, "granite.config.ts"), config, {
1070
1071
  encoding: "utf-8"
1071
1072
  });
1072
1073
  }
1073
1074
  async function templateReactNative({ appName, cwd }) {
1074
- p2.log.step("bedrock.config.ts \uD30C\uC77C\uC744 \uC0DD\uC131\uD558\uB294 \uC911...");
1075
+ p2.log.step("granite.config.ts \uD30C\uC77C\uC744 \uC0DD\uC131\uD558\uB294 \uC911...");
1075
1076
  const config = transformTemplate(REACT_NATIVE_FRAMEWORK_CONFIG_TEMPLATE, {
1076
1077
  appName
1077
1078
  });
1078
- await fs3.promises.writeFile(path2.join(cwd, "bedrock.config.ts"), config, {
1079
+ await fs3.promises.writeFile(path2.join(cwd, "granite.config.ts"), config, {
1079
1080
  encoding: "utf-8"
1080
1081
  });
1081
1082
  p2.log.step("src/_app.tsx \uD30C\uC77C\uC744 \uC0DD\uC131\uD558\uB294 \uC911...");
@@ -1101,8 +1102,8 @@ var InitCommand = class extends Command2 {
1101
1102
  },
1102
1103
  {
1103
1104
  value: "react-native",
1104
- label: "React Native \uD504\uB808\uC784\uC6CC\uD06C (Bedrock)",
1105
- hint: "Bedrock \uD504\uB85C\uC81D\uD2B8\uC5D0 \uC571\uC778\uD1A0\uC2A4 React Native\uC6A9 \uAC1C\uBC1C\uD658\uACBD\uC744 \uC138\uD305\uD569\uB2C8\uB2E4."
1105
+ label: "React Native \uD504\uB808\uC784\uC6CC\uD06C (Granite)",
1106
+ hint: "Granite \uD504\uB85C\uC81D\uD2B8\uC5D0 \uC571\uC778\uD1A0\uC2A4 React Native\uC6A9 \uAC1C\uBC1C\uD658\uACBD\uC744 \uC138\uD305\uD569\uB2C8\uB2E4."
1106
1107
  }
1107
1108
  ]
1108
1109
  })
@@ -1154,19 +1155,550 @@ var InitCommand = class extends Command2 {
1154
1155
  }
1155
1156
  };
1156
1157
 
1158
+ // src/MigrateCommand/index.ts
1159
+ init_esm_shims();
1160
+
1161
+ // src/MigrateCommand/MigrateCommand.ts
1162
+ init_esm_shims();
1163
+ import { Command as Command3, Option as Option3 } from "clipanion";
1164
+
1165
+ // src/MigrateCommand/logger/index.ts
1166
+ init_esm_shims();
1167
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
1168
+ var Logger = class {
1169
+ prefix = import_picocolors2.default.bold(import_picocolors2.default.bgCyan(import_picocolors2.default.black(" MIGRATE ")));
1170
+ log(...args) {
1171
+ console.log(this.prefix, ...args);
1172
+ }
1173
+ success(...args) {
1174
+ console.log(this.prefix, import_picocolors2.default.green("\u2713"), ...args);
1175
+ }
1176
+ error(...args) {
1177
+ console.error(this.prefix, import_picocolors2.default.red("\u2717"), ...args);
1178
+ }
1179
+ warn(...args) {
1180
+ console.warn(this.prefix, import_picocolors2.default.yellow("!"), ...args);
1181
+ }
1182
+ };
1183
+ var logger = new Logger();
1184
+
1185
+ // src/MigrateCommand/presets/index.ts
1186
+ init_esm_shims();
1187
+
1188
+ // src/MigrateCommand/presets/granite/index.ts
1189
+ init_esm_shims();
1190
+
1191
+ // src/MigrateCommand/presets/granite/migrateGranite.ts
1192
+ init_esm_shims();
1193
+ import assert2 from "assert";
1194
+ import dedent from "dedent";
1195
+
1196
+ // src/MigrateCommand/presets/granite/configProcessor.ts
1197
+ init_esm_shims();
1198
+
1199
+ // src/MigrateCommand/fs/fileProcessor.ts
1200
+ init_esm_shims();
1201
+ import { promises as fs4 } from "fs";
1202
+ async function readFile(filePath) {
1203
+ try {
1204
+ return await fs4.readFile(filePath, "utf-8");
1205
+ } catch {
1206
+ throw new Error(`Failed to read file: ${filePath}`);
1207
+ }
1208
+ }
1209
+ async function writeFile(filePath, content) {
1210
+ try {
1211
+ await fs4.writeFile(filePath, content, "utf-8");
1212
+ } catch {
1213
+ throw new Error(`Failed to write file: ${filePath}`);
1214
+ }
1215
+ }
1216
+ async function fileExists(filePath) {
1217
+ try {
1218
+ await fs4.access(filePath);
1219
+ return true;
1220
+ } catch {
1221
+ return false;
1222
+ }
1223
+ }
1224
+ async function renameFile(oldPath, newPath) {
1225
+ try {
1226
+ await fs4.rename(oldPath, newPath);
1227
+ } catch {
1228
+ throw new Error(`Failed to rename file: ${oldPath} -> ${newPath}`);
1229
+ }
1230
+ }
1231
+
1232
+ // src/MigrateCommand/presets/granite/configProcessor.ts
1233
+ var configTransformer = (root, { j }) => {
1234
+ root.find(j.ImportDeclaration).forEach((path5) => {
1235
+ const source = path5.value.source;
1236
+ if (j.StringLiteral.check(source) && source.value === "react-native-bedrock/config") {
1237
+ const defineConfigName = path5.value.specifiers?.find(
1238
+ (specifier) => j.ImportSpecifier.check(specifier) && specifier.imported.name === "defineConfig"
1239
+ )?.local?.name;
1240
+ if (!defineConfigName) {
1241
+ return;
1242
+ }
1243
+ root.find(j.CallExpression).forEach((path6) => {
1244
+ const callee = path6.value.callee;
1245
+ if (j.Identifier.check(callee) && callee.name === defineConfigName && path6.value.arguments.length > 0 && j.ObjectExpression.check(path6.value.arguments[0])) {
1246
+ const obj = path6.value.arguments[0];
1247
+ const hasScheme = obj.properties.some(
1248
+ (prop) => j.ObjectProperty.check(prop) && j.Identifier.check(prop.key) && prop.key.name === "scheme"
1249
+ );
1250
+ if (!hasScheme) {
1251
+ obj.properties.unshift(j.objectProperty(j.identifier("scheme"), j.stringLiteral("intoss")));
1252
+ }
1253
+ const routerImport = root.find(j.ImportDeclaration).filter((path7) => {
1254
+ const source2 = path7.value.source;
1255
+ return j.StringLiteral.check(source2) && source2.value === "@granite-js/plugin-router";
1256
+ });
1257
+ if (routerImport.length === 0) {
1258
+ const firstImport = root.find(j.ImportDeclaration).at(0);
1259
+ if (firstImport.length > 0) {
1260
+ firstImport.insertAfter(
1261
+ j.importDeclaration(
1262
+ [j.importSpecifier(j.identifier("router"))],
1263
+ j.stringLiteral("@granite-js/plugin-router")
1264
+ )
1265
+ );
1266
+ }
1267
+ }
1268
+ const hasPlugins = obj.properties.some(
1269
+ (prop) => j.ObjectProperty.check(prop) && j.Identifier.check(prop.key) && prop.key.name === "plugins"
1270
+ );
1271
+ const routerPluginCallExpr = j.callExpression(j.identifier("router"), []);
1272
+ if (hasPlugins) {
1273
+ const pluginsProp = obj.properties.find(
1274
+ (prop) => j.ObjectProperty.check(prop) && j.Identifier.check(prop.key) && prop.key.name === "plugins"
1275
+ );
1276
+ if (j.ObjectProperty.check(pluginsProp) && j.ArrayExpression.check(pluginsProp.value)) {
1277
+ const hasRouter = pluginsProp.value.elements.some(
1278
+ (element) => j.Identifier.check(element) && element.name === "router"
1279
+ );
1280
+ if (!hasRouter) {
1281
+ pluginsProp.value.elements.push(routerPluginCallExpr);
1282
+ }
1283
+ }
1284
+ } else {
1285
+ obj.properties.unshift(
1286
+ j.objectProperty(j.identifier("plugins"), j.arrayExpression([routerPluginCallExpr]))
1287
+ );
1288
+ }
1289
+ }
1290
+ });
1291
+ }
1292
+ });
1293
+ return root;
1294
+ };
1295
+ var processBedrockConfig = async (cwd, config) => {
1296
+ logger.log("Processing bedrock.config.ts...");
1297
+ const bedrockConfigPath = `${cwd}/bedrock.config.ts`;
1298
+ const graniteConfigPath = `${cwd}/granite.config.ts`;
1299
+ if (!await fileExists(bedrockConfigPath)) {
1300
+ logger.log("No bedrock.config.ts found");
1301
+ return;
1302
+ }
1303
+ if (config.dryRun) {
1304
+ return;
1305
+ }
1306
+ try {
1307
+ await renameFile(bedrockConfigPath, graniteConfigPath);
1308
+ logger.success("Renamed bedrock.config.ts to granite.config.ts");
1309
+ } catch (error) {
1310
+ logger.error(`Failed to process bedrock.config.ts: ${error}`);
1311
+ }
1312
+ };
1313
+
1314
+ // src/MigrateCommand/presets/granite/gitignoreProcessor.ts
1315
+ init_esm_shims();
1316
+ var processGitignore = async (cwd, config) => {
1317
+ let modified = false;
1318
+ logger.log("Processing .gitignore...");
1319
+ const gitignorePath = `${cwd}/.gitignore`;
1320
+ try {
1321
+ if (await fileExists(gitignorePath)) {
1322
+ const content = await readFile(gitignorePath);
1323
+ const newContent = content.replace(/\.bedrock/g, ".granite");
1324
+ if (newContent !== content) {
1325
+ if (config.dryRun) {
1326
+ logger.log("Skipping file write in dry run mode");
1327
+ } else {
1328
+ await writeFile(gitignorePath, newContent);
1329
+ logger.success("Updated .gitignore");
1330
+ }
1331
+ modified ||= true;
1332
+ } else {
1333
+ logger.log(`No changes needed in ${gitignorePath}`);
1334
+ }
1335
+ }
1336
+ } catch (error) {
1337
+ logger.error(`Failed to process .gitignore: ${error}`);
1338
+ }
1339
+ if (!modified) {
1340
+ logger.log("No .gitignore found");
1341
+ return;
1342
+ }
1343
+ };
1344
+
1345
+ // src/MigrateCommand/presets/granite/identifierReplacements.ts
1346
+ init_esm_shims();
1347
+
1348
+ // src/MigrateCommand/codemod/utils.ts
1349
+ init_esm_shims();
1350
+ function getIdentifierName(j, id) {
1351
+ if (typeof id === "string") {
1352
+ return id;
1353
+ }
1354
+ if (j.Identifier.check(id)) {
1355
+ return id.name;
1356
+ }
1357
+ return "";
1358
+ }
1359
+
1360
+ // src/MigrateCommand/presets/granite/identifierReplacements.ts
1361
+ var identifierReplacementsTransformer = (root, { j }) => {
1362
+ const importedVariables = /* @__PURE__ */ new Set();
1363
+ function toGraniteName(name) {
1364
+ let newName = null;
1365
+ if (name === "BedrockRoute") {
1366
+ newName = "createRoute";
1367
+ } else if (name.startsWith("bedrock")) {
1368
+ newName = toGraniteCamel(name);
1369
+ } else if (name.startsWith("Bedrock")) {
1370
+ newName = toGranitePascal(name);
1371
+ } else if (name.startsWith("BEDROCK")) {
1372
+ newName = toGraniteSnake(name);
1373
+ }
1374
+ return newName;
1375
+ }
1376
+ function toGraniteCamel(name) {
1377
+ const rest = name.substring(7);
1378
+ return "granite" + rest;
1379
+ }
1380
+ function toGranitePascal(name) {
1381
+ const rest = name.substring(7);
1382
+ return "Granite" + rest;
1383
+ }
1384
+ function toGraniteSnake(name) {
1385
+ const rest = name.substring(7);
1386
+ return "GRANITE" + rest;
1387
+ }
1388
+ root.find(j.ImportDeclaration, { source: { value: "react-native-bedrock" } }).forEach((importPath) => {
1389
+ importPath.value.specifiers?.forEach((specifier) => {
1390
+ if (j.ImportSpecifier.check(specifier)) {
1391
+ const importedName = getIdentifierName(j, specifier.imported);
1392
+ const localName = specifier.local ? getIdentifierName(j, specifier.local) : importedName;
1393
+ if (j.Identifier.check(specifier.imported)) {
1394
+ const newName = toGraniteName(importedName);
1395
+ if (newName) {
1396
+ specifier.imported.name = newName;
1397
+ }
1398
+ }
1399
+ importedVariables.add(localName);
1400
+ }
1401
+ });
1402
+ });
1403
+ root.find(j.Identifier).forEach((path5) => {
1404
+ const name = path5.value.name;
1405
+ if (importedVariables.has(name)) {
1406
+ const newName = toGraniteName(path5.value.name);
1407
+ if (newName) {
1408
+ path5.value.name = newName;
1409
+ }
1410
+ }
1411
+ });
1412
+ return root;
1413
+ };
1414
+
1415
+ // src/MigrateCommand/presets/granite/isBedrockProject.ts
1416
+ init_esm_shims();
1417
+ import * as fs5 from "fs";
1418
+ var BASE_NAME = "bedrock.config";
1419
+ var EXTENSIONS = ["ts", "mts", "js", "cjs"];
1420
+ async function isBedrockProject(cwd) {
1421
+ const files = fs5.readdirSync(cwd);
1422
+ return files.some(isBedrockConfigFile);
1423
+ }
1424
+ function isBedrockConfigFile(file) {
1425
+ return EXTENSIONS.some((ext) => file === `${BASE_NAME}.${ext}`);
1426
+ }
1427
+
1428
+ // src/MigrateCommand/presets/granite/packageImports.ts
1429
+ init_esm_shims();
1430
+ var import_picocolors3 = __toESM(require_picocolors(), 1);
1431
+
1432
+ // src/MigrateCommand/presets/granite/constants.ts
1433
+ init_esm_shims();
1434
+ var UNSUPPORTED_LIBRARIES = [
1435
+ "@react-native-bedrock/e2e-testing-library",
1436
+ "@react-native-bedrock/babel-plugin-obfuscate"
1437
+ ];
1438
+ var TARGET_VERSION = {
1439
+ granitePackages: "0.1.20",
1440
+ appsInTossPackages: "^1.0.0",
1441
+ tossDesignSystem: "^1.0.4"
1442
+ };
1443
+
1444
+ // src/MigrateCommand/presets/granite/packageImports.ts
1445
+ var packageImportsTransformer = (root, { j }, { fileName = "<unknown>" }) => {
1446
+ function transformPackageName(value) {
1447
+ if (UNSUPPORTED_LIBRARIES.includes(value)) {
1448
+ const libName = import_picocolors3.default.gray(`(${value})`);
1449
+ logger.warn(`Unsupported library found ${libName}`);
1450
+ logger.warn(`\u2514\u2500 ${import_picocolors3.default.gray(`at ${fileName}`)}`);
1451
+ return value;
1452
+ }
1453
+ if (value === "react-native-bedrock" || value.startsWith("react-native-bedrock/")) {
1454
+ return value.replace("react-native-bedrock", "@granite-js/react-native");
1455
+ }
1456
+ if (value.startsWith("@react-native-bedrock/")) {
1457
+ return value.replace("@react-native-bedrock/", "@granite-js/");
1458
+ }
1459
+ return value;
1460
+ }
1461
+ root.find(j.ImportDeclaration).forEach((path5) => {
1462
+ const source = path5.value.source;
1463
+ if (j.StringLiteral.check(source)) {
1464
+ const transformed = transformPackageName(source.value);
1465
+ if (transformed !== source.value) {
1466
+ source.value = transformed;
1467
+ }
1468
+ }
1469
+ });
1470
+ root.find(j.CallExpression, {
1471
+ callee: { name: "require" }
1472
+ }).forEach((path5) => {
1473
+ const args = path5.value.arguments;
1474
+ if (args.length > 0 && j.StringLiteral.check(args[0])) {
1475
+ const transformed = transformPackageName(args[0].value);
1476
+ if (transformed !== args[0].value) {
1477
+ args[0].value = transformed;
1478
+ }
1479
+ }
1480
+ });
1481
+ root.find(j.ImportExpression).forEach((path5) => {
1482
+ const source = path5.value.source;
1483
+ if (j.StringLiteral.check(source)) {
1484
+ const transformed = transformPackageName(source.value);
1485
+ if (transformed !== source.value) {
1486
+ source.value = transformed;
1487
+ }
1488
+ }
1489
+ });
1490
+ return root;
1491
+ };
1492
+
1493
+ // src/MigrateCommand/presets/granite/packageJsonProcessor.ts
1494
+ init_esm_shims();
1495
+ var import_picocolors4 = __toESM(require_picocolors(), 1);
1496
+ var processPackageJson = async (cwd, config) => {
1497
+ logger.log("Processing package.json...");
1498
+ const packageJsonPath = `${cwd}/package.json`;
1499
+ if (!await fileExists(packageJsonPath)) {
1500
+ logger.log("No package.json found");
1501
+ return;
1502
+ }
1503
+ try {
1504
+ const content = await readFile(packageJsonPath);
1505
+ const packageJson = JSON.parse(content);
1506
+ let modified = false;
1507
+ const depFields = ["dependencies", "devDependencies", "peerDependencies"];
1508
+ for (const field of depFields) {
1509
+ if (packageJson[field]) {
1510
+ const deps = packageJson[field];
1511
+ const newDeps = {
1512
+ "@granite-js/plugin-router": TARGET_VERSION.granitePackages
1513
+ };
1514
+ for (const [originLibName, originLibVersion] of Object.entries(deps)) {
1515
+ let libName = originLibName;
1516
+ let libVersion = originLibVersion;
1517
+ if (originLibName === "react-native-bedrock") {
1518
+ libName = "@granite-js/react-native";
1519
+ libVersion = TARGET_VERSION.granitePackages;
1520
+ } else if (originLibName.startsWith("@react-native-bedrock/")) {
1521
+ if (UNSUPPORTED_LIBRARIES.includes(originLibName)) {
1522
+ const packageName = import_picocolors4.default.gray(`(${originLibName})`);
1523
+ logger.warn(`Unsupported library found in package.json ${packageName}`);
1524
+ } else {
1525
+ libName = originLibName.replace("@react-native-bedrock", "@granite-js");
1526
+ libVersion = TARGET_VERSION.granitePackages;
1527
+ }
1528
+ }
1529
+ if (libName.startsWith("@apps-in-toss/")) {
1530
+ libVersion = TARGET_VERSION.appsInTossPackages;
1531
+ } else if (libName === "@toss-design-system/react-native") {
1532
+ libVersion = TARGET_VERSION.tossDesignSystem;
1533
+ }
1534
+ newDeps[libName] = libVersion;
1535
+ modified ||= libName !== originLibName;
1536
+ }
1537
+ packageJson[field] = newDeps;
1538
+ }
1539
+ }
1540
+ if (packageJson.scripts) {
1541
+ const scripts = packageJson.scripts;
1542
+ for (const [key, value] of Object.entries(scripts)) {
1543
+ if (typeof value === "string" && value.includes("bedrock")) {
1544
+ scripts[key] = value.replace(/\bbedrock\b/g, "granite");
1545
+ modified ||= true;
1546
+ }
1547
+ }
1548
+ }
1549
+ if (config.dryRun) {
1550
+ return;
1551
+ }
1552
+ if (modified) {
1553
+ await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
1554
+ logger.success("Updated package.json");
1555
+ } else {
1556
+ logger.log("No changes needed in package.json");
1557
+ }
1558
+ } catch (error) {
1559
+ logger.error(`Failed to process package.json: ${error}`);
1560
+ }
1561
+ };
1562
+
1563
+ // src/MigrateCommand/codemod/index.ts
1564
+ init_esm_shims();
1565
+
1566
+ // src/MigrateCommand/codemod/transform.ts
1567
+ init_esm_shims();
1568
+ import jscodeshift from "jscodeshift";
1569
+ function transform(source, { transformers: transformers2, options = {} }) {
1570
+ const j = jscodeshift.withParser("tsx");
1571
+ const report = [];
1572
+ const stats = /* @__PURE__ */ new Map();
1573
+ const context = {
1574
+ j,
1575
+ jscodeshift: j,
1576
+ stats: (name, quantity = 1) => {
1577
+ if (quantity === 0) {
1578
+ return;
1579
+ }
1580
+ stats.set(name, (stats.get(name) ?? 0) + quantity);
1581
+ },
1582
+ report: (message) => {
1583
+ report.push(message);
1584
+ }
1585
+ };
1586
+ const root = transformers2.reduce((root2, transformer) => transformer(root2, context, options), j(source));
1587
+ return root.toSource();
1588
+ }
1589
+
1590
+ // src/MigrateCommand/fs/fileScanner.ts
1591
+ init_esm_shims();
1592
+ import glob from "fast-glob";
1593
+ var DEFAULT_EXTENSIONS = ["js", "ts", "jsx", "tsx", "cjs", "mjs"];
1594
+ var DEFAULT_EXCLUDE_PATTERNS = ["**/node_modules/**", "**/.git/**", "**/dist/**"];
1595
+ async function scanFiles(directory, options = {}) {
1596
+ const { extensions = DEFAULT_EXTENSIONS, excludePatterns = DEFAULT_EXCLUDE_PATTERNS } = options;
1597
+ const patterns = extensions.map((ext) => `**/*.${ext}`);
1598
+ const files = await glob(patterns, {
1599
+ cwd: directory,
1600
+ absolute: true,
1601
+ ignore: excludePatterns
1602
+ });
1603
+ return files;
1604
+ }
1605
+
1606
+ // src/MigrateCommand/presets/granite/migrateGranite.ts
1607
+ var transformers = [configTransformer, identifierReplacementsTransformer, packageImportsTransformer];
1608
+ var migrateGranite = async (cwd, config) => {
1609
+ assert2(isBedrockProject(cwd), "This is not a Bedrock project");
1610
+ let processedCount = 0;
1611
+ const files = await scanFiles(cwd);
1612
+ logger.log(`Found ${files.length} source files`);
1613
+ logger.log("Processing source files...");
1614
+ for (const file of files) {
1615
+ try {
1616
+ const content = await readFile(file);
1617
+ const newContent = await transform(content, {
1618
+ transformers,
1619
+ options: {
1620
+ fileName: file
1621
+ }
1622
+ });
1623
+ if (config.dryRun !== true && newContent !== content) {
1624
+ await writeFile(file, newContent);
1625
+ processedCount++;
1626
+ }
1627
+ } catch (error) {
1628
+ logger.error(`Failed to process file: ${file}`, error);
1629
+ }
1630
+ }
1631
+ if (processedCount > 0) {
1632
+ logger.success(`Processed ${processedCount} source files`);
1633
+ } else {
1634
+ logger.log("No source files needed processing");
1635
+ }
1636
+ await processPackageJson(cwd, config);
1637
+ await processGitignore(cwd, config);
1638
+ await processBedrockConfig(cwd, config);
1639
+ logger.log(dedent`
1640
+ Please check the following steps:
1641
+
1642
+ - Install dependencies
1643
+ - Run type checks
1644
+ - Run lint checks if a lint config exists
1645
+ - Verify test results if tests are present\n
1646
+ `);
1647
+ };
1648
+
1649
+ // src/MigrateCommand/presets/index.ts
1650
+ var MIGRATE_PRESETS = {
1651
+ granite: migrateGranite
1652
+ };
1653
+
1654
+ // src/MigrateCommand/MigrateCommand.ts
1655
+ var MigrateCommand = class extends Command3 {
1656
+ static paths = [[`migrate`]];
1657
+ static usage = Command3.Usage({
1658
+ category: "Migration",
1659
+ description: "Run migration",
1660
+ examples: [
1661
+ ["Run migration", "ait migrate <target>"],
1662
+ ["Check migration availability", "ait migrate <target> --dryRun"]
1663
+ ]
1664
+ });
1665
+ target = Option3.String({ required: true });
1666
+ dryRun = Option3.Boolean("--dry-run", { required: false });
1667
+ async execute() {
1668
+ try {
1669
+ const cwd = process.cwd();
1670
+ const config = {
1671
+ dryRun: this.dryRun
1672
+ };
1673
+ logger.log("Starting migration...");
1674
+ logger.log(`Working directory: ${cwd}`);
1675
+ const migrate = MIGRATE_PRESETS[this.target];
1676
+ if (migrate == null) {
1677
+ throw new Error(`Unknown target: ${this.target}`);
1678
+ }
1679
+ await migrate(cwd, config);
1680
+ logger.success("Migration completed successfully!");
1681
+ return 0;
1682
+ } catch (error) {
1683
+ logger.error(`Migration failed: ${error.message}`);
1684
+ return 1;
1685
+ }
1686
+ }
1687
+ };
1688
+
1157
1689
  // src/integrations/UploadSentrySourcemap/index.ts
1158
1690
  init_esm_shims();
1159
1691
 
1160
1692
  // src/integrations/UploadSentrySourcemap/UploadSentrySourcemap.ts
1161
1693
  init_esm_shims();
1162
- import * as fs7 from "fs/promises";
1694
+ import * as fs9 from "fs/promises";
1163
1695
  import * as p3 from "@clack/prompts";
1164
- import { Command as Command3, Option as Option3 } from "clipanion";
1696
+ import { Command as Command4, Option as Option4 } from "clipanion";
1165
1697
 
1166
1698
  // src/integrations/UploadSentrySourcemap/downloadArtifacts.ts
1167
1699
  init_esm_shims();
1168
1700
  var import_debug4 = __toESM(require_src(), 1);
1169
- import * as fs4 from "fs";
1701
+ import * as fs6 from "fs";
1170
1702
  import * as os from "os";
1171
1703
  import * as path3 from "path";
1172
1704
  import { pipeline } from "stream";
@@ -1197,34 +1729,34 @@ async function downloadArtifacts(options) {
1197
1729
  const tmpDir = await createTempDirectory();
1198
1730
  const tmpFile = `${deploymentId}.zip`;
1199
1731
  const tmpFilePath = path3.join(tmpDir.path, tmpFile);
1200
- const fileStream = fs4.createWriteStream(tmpFilePath);
1732
+ const fileStream = fs6.createWriteStream(tmpFilePath);
1201
1733
  await streamPipeline(response.body, fileStream);
1202
1734
  debug4("Artifacts downloaded", { tmpFilePath });
1203
1735
  return tmpFilePath;
1204
1736
  }
1205
1737
  function createTempDirectory() {
1206
1738
  const tempDir = path3.join(os.tmpdir(), "apps-in-toss", "sentry-integration");
1207
- fs4.mkdirSync(tempDir, { recursive: true });
1739
+ fs6.mkdirSync(tempDir, { recursive: true });
1208
1740
  debug4("Temp directory created", { tempDir });
1209
1741
  return {
1210
1742
  path: tempDir,
1211
1743
  cleanup: () => {
1212
- fs4.rmSync(tempDir, { recursive: true, force: true });
1744
+ fs6.rmSync(tempDir, { recursive: true, force: true });
1213
1745
  }
1214
1746
  };
1215
1747
  }
1216
1748
 
1217
1749
  // src/integrations/UploadSentrySourcemap/extractSentryDebugId.ts
1218
1750
  init_esm_shims();
1219
- import fs5 from "fs/promises";
1751
+ import fs7 from "fs/promises";
1220
1752
  async function extractSentryDebugId(bundlePath) {
1221
- const bundleContent = await fs5.readFile(bundlePath, "utf-8");
1753
+ const bundleContent = await fs7.readFile(bundlePath, "utf-8");
1222
1754
  return bundleContent.match(/SENTRY_DEBUG_ID=([\w-]+)/)?.[1];
1223
1755
  }
1224
1756
 
1225
1757
  // src/integrations/UploadSentrySourcemap/extractSources.ts
1226
1758
  init_esm_shims();
1227
- import * as fs6 from "fs";
1759
+ import * as fs8 from "fs";
1228
1760
  import * as path4 from "path";
1229
1761
  import { pipeline as pipeline2 } from "stream";
1230
1762
  import { promisify as promisify2 } from "util";
@@ -1246,12 +1778,12 @@ async function extractSources(zipPath) {
1246
1778
  hermesSourceMap: ""
1247
1779
  }
1248
1780
  };
1249
- await fs6.createReadStream(zipPath).pipe(unzipper.Parse()).on("entry", async (entry) => {
1781
+ await fs8.createReadStream(zipPath).pipe(unzipper.Parse()).on("entry", async (entry) => {
1250
1782
  const isRoot = !entry.path.includes("/");
1251
1783
  const fileName = path4.basename(entry.path);
1252
1784
  const outputPath = path4.join(path4.dirname(zipPath), fileName);
1253
1785
  if (isRoot) {
1254
- entry.pipe(fs6.createWriteStream(outputPath));
1786
+ entry.pipe(fs8.createWriteStream(outputPath));
1255
1787
  const platform = fileName.includes("android") ? "android" : "ios";
1256
1788
  if (fileName.endsWith(".js")) {
1257
1789
  sources[platform].packagerBundle = outputPath;
@@ -1279,7 +1811,7 @@ async function extractSources(zipPath) {
1279
1811
  }
1280
1812
  async function decompressGzip(gzFile) {
1281
1813
  const outfile = gzFile.replace(/\.gz$/g, "");
1282
- await pipe(fs6.createReadStream(gzFile), zlib.createGunzip(), fs6.createWriteStream(outfile));
1814
+ await pipe(fs8.createReadStream(gzFile), zlib.createGunzip(), fs8.createWriteStream(outfile));
1283
1815
  return outfile;
1284
1816
  }
1285
1817
 
@@ -1310,33 +1842,33 @@ function uploadSourcemap(bundlePath, sourcemapPath, options) {
1310
1842
  }
1311
1843
 
1312
1844
  // src/integrations/UploadSentrySourcemap/UploadSentrySourcemap.ts
1313
- var UploadSentrySourcemap = class extends Command3 {
1845
+ var UploadSentrySourcemap = class extends Command4 {
1314
1846
  static paths = [["sentry", "upload-sourcemap"]];
1315
- apiKey = Option3.String("--api-key", {
1847
+ apiKey = Option4.String("--api-key", {
1316
1848
  required: false,
1317
1849
  description: "\uC778\uC99D API \uD0A4"
1318
1850
  });
1319
- appName = Option3.String("--app-name", {
1851
+ appName = Option4.String("--app-name", {
1320
1852
  required: false,
1321
1853
  description: "\uC571 \uC774\uB984"
1322
1854
  });
1323
- deploymentId = Option3.String("--deployment-id", {
1855
+ deploymentId = Option4.String("--deployment-id", {
1324
1856
  required: false,
1325
1857
  description: "\uBC30\uD3EC ID"
1326
1858
  });
1327
- sentryAuthToken = Option3.String("--sentry-auth-token", {
1859
+ sentryAuthToken = Option4.String("--sentry-auth-token", {
1328
1860
  required: false,
1329
1861
  description: "Sentry \uC778\uC99D\uD0A4"
1330
1862
  });
1331
- sentryOrg = Option3.String("--sentry-org", {
1863
+ sentryOrg = Option4.String("--sentry-org", {
1332
1864
  required: false,
1333
1865
  description: "Sentry \uC870\uC9C1"
1334
1866
  });
1335
- sentryProject = Option3.String("--sentry-project", {
1867
+ sentryProject = Option4.String("--sentry-project", {
1336
1868
  required: false,
1337
1869
  description: "Sentry \uD504\uB85C\uC81D\uD2B8"
1338
1870
  });
1339
- baseUrl = Option3.String("--base-url", {
1871
+ baseUrl = Option4.String("--base-url", {
1340
1872
  description: "API Base URL"
1341
1873
  });
1342
1874
  async execute() {
@@ -1392,11 +1924,11 @@ var UploadSentrySourcemap = class extends Command3 {
1392
1924
  throw new Error("Sentry Debug ID\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
1393
1925
  }
1394
1926
  const mergedSourceMap = await mergeSourceMaps(
1395
- await fs7.readFile(sources.packagerSourceMap, "utf-8"),
1396
- await fs7.readFile(sources.hermesSourceMap, "utf-8")
1927
+ await fs9.readFile(sources.packagerSourceMap, "utf-8"),
1928
+ await fs9.readFile(sources.hermesSourceMap, "utf-8")
1397
1929
  );
1398
1930
  const injectedSourceMap = injectSentryDebugId(mergedSourceMap, debugId);
1399
- await fs7.writeFile(sources.hermesSourceMap, JSON.stringify(injectedSourceMap, null, 2), "utf-8");
1931
+ await fs9.writeFile(sources.hermesSourceMap, JSON.stringify(injectedSourceMap, null, 2), "utf-8");
1400
1932
  }
1401
1933
  async promptRequiredValue(type, message, validateMessage) {
1402
1934
  const result = await p3[type]({
@@ -1423,6 +1955,7 @@ function initialize() {
1423
1955
  });
1424
1956
  cli.register(DeployCommand);
1425
1957
  cli.register(InitCommand);
1958
+ cli.register(MigrateCommand);
1426
1959
  cli.register(UploadSentrySourcemap);
1427
1960
  cli.runExit(process.argv.slice(2));
1428
1961
  }