transone-cli 0.4.0 → 0.6.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.
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createProject,
6
6
  isTargetType,
7
7
  startDevServer
8
- } from "./index-m455xjw2.js";
8
+ } from "./index-pg5v7h1t.js";
9
9
  import"./index-k1qfvp0y.js";
10
10
  import"./index-yb2wsc7f.js";
11
11
 
package/dist/create.d.ts CHANGED
@@ -11,6 +11,6 @@ export interface CreateProjectResult {
11
11
  /** Published framework version referenced by generated projects. */
12
12
  export declare const TRANSONE_FRAMEWORK_VERSION = "0.4.0";
13
13
  /** Published CLI version referenced by generated projects. */
14
- export declare const TRANSONE_CLI_VERSION = "0.4.0";
14
+ export declare const TRANSONE_CLI_VERSION = "0.6.0";
15
15
  export declare const GITHUB_URL = "https://github.com/geektech-team/transone";
16
16
  export declare function createProject(options?: CreateProjectOptions): CreateProjectResult;
@@ -118,12 +118,16 @@ function pickAppConfig(app, target) {
118
118
  return;
119
119
  }
120
120
  if (isAppConfigMap(app)) {
121
- return isAppTargetType(target) ? app[target] : undefined;
121
+ return {
122
+ ...app.host !== undefined ? { host: app.host } : {},
123
+ ...isAppTargetType(target) ? app[target] : {}
124
+ };
122
125
  }
123
126
  return app;
124
127
  }
125
128
  async function resolveApp(root, outDirOverride, app, target, fallbackPages) {
126
129
  return {
130
+ ...app.host !== undefined ? { host: app.host } : {},
127
131
  appName: app.appName ?? "TransOne",
128
132
  bundleId: app.bundleId ?? "com.transone.app",
129
133
  outDir: resolve(root, outDirOverride ?? app.outDir ?? `dist/build/${target}`),
@@ -141,20 +145,33 @@ var MP_DEFAULT_OUT_DIRS = {
141
145
  "mp-bytedance": "dist/build/mp-bytedance",
142
146
  "mp-xiaohongshu": "dist/build/mp-xiaohongshu"
143
147
  };
144
- function isMpConfigMap(value) {
145
- return isRecord(value) && MP_TARGET_TYPES.some((platform) => (platform in value));
146
- }
147
148
  function pickMpConfig(mp, target) {
148
149
  if (mp === undefined) {
149
150
  return;
150
151
  }
151
- if (isMpConfigMap(mp)) {
152
- return isMpTargetType(target) ? mp[target] : undefined;
152
+ const common = Object.fromEntries(Object.entries(mp).filter(([key]) => !MP_TARGET_TYPES.includes(key)));
153
+ const platform = isMpTargetType(target) ? mp[target] : undefined;
154
+ return mergeMpRecords(common, { ...platform });
155
+ }
156
+ function mergeMpRecords(common, overrides) {
157
+ const merged = { ...common };
158
+ for (const [key, value] of Object.entries(overrides)) {
159
+ if (value === undefined)
160
+ continue;
161
+ const previous = Object.prototype.hasOwnProperty.call(common, key) ? common[key] : undefined;
162
+ const next = isRecord(previous) && isRecord(value) ? mergeMpRecords(previous, value) : value;
163
+ Object.defineProperty(merged, key, {
164
+ value: next,
165
+ enumerable: true,
166
+ configurable: true,
167
+ writable: true
168
+ });
153
169
  }
154
- return mp;
170
+ return merged;
155
171
  }
156
172
  function resolveMiniProgram(root, outDirOverride, mp, pages, target) {
157
173
  return {
174
+ ...mp.host !== undefined ? { host: mp.host } : {},
158
175
  appId: mp.appId ?? "touristappid",
159
176
  outDir: resolve(root, outDirOverride ?? mp.outDir ?? (MP_DEFAULT_OUT_DIRS[target] ?? "dist/build/mp-weixin")),
160
177
  navigationBarTitleText: mp.navigationBarTitleText ?? "TransOne",
@@ -303,6 +320,7 @@ function validateUserConfig(config) {
303
320
  }
304
321
  function validateAppConfig(app) {
305
322
  assertRecord(app, "Config app");
323
+ validateApiHost(app.host, "Config app.host");
306
324
  if (isAppConfigMap(app)) {
307
325
  const flatKeys = ["appName", "bundleId", "outDir", "minPlatformVersion", "publicDir", "pages"];
308
326
  if (flatKeys.some((key) => (key in app))) {
@@ -319,6 +337,7 @@ function validateAppConfig(app) {
319
337
  }
320
338
  function validateSingleAppConfig(app, label) {
321
339
  assertRecord(app, label);
340
+ validateApiHost(app.host, `${label}.host`);
322
341
  for (const key of ["appName", "bundleId", "outDir", "minPlatformVersion", "publicDir"]) {
323
342
  if (app[key] !== undefined && typeof app[key] !== "string") {
324
343
  throw new Error(`${label}.${key} must be a string`);
@@ -330,19 +349,16 @@ function validateSingleAppConfig(app, label) {
330
349
  }
331
350
  function validateMpConfig(mp) {
332
351
  assertRecord(mp, "Config mp");
333
- if (isMpConfigMap(mp)) {
334
- for (const platform of MP_TARGET_TYPES) {
335
- const platformConfig = mp[platform];
336
- if (platformConfig !== undefined) {
337
- validateMiniProgramConfig(platformConfig, `Config mp.${platform}`);
338
- }
352
+ validateMiniProgramConfig(mp, "Config mp");
353
+ for (const platform of MP_TARGET_TYPES) {
354
+ if (mp[platform] !== undefined) {
355
+ validateMiniProgramConfig(mp[platform], `Config mp.${platform}`);
339
356
  }
340
- return;
341
357
  }
342
- validateMiniProgramConfig(mp, "Config mp");
343
358
  }
344
359
  function validateMiniProgramConfig(mp, label) {
345
360
  assertRecord(mp, label);
361
+ validateApiHost(mp.host, `${label}.host`);
346
362
  for (const key of ["appId", "outDir", "navigationBarTitleText", "publicDir"]) {
347
363
  if (mp[key] !== undefined && typeof mp[key] !== "string") {
348
364
  throw new Error(`${label}.${key} must be a string`);
@@ -468,6 +484,18 @@ function assertRecord(value, name) {
468
484
  function isRecord(value) {
469
485
  return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
470
486
  }
487
+ function validateApiHost(host, label) {
488
+ if (host === undefined)
489
+ return;
490
+ if (typeof host !== "string")
491
+ throw new Error(`${label} must be a string`);
492
+ try {
493
+ const url = new URL(host);
494
+ if (url.protocol === "http:" || url.protocol === "https:")
495
+ return;
496
+ } catch {}
497
+ throw new Error(`${label} must use http or https`);
498
+ }
471
499
 
472
500
  // src/target/web-target.ts
473
501
  import { mkdir, rm, writeFile } from "fs/promises";
@@ -825,7 +853,7 @@ class MpTarget {
825
853
  if (!config.mp) {
826
854
  throw new Error("Mini program build requires config.mp\uFF08\u8BF7\u5728 transone.config.ts \u914D\u7F6E mp \u5B57\u6BB5\uFF0C" + "\u5982 appId / pages / outDir\uFF09");
827
855
  }
828
- const { buildMiniProgram } = await import("./build-mp-6j38wf4r.js");
856
+ const { buildMiniProgram } = await import("./build-mp-004pd4h0.js");
829
857
  return buildMiniProgram(config, this.dialect);
830
858
  }
831
859
  }
@@ -1011,6 +1039,10 @@ async function buildNativeApp(config, dialect) {
1011
1039
  throw nativeError(config.entry, "\u9996\u671F\u539F\u751F App \u53EA\u652F\u6301\u4E00\u4E2A\u9875\u9762");
1012
1040
  const screen = await analyzeNativeScreen(entries[0]);
1013
1041
  const files = dialect.generateProject(screen, config.app);
1042
+ if (config.app.host !== undefined) {
1043
+ files[`${dialect.resourceDirectory}/transone.config.json`] = `${JSON.stringify({ host: config.app.host }, null, 2)}
1044
+ `;
1045
+ }
1014
1046
  await rm2(config.app.outDir, { recursive: true, force: true });
1015
1047
  const assetsBuilt = [];
1016
1048
  for (const [relative3, content] of Object.entries(files).sort(([a], [b]) => a.localeCompare(b))) {
@@ -1336,7 +1368,7 @@ async function runTsc(root, tsconfig) {
1336
1368
  import { existsSync as existsSync4, mkdirSync, writeFileSync } from "fs";
1337
1369
  import { basename as basename2, join as join2 } from "path";
1338
1370
  var TRANSONE_FRAMEWORK_VERSION = "0.4.0";
1339
- var TRANSONE_CLI_VERSION = "0.4.0";
1371
+ var TRANSONE_CLI_VERSION = "0.6.0";
1340
1372
  var GITHUB_URL = "https://github.com/geektech-team/transone";
1341
1373
  function createProject(options = {}) {
1342
1374
  const root = options.root ?? process.cwd();
@@ -2169,5 +2201,5 @@ function buildFailureResponse() {
2169
2201
 
2170
2202
  export { TARGET_TYPES, isTargetType, MP_TARGET_TYPES, isMpTargetType, defineConfig, resolveConfig, WebTarget, MpTarget, mpWeixinTarget, mpAlipayTarget, mpBytedanceTarget, mpXiaohongshuTarget, TargetRegistry, targetRegistry, build, createProject, startDevServer };
2171
2203
 
2172
- //# debugId=4621705A1E76309564756E2164756E21
2173
- //# sourceMappingURL=index-m455xjw2.js.map
2204
+ //# debugId=635285A08AF2FAAB64756E2164756E21
2205
+ //# sourceMappingURL=index-pg5v7h1t.js.map