create-sparkling-app 2.1.0-rc.24 → 2.1.0-rc.26

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.
@@ -146,7 +146,7 @@ async function copyTemplateWithVariables({ checkEmpty = true, from, isMergePacka
146
146
  throw new UserCancelledError();
147
147
  }
148
148
  }
149
- const allSkipFiles = new Set(['dist', 'node_modules', 'Pods', '.gradle', ...skipFiles]);
149
+ const allSkipFiles = new Set(['dist', 'node_modules', 'Pods', '.gradle', '.sparkling', ...skipFiles]);
150
150
  node_fs_1.default.mkdirSync(to, { recursive: true });
151
151
  for (const file of node_fs_1.default.readdirSync(from)) {
152
152
  if (allSkipFiles.has(file)) {
@@ -11,8 +11,7 @@ exports.applyPackageNamespace = applyPackageNamespace;
11
11
  // LICENSE file in the root directory of this source tree.
12
12
  const node_fs_1 = __importDefault(require("node:fs"));
13
13
  const node_path_1 = __importDefault(require("node:path"));
14
- const DEFAULT_ANDROID_NAMESPACE = 'com.tiktok.sparkling.go';
15
- const DEFAULT_ANDROID_TEST_PACKAGE = 'com.tiktok.sparkling.app';
14
+ const DEFAULT_ANDROID_NAMESPACE = 'com.example.sparkling.go';
16
15
  const DEFAULT_IOS_BUNDLE_ID = 'com.sparkling.app.SparklingGo';
17
16
  const DEFAULT_IOS_TEST_BUNDLE_ID = 'com.sparkling.app.SparklingGoTests';
18
17
  const DEFAULT_IOS_UITEST_BUNDLE_ID = 'com.sparkling.app.SparklingGoUITests';
@@ -40,32 +39,56 @@ function replaceInTree(targetPath, replacements) {
40
39
  }
41
40
  return;
42
41
  }
42
+ // Apply longer keys first so a shorter key that is a prefix of a longer one
43
+ // (e.g. main bundle id vs `${bundleId}Tests`) does not mangle the longer one.
44
+ const ordered = Object.entries(replacements)
45
+ .filter(([from]) => from)
46
+ .sort(([a], [b]) => b.length - a.length);
43
47
  let content = node_fs_1.default.readFileSync(targetPath, 'utf8');
44
48
  let updated = content;
45
- for (const [from, to] of Object.entries(replacements)) {
46
- if (!from)
47
- continue;
49
+ for (const [from, to] of ordered) {
48
50
  updated = updated.split(from).join(to);
49
51
  }
50
52
  if (updated !== content) {
51
53
  node_fs_1.default.writeFileSync(targetPath, updated, 'utf8');
52
54
  }
53
55
  }
56
+ function removeEmptyParentDirs(startDir, stopDir) {
57
+ let current = startDir;
58
+ const stop = node_path_1.default.resolve(stopDir);
59
+ while (node_path_1.default.resolve(current) !== stop) {
60
+ if (!node_fs_1.default.existsSync(current)) {
61
+ current = node_path_1.default.dirname(current);
62
+ continue;
63
+ }
64
+ const stat = node_fs_1.default.statSync(current);
65
+ if (!stat.isDirectory()) {
66
+ return;
67
+ }
68
+ if (node_fs_1.default.readdirSync(current).length > 0) {
69
+ return;
70
+ }
71
+ node_fs_1.default.rmdirSync(current);
72
+ current = node_path_1.default.dirname(current);
73
+ }
74
+ }
54
75
  function moveAndroidPackageDirs(appDir, oldNamespace, newNamespace) {
76
+ if (oldNamespace === newNamespace) {
77
+ return;
78
+ }
55
79
  const oldParts = oldNamespace.split('.');
56
80
  const newParts = newNamespace.split('.');
57
81
  const srcRoots = ['main', 'androidTest', 'test'];
58
82
  for (const root of srcRoots) {
59
- const oldPath = node_path_1.default.join(appDir, 'src', root, 'java', ...oldParts);
60
- const newPath = node_path_1.default.join(appDir, 'src', root, 'java', ...newParts);
61
- if (!node_fs_1.default.existsSync(oldPath)) {
62
- continue;
63
- }
64
- if (oldPath === newPath) {
83
+ const javaRoot = node_path_1.default.join(appDir, 'src', root, 'java');
84
+ const oldPath = node_path_1.default.join(javaRoot, ...oldParts);
85
+ const newPath = node_path_1.default.join(javaRoot, ...newParts);
86
+ if (!node_fs_1.default.existsSync(oldPath) || oldPath === newPath) {
65
87
  continue;
66
88
  }
67
89
  node_fs_1.default.mkdirSync(node_path_1.default.dirname(newPath), { recursive: true });
68
90
  node_fs_1.default.renameSync(oldPath, newPath);
91
+ removeEmptyParentDirs(node_path_1.default.dirname(oldPath), javaRoot);
69
92
  }
70
93
  }
71
94
  function applyAndroidNamespace(projectDir, namespace) {
@@ -75,8 +98,10 @@ function applyAndroidNamespace(projectDir, namespace) {
75
98
  }
76
99
  const replacements = {
77
100
  [DEFAULT_ANDROID_NAMESPACE]: namespace,
78
- [DEFAULT_ANDROID_TEST_PACKAGE]: namespace,
79
101
  };
102
+ // `replaceInTree` walks the entire `app` source set (main, test, androidTest,
103
+ // gradle/manifest files), so unit-test sources that import or declare the
104
+ // default package get rewritten alongside production code.
80
105
  replaceInTree(appDir, replacements);
81
106
  moveAndroidPackageDirs(appDir, DEFAULT_ANDROID_NAMESPACE, namespace);
82
107
  }
@@ -85,6 +110,9 @@ function applyIosBundleIdentifiers(projectDir, namespace) {
85
110
  if (!node_fs_1.default.existsSync(pbxproj)) {
86
111
  return;
87
112
  }
113
+ // Order matters: longer / more specific test bundle ids must be replaced
114
+ // before the shorter main bundle id (which is their prefix). `replaceInTree`
115
+ // sorts replacements by key length descending, so we just declare them all here.
88
116
  const replacements = {
89
117
  [DEFAULT_IOS_BUNDLE_ID]: namespace,
90
118
  [DEFAULT_IOS_TEST_BUNDLE_ID]: `${namespace}.tests`,
@@ -215,6 +215,7 @@ async function createSparklingApp(options) {
215
215
  ? packageName.split("/").pop()
216
216
  : packageName,
217
217
  appNameCamel: toPascalCase(packageName),
218
+ packageNamespace,
218
219
  version: version ?? "0.0.0",
219
220
  enableESLint: enableESLintPrettier.toString(),
220
221
  enablePrettier: enableESLintPrettier.toString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sparkling-app",
3
- "version": "2.1.0-rc.24",
3
+ "version": "2.1.0-rc.26",
4
4
  "homepage": "https://tiktok.github.io/sparkling/",
5
5
  "repository": {
6
6
  "type": "git",