@wkgeo/cli 1.1.0 → 1.1.1

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.
@@ -19,7 +19,7 @@ import { maskPii, maskPiiDeep, formatTime } from '../format.mjs';
19
19
  import { openUrlForUser } from '../login.mjs';
20
20
 
21
21
  /** 表单后台函数(`wkgeo-plugin-contact-form`)认的来源;不给会被 `checkAdminOrigin` 403 */
22
- const FORM_ORIGIN = 'https://wkgeo.com';
22
+ const FORM_ORIGIN = 'https://wkgeo.cn';
23
23
 
24
24
  const SITE_FLAG = {
25
25
  site: { type: 'string', desc: '站点 ID(默认用 `wkgeo site use` 选中的站点,可用 WKONGAI_SITE 覆盖)' },
@@ -824,7 +824,7 @@ export const previewCommand = {
824
824
  },
825
825
  examples: ['wkgeo preview /about/', 'wkgeo preview news/2026/ --site <站点ID> --open'],
826
826
  notes: [
827
- '地址形如 `https://wkgeo.com/cms/preview/<站点ID>/<路径>`,走预览通道:**看的是草稿态**,不影响线上。',
827
+ '地址形如 `https://wkgeo.cn/cms/preview/<站点ID>/<路径>`,走预览通道:**看的是草稿态**,不影响线上。',
828
828
  '零后端调用:只拼字符串,不产生任何写操作。',
829
829
  '`--open` 用的是系统默认浏览器;CI / 非交互环境会自动跳过(不会卡住)。',
830
830
  ],
@@ -836,7 +836,7 @@ export const previewCommand = {
836
836
  rel = rel.replace(/^https?:\/\/[^/]+/i, '');
837
837
  rel = rel.replace(/^\/+/, '');
838
838
 
839
- const url = `https://wkgeo.com/cms/preview/${site.id}/${rel}`;
839
+ const url = `https://wkgeo.cn/cms/preview/${site.id}/${rel}`;
840
840
  const payload = { site_id: site.id, path: `/${rel}`, url };
841
841
 
842
842
  if (!out.json) {
@@ -34,6 +34,7 @@
34
34
  import { CliError, UsageError } from '../errors.mjs';
35
35
  import { formatTime } from '../format.mjs';
36
36
  import { readSiteState } from '../site-state.mjs';
37
+ import { runSiteCreate } from '../site-create.mjs';
37
38
  import { rememberSite } from './cms.mjs';
38
39
 
39
40
  /**
@@ -745,141 +746,36 @@ export const sitesGetCommand = {
745
746
 
746
747
  /* ------------------------------------------------------------------ 建站 */
747
748
 
748
- /** `--channel` 取值:`auto` = 先 CMS 通道、明确不支持才回退平台 */
749
- const CREATE_CHANNELS = ['auto', 'platform', 'cms'];
750
-
751
- /** CMS 建站入参(与交互引导同一套口径:`template` 只传内置模板名,uuid 不传) */
752
- function cmsCreatePayload({ name, template }) {
753
- const payload = { name };
754
- if (template && !looksLikeUuid(template)) payload.template = template;
755
- return payload;
756
- }
757
-
758
749
  export const sitesCreateCommand = {
759
750
  name: 'sites create',
760
- summary: '建一个属于当前账号的站点(默认先走 CMS 通道;返回站点 id 与短域)',
761
- usage: 'wkgeo sites create --name <名称> [--template <模板ID>] [--domain <域名>] [--channel auto|platform|cms]',
751
+ summary: '建站原语:建站 → 可选装模板市场的模板 → 可选发布(返回 siteId / 短域 / url)',
752
+ usage:
753
+ 'wkgeo sites create --name <站点名> [--lang zh-CN|en] [--template <模板key>] [--publish] [--dry-run] [--region domestic|overseas|global] [--json]',
762
754
  flags: {
763
755
  name: { type: 'string', required: true, desc: '站点名称' },
764
- template: { type: 'string', desc: '模板 ID(uuid)或内置模板名' },
765
- domain: { type: 'string', desc: '主域名(可选;**只登记到 site.domains,不触发解析 / 证书**;解析要自己去域名商加)' },
766
- channel: { type: 'string', desc: '建站通道:auto(默认,先 CMS 后回退平台)/ platform(只建平台站)/ cms(只走 CMS,CMS 站点一起建)' },
756
+ lang: { type: 'string', desc: '站点语言:zh-CN(默认)/ en' },
757
+ template: { type: 'string', desc: '模板市场里的模板 key(可选;不传就是空站)' },
758
+ publish: { type: 'boolean', desc: '建完立即发布,并实测短域首页(HTTP 码 / 字节 / 标题)' },
759
+ 'dry-run': { type: 'boolean', desc: '只打印计划:不建站、不写库、不写 OSS' },
760
+ region: { type: 'string', desc: '区域/池位:domestic(默认,cn1)/ overseas(intl)/ global;国内池满了换 overseas' },
767
761
  },
768
762
  examples: [
769
- 'wkgeo sites create --name 我的站',
770
- 'wkgeo sites create --name 我的站 --channel platform',
771
- 'wkgeo sites create --name 我的站 --domain www.example.com --channel platform',
763
+ 'wkgeo sites create --name 我的站 --lang zh-CN',
764
+ 'wkgeo sites create --name 我的站 --template qbk-enterprise --publish',
765
+ 'wkgeo sites create --name 我的站 --lang en --template qbk-enterprise --publish --json',
766
+ 'wkgeo sites create --name 我的站 --template qbk-enterprise --dry-run',
767
+ 'wkgeo sites create --name 我的站 --region overseas --publish',
772
768
  ],
773
769
  notes: [
774
- '`--channel auto`(默认):先打 CMS 通道 `createCmsSite`(CMS 站点会一起建出来);服务端回「未知动作 / 400」才回退平台 `createSite`,网络 / 401 / 429 / 5xx 照常报错,不伪装成成功。',
775
- '`--domain` **只登记域名**:写的是站点记录里的 `site.domains`,**不写短域 KV、不碰 DNS、不申请证书**。真正对外访问还要在域名商加解析并走域名开通流程(`wkgeo domain status` 看进度)。',
776
- '`--domain` 与 `--channel cms` 不能一起用(CMS 建站不登记域名);`--channel auto` 遇到 `--domain` 会直接走平台通道,免得域名被静默丢掉。',
770
+ '**只做平台原语**:建站(平台通道 `createSite`:分配池位 + 短域 + 写短域 KV)→ 可选装**模板市场已有模板**(`templateMarketList` → `templateInstall` → `templateActivate`)→ 可选发布(CMS 发布任务)。',
771
+ '`--template` 只认**模板市场里已有的 key**;填错会直接报「模板市场里没有 key = …」并列出市场现有 key。不传就是空站,之后可以在 CMS 后台模板页安装/启用。',
772
+ '`--publish` 建完就发,并**实测短域首页**(HTTP 码 / 字节数 / 标题都进 `--json`)。不加 `--publish` 时站点内容还没发到短域。',
773
+ '`--dry-run` 只打印计划:**不建站、不写库、不写 OSS**(可以放心在正式环境跑)。',
774
+ '池位满(409「该区域名额已满」)时加 `--region overseas` 或 `--region global`。',
775
+ '**来源分析不在 CLI**:抓网址 / 解析文档 / 多来源合成都不归本命令,见 `docs/规范-建站三来源-20261031.md`(task-73 产出,task-178 合并为唯一一份)。',
777
776
  ],
778
777
  async run(ctx) {
779
- const { out, flags } = ctx;
780
- const requested = String(flags.channel || 'auto').toLowerCase();
781
- if (!CREATE_CHANNELS.includes(requested)) {
782
- throw new UsageError(`--channel 只能是 ${CREATE_CHANNELS.join(' / ')},收到:${flags.channel}`, {
783
- hint: 'auto=先 CMS 后回退平台(默认);platform=只走平台 createSite;cms=只走 CMS cmsCreateSite',
784
- });
785
- }
786
- if (requested === 'cms' && flags.domain) {
787
- throw new UsageError('--channel cms 不能配 --domain(CMS 建站不登记域名)', {
788
- hint: '去掉 --domain,或改成 `--channel platform` 让域名一起登记(只写库,不触发解析/证书)。',
789
- });
790
- }
791
- /** 带 `--domain` 时 auto 直接走平台:CMS 通道没有域名登记能力,走它会把 --domain 静默丢掉 */
792
- const wantCms = requested === 'cms' || (requested === 'auto' && !flags.domain);
793
-
794
- let channel = null;
795
- let res = null;
796
- let cmsSiteCreated = false;
797
- let cmsError = null;
798
- let cmsWarnings = [];
799
- if (wantCms) {
800
- try {
801
- /** `noSite:true`:新站点还不存在,绝不能带本地残留的 `x-cms-site`(同 createSiteByGuide) */
802
- const r = await ctx.cmsCall('createCmsSite', cmsCreatePayload({ name: flags.name, template: flags.template }), { noSite: true });
803
- res = (r && r.site) || r;
804
- channel = 'cms';
805
- cmsSiteCreated = true;
806
- if (r && Array.isArray(r.warnings)) cmsWarnings = r.warnings.map(String).filter(Boolean);
807
- } catch (e) {
808
- /** 明确选了 cms 就不回退;auto 只在「服务端还不认识这个动作」时回退 */
809
- if (requested === 'cms' || !isMissingCmsAction(e)) throw e;
810
- cmsError = { kind: (e && e.kind) || 'error', message: (e && e.message) || String(e) };
811
- }
812
- }
813
- if (!channel) {
814
- const payload = { name: flags.name };
815
- if (flags.template) payload.template_id = flags.template;
816
- if (flags.domain) payload.domains = [flags.domain];
817
- res = await ctx.callData('createSite', payload);
818
- channel = 'platform';
819
- }
820
-
821
- const site = normalizeSite(res, channel === 'cms' ? 'cms' : 'platform');
822
- if (!site.id) {
823
- throw new CliError('建站接口没有返回站点 id', {
824
- kind: 'bad_response',
825
- hint: '服务端可能刚升级 / 部署不完整;请稍后用 `wkgeo sites list` 确认,或到网页后台查看。',
826
- });
827
- }
828
-
829
- /** 复核归属:owner 必须能对上当前登录用户;对不上/拿不到都如实说(A3:拿不到 ≠ 不一致) */
830
- let creds = null;
831
- try {
832
- creds = ctx.requireAuth();
833
- } catch {
834
- /* 拿不到也继续,只影响复核 */
835
- }
836
- const meId = creds && creds.account ? String(creds.account.sub || '') : '';
837
- const ownership = checkOwnership(site, meId);
838
-
839
- const data = {
840
- site,
841
- /** 实际走的通道(A9:`--json` 里必须能看出走的是哪条) */
842
- channel,
843
- channel_requested: requested,
844
- cms_site_created: cmsSiteCreated,
845
- cms_error: cmsError,
846
- cms_warnings: cmsWarnings,
847
- short_domain: shortDomainOf(site),
848
- domain_requested: flags.domain ? String(flags.domain) : null,
849
- /**
850
- * `--domain` 只写 `site.domains`(A10),不触发解析/证书。
851
- * `null` = 服务端没回显 domains,无法确认(不是失败)。
852
- */
853
- domain_registered: flags.domain ? Boolean(Array.isArray(site.domains) && site.domains.length) : null,
854
- owner_matches_current_user: meId ? ownership.ok : null,
855
- current_user_id: meId || null,
856
- };
857
-
858
- if (!out.json) {
859
- out.ok(`站点已创建:${site.name || site.id}`);
860
- out.line(` 站点 ID:${site.id}`);
861
- out.line(` 通道:${channel === 'cms' ? 'CMS(cmsCreateSite,CMS 站点已同时创建)' : '平台(createSite)'}`);
862
- if (site.status) out.line(` 状态:${site.status}${site.provision_state ? ` · 开通:${site.provision_state}` : ''}`);
863
- if (meId) {
864
- out.line(
865
- ` 归属用户:${site.owner_user_id || '(未知)'}${
866
- ownership.ok === true ? '(= 当前账号 ✔)' : ownership.ok === false ? ` ⚠️ 与当前账号 ${meId} 不一致,请核查` : '(无法核对)'
867
- }`,
868
- );
869
- }
870
- printShortDomain(out, site, { channel });
871
- if (flags.domain) {
872
- out.line(` 域名:${flags.domain}(已提交登记到站点记录;**不触发解析 / 证书**)`);
873
- out.info(' → 还要去域名商加解析:`wkgeo domain dns` 看要加哪几条;开通进度:`wkgeo domain status`');
874
- }
875
- for (const warn of cmsWarnings) out.info(` ⚠️ ${warn}`);
876
- } else {
877
- /** JSON 模式:短域本身在 `short_domain` 里;只有 KV 没写进去才走 stderr 告警(A2) */
878
- printShortDomain(out, site, { channel });
879
- }
880
- if (ownership.ok === false) {
881
- out.warn(`站点归属(${site.owner_user_id}) ≠ 当前账号(${meId}),请核查`);
882
- }
778
+ const data = await runSiteCreate(ctx, ctx.flags);
883
779
  ctx.done(data);
884
780
  return data;
885
781
  },