@tanqory/partner-cli 0.0.0-stage → 0.1.0-alpha.2

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/bin/tanqory-partner.mjs +10 -0
  3. package/config/mirror-allowlist.json +17 -0
  4. package/config/theme-licences.json +108 -0
  5. package/config/third-party-toolchains.json +45 -0
  6. package/lib/api.mjs +109 -0
  7. package/lib/auth.mjs +211 -0
  8. package/lib/check.mjs +66 -0
  9. package/lib/cli.mjs +217 -0
  10. package/lib/mcp.mjs +177 -0
  11. package/lib/ops.mjs +179 -0
  12. package/lib/theme.mjs +121 -0
  13. package/lib/vendor/partner-checks.cjs +2420 -0
  14. package/package.json +59 -4
  15. package/starter/LICENSE +18 -0
  16. package/starter/README.md +44 -0
  17. package/starter/config/settings.json +5 -0
  18. package/starter/gitignore +3 -0
  19. package/starter/locales/en.json +22 -0
  20. package/starter/locales/en.schema.json +69 -0
  21. package/starter/locales/th.json +22 -0
  22. package/starter/locales/th.schema.json +69 -0
  23. package/starter/package.json +29 -0
  24. package/starter/regions/footer.json +35 -0
  25. package/starter/regions/header.json +13 -0
  26. package/starter/scripts/build.mjs +211 -0
  27. package/starter/scripts/probe.ts +4 -0
  28. package/starter/src/bundle.ts +15 -0
  29. package/starter/src/components/parts.tsx +32 -0
  30. package/starter/src/entry.client.tsx +6 -0
  31. package/starter/src/entry.server.tsx +13 -0
  32. package/starter/src/sections/chrome.tsx +132 -0
  33. package/starter/src/sections/commerce.tsx +242 -0
  34. package/starter/src/sections/content.tsx +115 -0
  35. package/starter/src/sections/editorial.tsx +232 -0
  36. package/starter/src/settings.ts +12 -0
  37. package/starter/src/styles/theme.css +241 -0
  38. package/starter/src/templates.ts +14 -0
  39. package/starter/src/theme.tsx +86 -0
  40. package/starter/templates/404.json +14 -0
  41. package/starter/templates/account.json +14 -0
  42. package/starter/templates/article.json +14 -0
  43. package/starter/templates/blog.json +14 -0
  44. package/starter/templates/cart.json +14 -0
  45. package/starter/templates/collection.json +14 -0
  46. package/starter/templates/index.json +116 -0
  47. package/starter/templates/page.contact.json +22 -0
  48. package/starter/templates/page.json +14 -0
  49. package/starter/templates/product.json +18 -0
  50. package/starter/templates/search.json +14 -0
  51. package/starter/tsconfig.json +17 -0
  52. package/starter/vite.client.config.ts +17 -0
  53. package/starter/vite.probe.config.ts +16 -0
  54. package/starter/vite.server.config.ts +32 -0
  55. package/README.md +0 -3
package/lib/theme.mjs ADDED
@@ -0,0 +1,121 @@
1
+ // A partner theme folder on this machine: its files, its build, its package (.tgz) and its manifest.
2
+ //
3
+ // The package is what a partner uploads (docs/online-store/PARTNER_THEMES.md §5.1): the starter layout (no root
4
+ // manifest.json; the platform runs the theme's own build, `package.json` `tanqory.build`, in its sandbox), and the
5
+ // manifest the build writes sent beside it. The file set follows themes/nova-v3/scripts/partner/pack.mjs:
6
+ // - the files git tracks here, plus untracked ones git does not ignore; outside a git checkout the same set from a
7
+ // walk that applies the folder's .gitignore;
8
+ // - never node_modules, dist or .git;
9
+ // - no lockfile (package-lock.json, pnpm-lock.yaml, yarn.lock, bun.lockb): the builder never installs from one (it
10
+ // uses its own toolchain). (An uploaded lockfile is read for the SBOM only; since DECISIONS row 185 the licences
11
+ // check counts only what it ships, so its developer tools no longer fail it.)
12
+ import { execFileSync, spawnSync } from 'node:child_process'
13
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync, copyFileSync } from 'node:fs'
14
+ import { dirname, join, resolve } from 'node:path'
15
+ import * as tar from 'tar'
16
+
17
+ export const LOCKFILES = new Set(['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lockb', 'npm-shrinkwrap.json'])
18
+ const NEVER = new Set(['node_modules', 'dist', '.git'])
19
+
20
+ export class ThemeError extends Error {}
21
+
22
+ export function readPackage(dir) {
23
+ const p = join(dir, 'package.json')
24
+ if (!existsSync(p)) throw new ThemeError(`${dir} has no package.json. Run this in a theme folder, or make one with: tanqory-partner theme init <name>`)
25
+ try {
26
+ return JSON.parse(readFileSync(p, 'utf8'))
27
+ } catch (e) {
28
+ throw new ThemeError(`package.json is not valid JSON: ${e.message}`)
29
+ }
30
+ }
31
+
32
+ /** One .gitignore line as a test on a path relative to the theme (the subset of gitignore(5) themes use). */
33
+ function ignoreRule(raw) {
34
+ let p = raw.replace(/\s+$/, '')
35
+ if (!p || p.startsWith('#')) return null
36
+ const negate = p.startsWith('!')
37
+ if (negate) p = p.slice(1)
38
+ const dirOnly = p.endsWith('/')
39
+ if (dirOnly) p = p.slice(0, -1)
40
+ const anchored = p.includes('/')
41
+ if (p.startsWith('/')) p = p.slice(1)
42
+ const re = new RegExp(`^${p.split('*').map((x) => x.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('[^/]*')}$`)
43
+ return { negate, test: (rel, isDir) => (!dirOnly || isDir) && re.test(anchored ? rel : rel.slice(rel.lastIndexOf('/') + 1)) }
44
+ }
45
+
46
+ /** The theme's source files, relative to `dir`, sorted. */
47
+ export function themeFiles(dir) {
48
+ let paths
49
+ try {
50
+ const top = execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
51
+ if (!top) throw new Error('no git')
52
+ paths = execFileSync('git', ['ls-files', '-co', '--exclude-standard', '-z', '.'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).split('\0').filter(Boolean)
53
+ } catch {
54
+ const rules = existsSync(join(dir, '.gitignore')) ? readFileSync(join(dir, '.gitignore'), 'utf8').split('\n').map(ignoreRule).filter(Boolean) : []
55
+ const ignored = (rel, isDir) => rules.reduce((out, r) => (r.test(rel, isDir) ? !r.negate : out), false)
56
+ paths = []
57
+ const walk = (rel) => {
58
+ for (const name of readdirSync(join(dir, rel)).sort()) {
59
+ const p = rel ? `${rel}/${name}` : name
60
+ const isDir = statSync(join(dir, p)).isDirectory()
61
+ if (NEVER.has(name) || ignored(p, isDir)) continue
62
+ if (isDir) walk(p)
63
+ else paths.push(p)
64
+ }
65
+ }
66
+ walk('')
67
+ }
68
+ return paths
69
+ .filter((p) => !p.split('/').some((seg) => NEVER.has(seg)) && !LOCKFILES.has(p))
70
+ .filter((p) => existsSync(join(dir, p)) && statSync(join(dir, p)).isFile())
71
+ .sort()
72
+ }
73
+
74
+ /** Run the theme's own build (`package.json` `tanqory.build`, default scripts/build.mjs) → its out dir (default dist/abi). */
75
+ export function buildTheme(dir, { quiet = false } = {}) {
76
+ const pkg = readPackage(dir)
77
+ const script = pkg.tanqory?.build ?? 'scripts/build.mjs'
78
+ const out = resolve(dir, pkg.tanqory?.out ?? 'dist/abi')
79
+ if (!existsSync(join(dir, script))) throw new ThemeError(`The build file ${script} (package.json tanqory.build) does not exist.`)
80
+ if (!existsSync(join(dir, 'node_modules'))) throw new ThemeError('node_modules is missing. Run npm install in the theme folder first.')
81
+ const r = spawnSync(process.execPath, [script], { cwd: dir, stdio: quiet ? ['ignore', 'pipe', 'pipe'] : 'inherit', encoding: 'utf8' })
82
+ if (r.status !== 0) {
83
+ const tail = quiet ? `\n${`${r.stdout ?? ''}${r.stderr ?? ''}`.trim().split('\n').slice(-20).join('\n')}` : ''
84
+ throw new ThemeError(`The theme build failed (node ${script}, exit ${r.status}).${tail}`)
85
+ }
86
+ if (!existsSync(join(out, 'manifest.json'))) throw new ThemeError(`The build wrote no manifest.json in ${out}.`)
87
+ return { out, manifestPath: join(out, 'manifest.json') }
88
+ }
89
+
90
+ /** The theme's source as the .tgz a partner uploads (bytes) and the file list in it. */
91
+ export async function packSource(dir) {
92
+ const files = themeFiles(dir)
93
+ if (!files.includes('package.json')) throw new ThemeError('package.json is not in the theme\'s file set (is it ignored?).')
94
+ const chunks = []
95
+ // portable: no uid, gid, user or group names; a fixed mtime so the same files make the same bytes
96
+ const stream = tar.c({ gzip: { level: 9 }, cwd: dir, portable: true, mtime: new Date('2026-01-01T00:00:00Z'), noDirRecurse: true }, files)
97
+ for await (const c of stream) chunks.push(c)
98
+ return { bytes: Buffer.concat(chunks), files }
99
+ }
100
+
101
+ /** `theme package`: dist/partner/<name>-<version>.tgz and manifest.json beside it. */
102
+ export async function packageTheme(dir, { outDir, quiet = false } = {}) {
103
+ const pkg = readPackage(dir)
104
+ const { manifestPath, out } = buildTheme(dir, { quiet })
105
+ const { bytes, files } = await packSource(dir)
106
+ const target = resolve(outDir ?? join(dir, 'dist', 'partner'))
107
+ mkdirSync(target, { recursive: true })
108
+ const base = `${String(pkg.name ?? 'theme').replace(/^@[^/]+\//, '').replace(/[^A-Za-z0-9._-]+/g, '-')}-${pkg.version ?? '0.0.0'}`
109
+ const tgz = join(target, `${base}.tgz`)
110
+ writeFileSync(tgz, bytes)
111
+ const manifest = join(target, `${base}.manifest.json`)
112
+ copyFileSync(manifestPath, manifest)
113
+ return { tgz, manifest, files, bytes: bytes.length, out }
114
+ }
115
+
116
+ export function writeIfAbsent(path, bytes) {
117
+ if (existsSync(path)) return false
118
+ mkdirSync(dirname(path), { recursive: true })
119
+ writeFileSync(path, bytes)
120
+ return true
121
+ }