pakstr 0.26.0 → 0.27.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.
@@ -7,6 +7,7 @@ exports.initCommand = initCommand;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const crypto_1 = require("crypto");
10
+ const promises_1 = require("readline/promises");
10
11
  const pakstrConfig_1 = require("../core/pakstrConfig");
11
12
  const nostr_1 = require("../core/nostr");
12
13
  /**
@@ -29,8 +30,9 @@ async function initCommand(options = {}) {
29
30
  throw new Error(`${configPath} already exists. Use --force to overwrite, or remove it first.`);
30
31
  }
31
32
  const pkg = readPackageJson();
32
- const { appId, sanitized: appIdSanitized } = inferAppId(pkg);
33
- const appName = inferAppName(pkg) ?? appNameFromAppId(appId);
33
+ const { appId: inferredAppId, sanitized: appIdSanitized } = inferAppId(pkg);
34
+ const { appId, overridden: appIdOverridden } = await confirmAppId(inferredAppId, options);
35
+ const appName = inferAppName(pkg) ?? appNameFromAppId(inferredAppId);
34
36
  const versionName = (pkg && typeof pkg.version === "string" ? pkg.version : "1.0.0");
35
37
  const versionCode = 1;
36
38
  const web = inferWebDir();
@@ -46,7 +48,7 @@ async function initCommand(options = {}) {
46
48
  });
47
49
  fs_1.default.writeFileSync(configPath, yaml, "utf8");
48
50
  console.log(`✅ Wrote ${configPath}`);
49
- if (appIdSanitized) {
51
+ if (appIdSanitized && !appIdOverridden) {
50
52
  console.log(`⚠️ Your package.json name contains characters that aren't valid in an Android package`);
51
53
  console.log(` name (e.g. hyphens). pakstr sanitized it to appId "${appId}". Edit`);
52
54
  console.log(` ${pakstrConfig_1.PAKSTR_CONFIG_FILENAME} if you'd prefer a different value.`);
@@ -235,6 +237,40 @@ function escapeYamlScalar(value) {
235
237
  }
236
238
  return value;
237
239
  }
240
+ async function confirmAppId(inferredAppId, options) {
241
+ const prompt = options.promptAppId ?? (isInteractive() ? promptForAppId : null);
242
+ if (!prompt)
243
+ return { appId: inferredAppId, overridden: false };
244
+ const response = await prompt(inferredAppId);
245
+ if (response === "")
246
+ return { appId: inferredAppId, overridden: false };
247
+ validateAppId(response);
248
+ return { appId: response, overridden: response !== inferredAppId };
249
+ }
250
+ function isInteractive() {
251
+ return process.stdin.isTTY === true && process.stdout.isTTY === true;
252
+ }
253
+ async function promptForAppId(defaultAppId) {
254
+ const readline = (0, promises_1.createInterface)({ input: process.stdin, output: process.stdout });
255
+ try {
256
+ return await readline.question(`App ID [${defaultAppId}]: `);
257
+ }
258
+ finally {
259
+ readline.close();
260
+ }
261
+ }
262
+ function validateAppId(appId) {
263
+ if (appId !== appId.trim()) {
264
+ throw new Error("App ID must not have leading or trailing whitespace");
265
+ }
266
+ if (Buffer.byteLength(appId, "utf8") > 255) {
267
+ throw new Error("App ID must be ≤ 255 UTF-8 bytes");
268
+ }
269
+ if (!pakstrConfig_1.APP_ID_PATTERN.test(appId)) {
270
+ throw new Error("App ID must be a valid Android package name: dot-separated segments of" +
271
+ ` lower-case letters, digits, and underscores (no hyphens). Got: "${appId}"`);
272
+ }
273
+ }
238
274
  function readPackageJson() {
239
275
  const p = path_1.default.join(process.cwd(), "package.json");
240
276
  if (!fs_1.default.existsSync(p))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pakstr",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "CLI for packaging Nostr web apps into Android APKs",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",