@xrystal/core 3.28.3 → 3.37.3
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/README.md +2331 -21
- package/package.json +66 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +136 -0
- package/x/bin/commands/doctor.mjs +149 -0
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +126 -0
- package/x/bin/commands/release.mjs +66 -0
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +57 -0
- package/x/bin/constants/index.mjs +6 -0
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +80 -0
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/cli-identity.mjs +17 -0
- package/x/bin/helpers/create-target.mjs +35 -0
- package/{bin → x/bin}/helpers/index.mjs +44 -1
- package/x/bin/helpers/project-artifacts.mjs +140 -0
- package/x/bin/helpers/project-root.mjs +70 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +67 -0
- package/x/bin/helpers/tmp-layout.mjs +281 -0
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +80 -0
- package/x/bin/paths.mjs +14 -0
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
- package/x/bin/scripts/release-prepare.mjs +56 -0
- package/x/bin/scripts/tag.mjs +17 -0
- package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
- package/x/bin/scripts/verify-npm-pack.mjs +45 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +370 -0
- package/x/dist/index.d.ts +3 -0
- package/x/dist/index.js +1 -0
- package/{source → x/dist}/loader/clients/index.d.ts +2 -1
- package/x/dist/loader/clients/index.js +1 -0
- package/{source → x/dist}/loader/configs/index.d.ts +3 -2
- package/x/dist/loader/configs/index.js +1 -0
- package/x/dist/loader/controller/index.d.ts +69 -0
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.d.ts +39 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/{source → x/dist}/loader/events/index.d.ts +1 -1
- package/x/dist/loader/events/index.js +1 -0
- package/{source → x/dist}/loader/index.d.ts +2 -1
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
- package/x/dist/loader/kafka/index.js +1 -0
- package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +10 -7
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/{source → x/dist}/loader/system/index.d.ts +4 -3
- package/x/dist/loader/system/index.js +1 -0
- package/{source → x/dist}/project/index.d.ts +2 -2
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.d.ts +27 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.d.ts +18 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.d.ts +2 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.d.ts +10 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.d.ts +3 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.d.ts +26 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.d.ts +59 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.d.ts +3 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.d.ts +9 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.d.ts +5 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.d.ts +2 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +48 -17
- package/bin/constants/index.mjs +0 -17
- package/bin/main-cli.js +0 -131
- package/source/index.js +0 -6
- package/source/loader/clients/index.js +0 -18
- package/source/loader/configs/index.js +0 -81
- package/source/loader/controller/index.d.ts +0 -129
- package/source/loader/controller/index.js +0 -327
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.js +0 -10
- package/source/loader/kafka/index.js +0 -122
- package/source/loader/localizations/index.js +0 -40
- package/source/loader/logger/index.js +0 -183
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -19
- package/source/project/index.js +0 -66
- package/source/utils/constants/index.d.ts +0 -10
- package/source/utils/constants/index.js +0 -11
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/core/index.js +0 -105
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.d.ts +0 -17
- package/source/utils/helpers/index.js +0 -17
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -63
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middlewares/index.d.ts +0 -1
- package/source/utils/helpers/middlewares/index.js +0 -26
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.d.ts +0 -3
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.dtos.d.ts +0 -47
- package/source/utils/models/classes/class.dtos.js +0 -36
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.response.d.ts +0 -17
- package/source/utils/models/classes/class.response.js +0 -35
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -179
- package/source/utils/models/enums/index.js +0 -133
- package/source/utils/models/index.d.ts +0 -11
- package/source/utils/models/index.js +0 -11
- package/source/utils/models/types/index.d.ts +0 -3
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const distRoot = path.join(process.cwd(), 'x', 'dist')
|
|
5
|
+
|
|
6
|
+
const HAS_EXT = /\.(js|mjs|cjs|json|node|wasm)(\?.*)?$/i
|
|
7
|
+
|
|
8
|
+
function walkJsFiles(dir, out = []) {
|
|
9
|
+
for (const name of fs.readdirSync(dir)) {
|
|
10
|
+
const abs = path.join(dir, name)
|
|
11
|
+
const stat = fs.statSync(abs)
|
|
12
|
+
if (stat.isDirectory()) {
|
|
13
|
+
walkJsFiles(abs, out)
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
16
|
+
if (name.endsWith('.js')) out.push(abs)
|
|
17
|
+
}
|
|
18
|
+
return out
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fixRelativeSpecifier(fileDir, specifier) {
|
|
22
|
+
if (!specifier.startsWith('.')) return specifier
|
|
23
|
+
if (HAS_EXT.test(specifier)) return specifier
|
|
24
|
+
|
|
25
|
+
const resolved = path.resolve(fileDir, specifier)
|
|
26
|
+
const asFile = `${resolved}.js`
|
|
27
|
+
if (fs.existsSync(asFile)) {
|
|
28
|
+
return HAS_EXT.test(specifier) ? specifier : `${specifier}.js`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const indexFile = path.join(resolved, 'index.js')
|
|
32
|
+
if (fs.existsSync(indexFile)) {
|
|
33
|
+
const normalized = specifier.replace(/\/+$/, '')
|
|
34
|
+
return `${normalized}/index.js`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return `${specifier}.js`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function fixJsonImportAttributes(source) {
|
|
42
|
+
return source.replace(
|
|
43
|
+
/(from\s*)(['"])([^'"]+\.json)\2(?!\s+with\b)/g,
|
|
44
|
+
(match, fromKw, quote, spec) => `${fromKw}${quote}${spec}${quote} with { type: 'json' }`,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function fixImportSpecifiersInSource(source, fileDir) {
|
|
49
|
+
return source.replace(/(['"])(\.\.?\/[^'"]+?)\1/g, (match, quote, spec) => {
|
|
50
|
+
const fixed = fixRelativeSpecifier(fileDir, spec)
|
|
51
|
+
return fixed === spec ? match : `${quote}${fixed}${quote}`
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function fixDistImports(distDir = distRoot) {
|
|
56
|
+
if (!fs.existsSync(distDir)) {
|
|
57
|
+
throw new Error(`dist directory not found: ${distDir}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let filesChanged = 0
|
|
61
|
+
const jsFiles = walkJsFiles(distDir)
|
|
62
|
+
for (const file of jsFiles) {
|
|
63
|
+
const before = fs.readFileSync(file, 'utf8')
|
|
64
|
+
const after = fixJsonImportAttributes(fixImportSpecifiersInSource(before, path.dirname(file)))
|
|
65
|
+
if (after !== before) {
|
|
66
|
+
fs.writeFileSync(file, after)
|
|
67
|
+
filesChanged++
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { filesChanged, jsFileCount: jsFiles.length }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const invoked = process.argv[1] ? path.resolve(process.argv[1]) : ''
|
|
74
|
+
const isMain = invoked === path.resolve('x/bin/scripts/fix-dist-imports.mjs')
|
|
75
|
+
|| invoked.endsWith(`${path.sep}fix-dist-imports.mjs`)
|
|
76
|
+
|
|
77
|
+
if (isMain) {
|
|
78
|
+
const result = fixDistImports()
|
|
79
|
+
console.log(`fix-dist-imports: updated ${result.filesChanged} file(s), ${result.jsFileCount} .js total`)
|
|
80
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
import { resolveProjectRoot } from '../helpers/project-root.mjs'
|
|
7
|
+
|
|
8
|
+
const verifyScriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'verify-version-bump.mjs')
|
|
9
|
+
const HOOK_MARKER = '@xrystal/core version-bump pre-commit'
|
|
10
|
+
|
|
11
|
+
export function resolveVerifyScriptPath() {
|
|
12
|
+
return verifyScriptPath
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isGitHookInstalled(root = resolveProjectRoot()) {
|
|
16
|
+
const hookPath = path.join(root, '.git', 'hooks', 'pre-commit')
|
|
17
|
+
if (!fs.existsSync(hookPath)) return false
|
|
18
|
+
return fs.readFileSync(hookPath, 'utf8').includes(HOOK_MARKER)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Install pre-commit into .git/hooks (core repo + services). No .githooks folder. */
|
|
22
|
+
export function installGitHooks(root = resolveProjectRoot()) {
|
|
23
|
+
const gitDir = path.join(root, '.git')
|
|
24
|
+
if (!fs.existsSync(gitDir)) {
|
|
25
|
+
throw new Error('Not a git repository. Run git init first.')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
execSync('git config --unset core.hooksPath', { cwd: root, stdio: 'ignore' })
|
|
30
|
+
} catch {
|
|
31
|
+
// already unset
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const hooksDir = path.join(gitDir, 'hooks')
|
|
35
|
+
fs.mkdirSync(hooksDir, { recursive: true })
|
|
36
|
+
|
|
37
|
+
const hookPath = path.join(hooksDir, 'pre-commit')
|
|
38
|
+
const nodeBin = process.execPath
|
|
39
|
+
const scriptPath = resolveVerifyScriptPath()
|
|
40
|
+
|
|
41
|
+
const content = `#!/bin/sh
|
|
42
|
+
# ${HOOK_MARKER}
|
|
43
|
+
set -e
|
|
44
|
+
"${nodeBin}" "${scriptPath}" --staged
|
|
45
|
+
`
|
|
46
|
+
|
|
47
|
+
fs.writeFileSync(hookPath, content, { mode: 0o755 })
|
|
48
|
+
|
|
49
|
+
return { root, hookPath, scriptPath }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export function ensureHooksInstallScript(projectRoot, cliName = 'xcore') {
|
|
54
|
+
const packageJsonPath = path.join(projectRoot, 'package.json')
|
|
55
|
+
if (!fs.existsSync(packageJsonPath)) return false
|
|
56
|
+
|
|
57
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
58
|
+
pkg.scripts = pkg.scripts ?? {}
|
|
59
|
+
const script = `${cliName} hooks install`
|
|
60
|
+
if (pkg.scripts['hooks:install'] === script) return false
|
|
61
|
+
|
|
62
|
+
pkg.scripts['hooks:install'] = script
|
|
63
|
+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 4)}
|
|
64
|
+
`)
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Install pre-commit hook + package.json hooks:install script (create + manual). */
|
|
69
|
+
export function setupProjectGitHooks(projectRoot, { cliName = 'xcore' } = {}) {
|
|
70
|
+
ensureHooksInstallScript(projectRoot, cliName)
|
|
71
|
+
const refreshed = isGitHookInstalled(projectRoot)
|
|
72
|
+
const result = installGitHooks(projectRoot)
|
|
73
|
+
return { ...result, refreshed }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
77
|
+
|
|
78
|
+
if (isMain) {
|
|
79
|
+
try {
|
|
80
|
+
const result = installGitHooks()
|
|
81
|
+
console.log(`✓ pre-commit hook installed → ${result.hookPath}`)
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(`✗ ${error.message}`)
|
|
84
|
+
process.exit(1)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
const distRoot = path.join(process.cwd(), 'x', 'dist')
|
|
6
|
+
|
|
7
|
+
function walkJsFiles(dir, out = []) {
|
|
8
|
+
for (const name of fs.readdirSync(dir)) {
|
|
9
|
+
const abs = path.join(dir, name)
|
|
10
|
+
const stat = fs.statSync(abs)
|
|
11
|
+
if (stat.isDirectory()) {
|
|
12
|
+
walkJsFiles(abs, out)
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
if (name.endsWith('.js')) out.push(abs)
|
|
16
|
+
}
|
|
17
|
+
return out
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function minifyDistFile(file) {
|
|
21
|
+
const result = spawnSync(
|
|
22
|
+
'bun',
|
|
23
|
+
['build', file, '--outfile', file, '--minify', '--no-bundle', '--external', '*'],
|
|
24
|
+
{ stdio: 'pipe', encoding: 'utf8' },
|
|
25
|
+
)
|
|
26
|
+
if (result.status !== 0) {
|
|
27
|
+
const detail = (result.stderr || result.stdout || '').trim()
|
|
28
|
+
throw new Error(`minify failed for ${file}: ${detail || `exit ${result.status}`}`)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function minifyDist(distDir = distRoot) {
|
|
33
|
+
if (!fs.existsSync(distDir)) {
|
|
34
|
+
throw new Error(`dist directory not found: ${distDir}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const files = walkJsFiles(distDir)
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
minifyDistFile(file)
|
|
40
|
+
}
|
|
41
|
+
return { jsFileCount: files.length }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const invoked = process.argv[1] ? path.resolve(process.argv[1]) : ''
|
|
45
|
+
const isMain = invoked.endsWith(`${path.sep}minify-dist.mjs`)
|
|
46
|
+
|
|
47
|
+
if (isMain) {
|
|
48
|
+
const result = minifyDist()
|
|
49
|
+
console.log(`minify-dist: minified ${result.jsFileCount} file(s)`)
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
const root = process.cwd()
|
|
6
|
+
|
|
7
|
+
const pathsToRemove = [
|
|
8
|
+
'source',
|
|
9
|
+
'x/tests',
|
|
10
|
+
'.github',
|
|
11
|
+
'.vscode',
|
|
12
|
+
'x/logs',
|
|
13
|
+
'x/docker',
|
|
14
|
+
'tsconfig.json',
|
|
15
|
+
'eslint.config.js',
|
|
16
|
+
'.gitignore',
|
|
17
|
+
'.babelrc',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
for (const rel of pathsToRemove) {
|
|
21
|
+
const abs = path.join(root, rel)
|
|
22
|
+
if (!fs.existsSync(abs)) continue
|
|
23
|
+
fs.rmSync(abs, { recursive: true, force: true })
|
|
24
|
+
console.log(`prepare-npm-publish: removed ${rel}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const distJs = []
|
|
28
|
+
function countDistJs(dir) {
|
|
29
|
+
for (const name of fs.readdirSync(dir)) {
|
|
30
|
+
const abs = path.join(dir, name)
|
|
31
|
+
const stat = fs.statSync(abs)
|
|
32
|
+
if (stat.isDirectory()) countDistJs(abs)
|
|
33
|
+
else if (name.endsWith('.js')) distJs.push(abs)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const distDir = path.join(root, 'x', 'dist')
|
|
38
|
+
if (!fs.existsSync(distDir)) {
|
|
39
|
+
console.error('prepare-npm-publish: x/dist missing — run build first')
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
countDistJs(distDir)
|
|
44
|
+
if (distJs.length < 10) {
|
|
45
|
+
console.error(`prepare-npm-publish: expected full dist tree, found ${distJs.length} .js file(s)`)
|
|
46
|
+
process.exit(1)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(`prepare-npm-publish: ready (${distJs.length} .js in x/dist, no source/)`)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { packageDefaults } from '../paths.mjs'
|
|
6
|
+
import { resolveProjectRoot } from '../helpers/project-root.mjs'
|
|
7
|
+
|
|
8
|
+
const PREPARE_STEPS = [
|
|
9
|
+
{ name: 'lint', cmd: 'bun run lint' },
|
|
10
|
+
{ name: 'test', cmd: 'bun test x/tests' },
|
|
11
|
+
{ name: 'build', cmd: 'bun run build' },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
function run(cmd, { root, inherit = false } = {}) {
|
|
15
|
+
execSync(cmd, {
|
|
16
|
+
cwd: root,
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
stdio: inherit ? 'inherit' : 'pipe',
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function readDiskPackageJson(root) {
|
|
23
|
+
return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isCorePackageProject(root) {
|
|
27
|
+
try {
|
|
28
|
+
return readDiskPackageJson(root).name === packageDefaults.packageName
|
|
29
|
+
} catch {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function runReleasePrepare({ root = resolveProjectRoot(), dryRun = false, skipPrepare = false } = {}) {
|
|
35
|
+
if (skipPrepare || !isCorePackageProject(root)) {
|
|
36
|
+
if (!skipPrepare && !isCorePackageProject(root)) {
|
|
37
|
+
console.log('\nRelease prepare skipped (not @xrystal/core).\n')
|
|
38
|
+
}
|
|
39
|
+
return { skipped: true }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('\nRelease prepare (@xrystal/core):\n')
|
|
43
|
+
console.log(' (npm publish CI converts source → .js; git keeps TypeScript)\n')
|
|
44
|
+
|
|
45
|
+
for (const step of PREPARE_STEPS) {
|
|
46
|
+
console.log(`→ ${step.name}`)
|
|
47
|
+
if (dryRun) {
|
|
48
|
+
console.log(` [dry-run] ${step.cmd}`)
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
run(step.cmd, { inherit: true, root })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.log('\n✓ Ready to tag. GitHub Actions will build and publish on tag push.\n')
|
|
55
|
+
return { skipped: false }
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import { runTagRelease } from './version-check.mjs'
|
|
5
|
+
|
|
6
|
+
const dryRun = process.argv.includes('--dry-run')
|
|
7
|
+
const skipPrepare = process.argv.includes('--skip-prepare')
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const state = await runTagRelease({ dryRun, skipPrepare })
|
|
11
|
+
if (!dryRun) {
|
|
12
|
+
console.log(chalk.green(`\n✓ Tag ${state.tag.tagName} pushed — GitHub Publish workflow should trigger.\n`))
|
|
13
|
+
}
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ONE-TIME cleanup: remove npm versions that shipped source/ in the tarball.
|
|
4
|
+
* Remove this script + the workflow step after leaked versions are gone.
|
|
5
|
+
*/
|
|
6
|
+
import { execSync } from 'node:child_process'
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
|
|
10
|
+
const pkgName = '@xrystal/core'
|
|
11
|
+
const root = process.cwd()
|
|
12
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
13
|
+
const publishingVersion = pkg.version
|
|
14
|
+
|
|
15
|
+
function run(cmd) {
|
|
16
|
+
return execSync(cmd, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function resolveVersionsToUnpublish() {
|
|
20
|
+
const fromEnv = process.env.UNPUBLISH_VERSIONS?.trim()
|
|
21
|
+
if (fromEnv) {
|
|
22
|
+
return fromEnv.split(',').map((v) => v.trim()).filter(Boolean)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let published = []
|
|
26
|
+
try {
|
|
27
|
+
const raw = run(`npm view ${pkgName} versions --json`)
|
|
28
|
+
published = JSON.parse(raw)
|
|
29
|
+
if (!Array.isArray(published)) published = [published]
|
|
30
|
+
} catch {
|
|
31
|
+
console.log('unpublish-leaked: no published versions found on registry')
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return published
|
|
36
|
+
.filter((v) => v !== publishingVersion)
|
|
37
|
+
.slice(-3)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const versions = resolveVersionsToUnpublish()
|
|
41
|
+
if (versions.length === 0) {
|
|
42
|
+
console.log('unpublish-leaked: nothing to unpublish')
|
|
43
|
+
process.exit(0)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
console.log(`unpublish-leaked: targeting ${versions.join(', ')} (keeping ${publishingVersion} for publish)`)
|
|
47
|
+
|
|
48
|
+
for (const version of versions) {
|
|
49
|
+
try {
|
|
50
|
+
run(`npm unpublish ${pkgName}@${version} --force`)
|
|
51
|
+
console.log(`unpublish-leaked: ✓ removed ${pkgName}@${version}`)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const stderr = error.stderr?.toString?.() ?? String(error)
|
|
54
|
+
console.warn(`unpublish-leaked: ⚠ unpublish ${version} failed: ${stderr.split('\n')[0]}`)
|
|
55
|
+
try {
|
|
56
|
+
run(`npm deprecate ${pkgName}@${version} "Removed: shipped source by mistake. Upgrade to a newer release."`)
|
|
57
|
+
console.log(`unpublish-leaked: deprecated ${pkgName}@${version} as fallback`)
|
|
58
|
+
} catch {
|
|
59
|
+
console.warn(`unpublish-leaked: ⚠ deprecate also failed for ${version}`)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'node:child_process'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
const root = process.cwd()
|
|
7
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
8
|
+
|
|
9
|
+
function fail(message) {
|
|
10
|
+
console.error(`verify-npm-pack: ✗ ${message}`)
|
|
11
|
+
process.exit(1)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (fs.existsSync(path.join(root, 'source'))) {
|
|
15
|
+
fail('source/ still exists on disk — run prepare-npm-publish.mjs first')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const files = Array.isArray(pkg.files) ? pkg.files : []
|
|
19
|
+
if (files.some((entry) => {
|
|
20
|
+
const normalized = String(entry).replace(/^\.\//, '')
|
|
21
|
+
return normalized === 'source' || normalized.startsWith('source/')
|
|
22
|
+
})) {
|
|
23
|
+
fail('package.json files must not include source/')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!files.some((entry) => String(entry).replace(/^\.\//, '').includes('dist'))) {
|
|
27
|
+
fail('package.json files must include x/dist')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const dryRun = execSync('npm pack --dry-run 2>&1', { cwd: root, encoding: 'utf8' })
|
|
31
|
+
|
|
32
|
+
if (/source\/.*\.ts/.test(dryRun) || /npm notice.*source\//.test(dryRun)) {
|
|
33
|
+
fail('npm pack tarball lists source/ — TypeScript source must not ship')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!/x\/dist\/.*\.js/.test(dryRun)) {
|
|
37
|
+
fail('npm pack tarball must include x/dist/**/*.js')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(path.join(root, 'x/dist/index.js'))) {
|
|
41
|
+
fail('x/dist/index.js missing')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log('verify-npm-pack: ✓ no source/ in package')
|
|
45
|
+
console.log('verify-npm-pack: ✓ x/dist runtime present')
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
assertVersionBumpForStagedCommit,
|
|
6
|
+
assertVersionBumpForTag,
|
|
7
|
+
getProjectRoot,
|
|
8
|
+
} from './version-check.mjs'
|
|
9
|
+
|
|
10
|
+
const mode = process.argv.includes('--staged') ? 'staged' : process.argv.includes('--tag') ? 'tag' : 'staged'
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const root = getProjectRoot()
|
|
14
|
+
if (mode === 'tag') {
|
|
15
|
+
assertVersionBumpForTag(root)
|
|
16
|
+
} else {
|
|
17
|
+
assertVersionBumpForStagedCommit(root)
|
|
18
|
+
}
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(`\n✗ ${error.message}\n`)
|
|
21
|
+
process.exit(1)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
25
|
+
if (isMain) {
|
|
26
|
+
// success is silent for hooks
|
|
27
|
+
}
|