@xylabs/ts-scripts-common 7.5.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/actions/build.mjs +161 -0
- package/dist/actions/build.mjs.map +1 -0
- package/dist/actions/claude-clean.mjs +71 -0
- package/dist/actions/claude-clean.mjs.map +1 -0
- package/dist/actions/claude-commands.mjs +112 -0
- package/dist/actions/claude-commands.mjs.map +1 -0
- package/dist/actions/claude-rules.mjs +137 -0
- package/dist/actions/claude-rules.mjs.map +1 -0
- package/dist/actions/claude-settings.mjs +85 -0
- package/dist/actions/claude-settings.mjs.map +1 -0
- package/dist/actions/claude-skills.mjs +120 -0
- package/dist/actions/claude-skills.mjs.map +1 -0
- package/dist/actions/clean-docs.mjs +45 -0
- package/dist/actions/clean-docs.mjs.map +1 -0
- package/dist/actions/clean-eslint.mjs +26 -0
- package/dist/actions/clean-eslint.mjs.map +1 -0
- package/dist/actions/clean.mjs +145 -0
- package/dist/actions/clean.mjs.map +1 -0
- package/dist/actions/compile.mjs +172 -0
- package/dist/actions/compile.mjs.map +1 -0
- package/dist/actions/copy-assets.mjs +81 -0
- package/dist/actions/copy-assets.mjs.map +1 -0
- package/dist/actions/cycle.mjs +165 -0
- package/dist/actions/cycle.mjs.map +1 -0
- package/dist/actions/dead.mjs +98 -0
- package/dist/actions/dead.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/checkPackage.mjs +672 -0
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs +1 -0
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +48 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +33 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +30 -0
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +309 -0
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +26 -0
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/index.mjs +672 -0
- package/dist/actions/deplint/checkPackage/index.mjs.map +1 -0
- package/dist/actions/deplint/deplint.mjs +770 -0
- package/dist/actions/deplint/deplint.mjs.map +1 -0
- package/dist/actions/deplint/findFiles.mjs +39 -0
- package/dist/actions/deplint/findFiles.mjs.map +1 -0
- package/dist/actions/deplint/findFilesByGlob.mjs +14 -0
- package/dist/actions/deplint/findFilesByGlob.mjs.map +1 -0
- package/dist/actions/deplint/getBasePackageName.mjs +13 -0
- package/dist/actions/deplint/getBasePackageName.mjs.map +1 -0
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs +140 -0
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs.map +1 -0
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs +20 -0
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs.map +1 -0
- package/dist/actions/deplint/getExtendsFromTsconfigs.mjs +44 -0
- package/dist/actions/deplint/getExtendsFromTsconfigs.mjs.map +1 -0
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs +122 -0
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +1 -0
- package/dist/actions/deplint/getImportsFromFile.mjs +85 -0
- package/dist/actions/deplint/getImportsFromFile.mjs.map +1 -0
- package/dist/actions/deplint/getRequiredPeerDependencies.mjs +36 -0
- package/dist/actions/deplint/getRequiredPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/getScriptReferencedPackages.mjs +83 -0
- package/dist/actions/deplint/getScriptReferencedPackages.mjs.map +1 -0
- package/dist/actions/deplint/implicitDevDependencies.mjs +80 -0
- package/dist/actions/deplint/implicitDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/index.mjs +770 -0
- package/dist/actions/deplint/index.mjs.map +1 -0
- package/dist/actions/dupdeps.mjs +205 -0
- package/dist/actions/dupdeps.mjs.map +1 -0
- package/dist/actions/fix.mjs +163 -0
- package/dist/actions/fix.mjs.map +1 -0
- package/dist/actions/gen-docs.mjs +130 -0
- package/dist/actions/gen-docs.mjs.map +1 -0
- package/dist/actions/gitignore.mjs +160 -0
- package/dist/actions/gitignore.mjs.map +1 -0
- package/dist/actions/gitlint-fix.mjs +27 -0
- package/dist/actions/gitlint-fix.mjs.map +1 -0
- package/dist/actions/gitlint.mjs +48 -0
- package/dist/actions/gitlint.mjs.map +1 -0
- package/dist/actions/index.mjs +4129 -0
- package/dist/actions/index.mjs.map +1 -0
- package/dist/actions/knip.mjs +98 -0
- package/dist/actions/knip.mjs.map +1 -0
- package/dist/actions/license.mjs +92 -0
- package/dist/actions/license.mjs.map +1 -0
- package/dist/actions/lint.mjs +160 -0
- package/dist/actions/lint.mjs.map +1 -0
- package/dist/actions/lintlint.mjs +230 -0
- package/dist/actions/lintlint.mjs.map +1 -0
- package/dist/actions/npmignore-gen.mjs +91 -0
- package/dist/actions/npmignore-gen.mjs.map +1 -0
- package/dist/actions/package/clean-outputs.mjs +29 -0
- package/dist/actions/package/clean-outputs.mjs.map +1 -0
- package/dist/actions/package/clean-typescript.mjs +29 -0
- package/dist/actions/package/clean-typescript.mjs.map +1 -0
- package/dist/actions/package/clean.mjs +48 -0
- package/dist/actions/package/clean.mjs.map +1 -0
- package/dist/actions/package/compile/XyConfig.mjs +1 -0
- package/dist/actions/package/compile/XyConfig.mjs.map +1 -0
- package/dist/actions/package/compile/buildEntries.mjs +53 -0
- package/dist/actions/package/compile/buildEntries.mjs.map +1 -0
- package/dist/actions/package/compile/compile.mjs +433 -0
- package/dist/actions/package/compile/compile.mjs.map +1 -0
- package/dist/actions/package/compile/copyTypeFiles.mjs +34 -0
- package/dist/actions/package/compile/copyTypeFiles.mjs.map +1 -0
- package/dist/actions/package/compile/deepMerge.mjs +26 -0
- package/dist/actions/package/compile/deepMerge.mjs.map +1 -0
- package/dist/actions/package/compile/getCompilerOptions.mjs +12 -0
- package/dist/actions/package/compile/getCompilerOptions.mjs.map +1 -0
- package/dist/actions/package/compile/index.mjs +436 -0
- package/dist/actions/package/compile/index.mjs.map +1 -0
- package/dist/actions/package/compile/inputs.mjs +22 -0
- package/dist/actions/package/compile/inputs.mjs.map +1 -0
- package/dist/actions/package/compile/packageCompileTsc.mjs +94 -0
- package/dist/actions/package/compile/packageCompileTsc.mjs.map +1 -0
- package/dist/actions/package/compile/packageCompileTscTypes.mjs +92 -0
- package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +1 -0
- package/dist/actions/package/compile/packageCompileTsup.mjs +402 -0
- package/dist/actions/package/compile/packageCompileTsup.mjs.map +1 -0
- package/dist/actions/package/copy-assets.mjs +46 -0
- package/dist/actions/package/copy-assets.mjs.map +1 -0
- package/dist/actions/package/cycle.mjs +39 -0
- package/dist/actions/package/cycle.mjs.map +1 -0
- package/dist/actions/package/gen-docs.mjs +114 -0
- package/dist/actions/package/gen-docs.mjs.map +1 -0
- package/dist/actions/package/index.mjs +825 -0
- package/dist/actions/package/index.mjs.map +1 -0
- package/dist/actions/package/lint.mjs +80 -0
- package/dist/actions/package/lint.mjs.map +1 -0
- package/dist/actions/package/publint.mjs +66 -0
- package/dist/actions/package/publint.mjs.map +1 -0
- package/dist/actions/package/recompile.mjs +483 -0
- package/dist/actions/package/recompile.mjs.map +1 -0
- package/dist/actions/package-lint.mjs +186 -0
- package/dist/actions/package-lint.mjs.map +1 -0
- package/dist/actions/packman/convert.mjs +387 -0
- package/dist/actions/packman/convert.mjs.map +1 -0
- package/dist/actions/packman/convertToPnpm.mjs +149 -0
- package/dist/actions/packman/convertToPnpm.mjs.map +1 -0
- package/dist/actions/packman/convertToYarn.mjs +171 -0
- package/dist/actions/packman/convertToYarn.mjs.map +1 -0
- package/dist/actions/packman/index.mjs +389 -0
- package/dist/actions/packman/index.mjs.map +1 -0
- package/dist/actions/packman/rewriteScripts.mjs +52 -0
- package/dist/actions/packman/rewriteScripts.mjs.map +1 -0
- package/dist/actions/publint.mjs +187 -0
- package/dist/actions/publint.mjs.map +1 -0
- package/dist/actions/readme-gen.mjs +292 -0
- package/dist/actions/readme-gen.mjs.map +1 -0
- package/dist/actions/readme-init.mjs +83 -0
- package/dist/actions/readme-init.mjs.map +1 -0
- package/dist/actions/rebuild.mjs +122 -0
- package/dist/actions/rebuild.mjs.map +1 -0
- package/dist/actions/recompile.mjs +188 -0
- package/dist/actions/recompile.mjs.map +1 -0
- package/dist/actions/relint.mjs +160 -0
- package/dist/actions/relint.mjs.map +1 -0
- package/dist/actions/retest.mjs +129 -0
- package/dist/actions/retest.mjs.map +1 -0
- package/dist/actions/sonar.mjs +98 -0
- package/dist/actions/sonar.mjs.map +1 -0
- package/dist/actions/statics.mjs +204 -0
- package/dist/actions/statics.mjs.map +1 -0
- package/dist/actions/test.mjs +123 -0
- package/dist/actions/test.mjs.map +1 -0
- package/dist/bin/package/build-only.mjs +445 -0
- package/dist/bin/package/build-only.mjs.map +1 -0
- package/dist/bin/package/build.mjs +445 -0
- package/dist/bin/package/build.mjs.map +1 -0
- package/dist/bin/package/clean-outputs.mjs +29 -0
- package/dist/bin/package/clean-outputs.mjs.map +1 -0
- package/dist/bin/package/clean-typescript.mjs +29 -0
- package/dist/bin/package/clean-typescript.mjs.map +1 -0
- package/dist/bin/package/clean.mjs +53 -0
- package/dist/bin/package/clean.mjs.map +1 -0
- package/dist/bin/package/compile-only.mjs +441 -0
- package/dist/bin/package/compile-only.mjs.map +1 -0
- package/dist/bin/package/compile-tsup.mjs +409 -0
- package/dist/bin/package/compile-tsup.mjs.map +1 -0
- package/dist/bin/package/compile.mjs +445 -0
- package/dist/bin/package/compile.mjs.map +1 -0
- package/dist/bin/package/copy-assets-cjs.mjs +54 -0
- package/dist/bin/package/copy-assets-cjs.mjs.map +1 -0
- package/dist/bin/package/copy-assets-esm.mjs +54 -0
- package/dist/bin/package/copy-assets-esm.mjs.map +1 -0
- package/dist/bin/package/cycle.mjs +51 -0
- package/dist/bin/package/cycle.mjs.map +1 -0
- package/dist/bin/package/fix.mjs +92 -0
- package/dist/bin/package/fix.mjs.map +1 -0
- package/dist/bin/package/gen-docs.mjs +121 -0
- package/dist/bin/package/gen-docs.mjs.map +1 -0
- package/dist/bin/package/lint-verbose.mjs +92 -0
- package/dist/bin/package/lint-verbose.mjs.map +1 -0
- package/dist/bin/package/lint.mjs +92 -0
- package/dist/bin/package/lint.mjs.map +1 -0
- package/dist/bin/package/publint.mjs +75 -0
- package/dist/bin/package/publint.mjs.map +1 -0
- package/dist/bin/package/recompile.mjs +489 -0
- package/dist/bin/package/recompile.mjs.map +1 -0
- package/dist/bin/package/relint.mjs +92 -0
- package/dist/bin/package/relint.mjs.map +1 -0
- package/dist/bin/xy.mjs +3826 -0
- package/dist/bin/xy.mjs.map +1 -0
- package/dist/index.d.ts +564 -0
- package/dist/index.mjs +4979 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/checkResult.mjs +16 -0
- package/dist/lib/checkResult.mjs.map +1 -0
- package/dist/lib/claudeMdTemplate.mjs +65 -0
- package/dist/lib/claudeMdTemplate.mjs.map +1 -0
- package/dist/lib/createBuildConfig.mjs +55 -0
- package/dist/lib/createBuildConfig.mjs.map +1 -0
- package/dist/lib/defaultBuildConfig.mjs +23 -0
- package/dist/lib/defaultBuildConfig.mjs.map +1 -0
- package/dist/lib/deleteGlob.mjs +13 -0
- package/dist/lib/deleteGlob.mjs.map +1 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs +81 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs.map +1 -0
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs +185 -0
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +1 -0
- package/dist/lib/dependencies/index.mjs +186 -0
- package/dist/lib/dependencies/index.mjs.map +1 -0
- package/dist/lib/file/ReadFileSyncOptions.mjs +6 -0
- package/dist/lib/file/ReadFileSyncOptions.mjs.map +1 -0
- package/dist/lib/file/constants.mjs +8 -0
- package/dist/lib/file/constants.mjs.map +1 -0
- package/dist/lib/file/fileLines.mjs +32 -0
- package/dist/lib/file/fileLines.mjs.map +1 -0
- package/dist/lib/file/index.mjs +42 -0
- package/dist/lib/file/index.mjs.map +1 -0
- package/dist/lib/file/tryReadFileSync.mjs +14 -0
- package/dist/lib/file/tryReadFileSync.mjs.map +1 -0
- package/dist/lib/generateIgnoreFiles.mjs +87 -0
- package/dist/lib/generateIgnoreFiles.mjs.map +1 -0
- package/dist/lib/generateReadmeFiles.mjs +260 -0
- package/dist/lib/generateReadmeFiles.mjs.map +1 -0
- package/dist/lib/gitignoreTemplate.mjs +12 -0
- package/dist/lib/gitignoreTemplate.mjs.map +1 -0
- package/dist/lib/index.mjs +834 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/initCwd.mjs +9 -0
- package/dist/lib/initCwd.mjs.map +1 -0
- package/dist/lib/jsonFormatters.mjs +11 -0
- package/dist/lib/jsonFormatters.mjs.map +1 -0
- package/dist/lib/loadConfig.mjs +24 -0
- package/dist/lib/loadConfig.mjs.map +1 -0
- package/dist/lib/parsedPackageJSON.mjs +11 -0
- package/dist/lib/parsedPackageJSON.mjs.map +1 -0
- package/dist/lib/processEx.mjs +36 -0
- package/dist/lib/processEx.mjs.map +1 -0
- package/dist/lib/runSteps.mjs +95 -0
- package/dist/lib/runSteps.mjs.map +1 -0
- package/dist/lib/runStepsAsync.mjs +113 -0
- package/dist/lib/runStepsAsync.mjs.map +1 -0
- package/dist/lib/runXy.mjs +124 -0
- package/dist/lib/runXy.mjs.map +1 -0
- package/dist/lib/runXyWithWarning.mjs +36 -0
- package/dist/lib/runXyWithWarning.mjs.map +1 -0
- package/dist/lib/safeExit.mjs +61 -0
- package/dist/lib/safeExit.mjs.map +1 -0
- package/dist/lib/string/empty.mjs +8 -0
- package/dist/lib/string/empty.mjs.map +1 -0
- package/dist/lib/string/index.mjs +12 -0
- package/dist/lib/string/index.mjs.map +1 -0
- package/dist/lib/string/union.mjs +6 -0
- package/dist/lib/string/union.mjs.map +1 -0
- package/dist/lib/tryRunLocalScript.mjs +56 -0
- package/dist/lib/tryRunLocalScript.mjs.map +1 -0
- package/dist/lib/withErrnoException.mjs +13 -0
- package/dist/lib/withErrnoException.mjs.map +1 -0
- package/dist/lib/withError.mjs +8 -0
- package/dist/lib/withError.mjs.map +1 -0
- package/dist/loadPackageConfig.mjs +11 -0
- package/dist/loadPackageConfig.mjs.map +1 -0
- package/dist/pm/PackageManager.mjs +1 -0
- package/dist/pm/PackageManager.mjs.map +1 -0
- package/dist/pm/detectPackageManager.mjs +10 -0
- package/dist/pm/detectPackageManager.mjs.map +1 -0
- package/dist/pm/index.mjs +28 -0
- package/dist/pm/index.mjs.map +1 -0
- package/dist/pm/registry.mjs +27 -0
- package/dist/pm/registry.mjs.map +1 -0
- package/dist/types.d.mjs +1 -0
- package/dist/types.d.mjs.map +1 -0
- package/dist/xy/build/buildCommand.mjs +182 -0
- package/dist/xy/build/buildCommand.mjs.map +1 -0
- package/dist/xy/build/compileCommand.mjs +189 -0
- package/dist/xy/build/compileCommand.mjs.map +1 -0
- package/dist/xy/build/compileOnlyCommand.mjs +190 -0
- package/dist/xy/build/compileOnlyCommand.mjs.map +1 -0
- package/dist/xy/build/copyAssetsCommand.mjs +92 -0
- package/dist/xy/build/copyAssetsCommand.mjs.map +1 -0
- package/dist/xy/build/index.mjs +493 -0
- package/dist/xy/build/index.mjs.map +1 -0
- package/dist/xy/build/rebuildCommand.mjs +135 -0
- package/dist/xy/build/rebuildCommand.mjs.map +1 -0
- package/dist/xy/build/recompileCommand.mjs +205 -0
- package/dist/xy/build/recompileCommand.mjs.map +1 -0
- package/dist/xy/common/claude/cleanCommand.mjs +79 -0
- package/dist/xy/common/claude/cleanCommand.mjs.map +1 -0
- package/dist/xy/common/claude/commandsCommand.mjs +120 -0
- package/dist/xy/common/claude/commandsCommand.mjs.map +1 -0
- package/dist/xy/common/claude/index.mjs +546 -0
- package/dist/xy/common/claude/index.mjs.map +1 -0
- package/dist/xy/common/claude/initCommand.mjs +319 -0
- package/dist/xy/common/claude/initCommand.mjs.map +1 -0
- package/dist/xy/common/claude/rulesCommand.mjs +153 -0
- package/dist/xy/common/claude/rulesCommand.mjs.map +1 -0
- package/dist/xy/common/claude/settingsCommand.mjs +93 -0
- package/dist/xy/common/claude/settingsCommand.mjs.map +1 -0
- package/dist/xy/common/claude/skillsCommand.mjs +129 -0
- package/dist/xy/common/claude/skillsCommand.mjs.map +1 -0
- package/dist/xy/common/cleanDocsCommand.mjs +53 -0
- package/dist/xy/common/cleanDocsCommand.mjs.map +1 -0
- package/dist/xy/common/deadCommand.mjs +116 -0
- package/dist/xy/common/deadCommand.mjs.map +1 -0
- package/dist/xy/common/genDocsCommand.mjs +146 -0
- package/dist/xy/common/genDocsCommand.mjs.map +1 -0
- package/dist/xy/common/gitignoreCommand.mjs +166 -0
- package/dist/xy/common/gitignoreCommand.mjs.map +1 -0
- package/dist/xy/common/gitlintCommand.mjs +82 -0
- package/dist/xy/common/gitlintCommand.mjs.map +1 -0
- package/dist/xy/common/index.mjs +1874 -0
- package/dist/xy/common/index.mjs.map +1 -0
- package/dist/xy/common/licenseCommand.mjs +108 -0
- package/dist/xy/common/licenseCommand.mjs.map +1 -0
- package/dist/xy/common/npmignoreGenCommand.mjs +101 -0
- package/dist/xy/common/npmignoreGenCommand.mjs.map +1 -0
- package/dist/xy/common/packmanCommand.mjs +415 -0
- package/dist/xy/common/packmanCommand.mjs.map +1 -0
- package/dist/xy/common/readme/genCommand.mjs +324 -0
- package/dist/xy/common/readme/genCommand.mjs.map +1 -0
- package/dist/xy/common/readme/index.mjs +364 -0
- package/dist/xy/common/readme/index.mjs.map +1 -0
- package/dist/xy/common/readme/initCommand.mjs +103 -0
- package/dist/xy/common/readme/initCommand.mjs.map +1 -0
- package/dist/xy/common/retestCommand.mjs +142 -0
- package/dist/xy/common/retestCommand.mjs.map +1 -0
- package/dist/xy/common/testCommand.mjs +136 -0
- package/dist/xy/common/testCommand.mjs.map +1 -0
- package/dist/xy/index.mjs +3823 -0
- package/dist/xy/index.mjs.map +1 -0
- package/dist/xy/lint/cycleCommand.mjs +184 -0
- package/dist/xy/lint/cycleCommand.mjs.map +1 -0
- package/dist/xy/lint/deplintCommand.mjs +820 -0
- package/dist/xy/lint/deplintCommand.mjs.map +1 -0
- package/dist/xy/lint/fixCommand.mjs +184 -0
- package/dist/xy/lint/fixCommand.mjs.map +1 -0
- package/dist/xy/lint/index.mjs +1691 -0
- package/dist/xy/lint/index.mjs.map +1 -0
- package/dist/xy/lint/knipCommand.mjs +121 -0
- package/dist/xy/lint/knipCommand.mjs.map +1 -0
- package/dist/xy/lint/lintCommand.mjs +202 -0
- package/dist/xy/lint/lintCommand.mjs.map +1 -0
- package/dist/xy/lint/lintlintCommand.mjs +250 -0
- package/dist/xy/lint/lintlintCommand.mjs.map +1 -0
- package/dist/xy/lint/packageLintCommand.mjs +201 -0
- package/dist/xy/lint/packageLintCommand.mjs.map +1 -0
- package/dist/xy/lint/publintCommand.mjs +208 -0
- package/dist/xy/lint/publintCommand.mjs.map +1 -0
- package/dist/xy/lint/relintCommand.mjs +179 -0
- package/dist/xy/lint/relintCommand.mjs.map +1 -0
- package/dist/xy/lint/sonarCommand.mjs +121 -0
- package/dist/xy/lint/sonarCommand.mjs.map +1 -0
- package/dist/xy/param.mjs +8 -0
- package/dist/xy/param.mjs.map +1 -0
- package/dist/xy/xy.mjs +3819 -0
- package/dist/xy/xy.mjs.map +1 -0
- package/dist/xy/xyParseOptions.mjs +91 -0
- package/dist/xy/xyParseOptions.mjs.map +1 -0
- package/package.json +108 -0
- package/templates/claude/CLAUDE-local.md +4 -0
- package/templates/claude/CLAUDE-project.md +4 -0
- package/templates/claude/commands/xy-build.md +5 -0
- package/templates/claude/commands/xy-clean.md +5 -0
- package/templates/claude/commands/xy-compile.md +5 -0
- package/templates/claude/commands/xy-cycle.md +5 -0
- package/templates/claude/commands/xy-dead.md +5 -0
- package/templates/claude/commands/xy-deplint.md +5 -0
- package/templates/claude/commands/xy-deps.md +24 -0
- package/templates/claude/commands/xy-dupdeps.md +5 -0
- package/templates/claude/commands/xy-fix.md +5 -0
- package/templates/claude/commands/xy-gen-docs.md +5 -0
- package/templates/claude/commands/xy-gitignore.md +5 -0
- package/templates/claude/commands/xy-gitlint.md +5 -0
- package/templates/claude/commands/xy-knip.md +5 -0
- package/templates/claude/commands/xy-license.md +5 -0
- package/templates/claude/commands/xy-lint-rules.md +44 -0
- package/templates/claude/commands/xy-lint.md +5 -0
- package/templates/claude/commands/xy-publint.md +5 -0
- package/templates/claude/commands/xy-rebuild.md +5 -0
- package/templates/claude/commands/xy-recompile.md +5 -0
- package/templates/claude/commands/xy-reinstall.md +5 -0
- package/templates/claude/commands/xy-relint.md +5 -0
- package/templates/claude/commands/xy-retest.md +5 -0
- package/templates/claude/commands/xy-sonar.md +5 -0
- package/templates/claude/commands/xy-test.md +5 -0
- package/templates/claude/commands/xy-up.md +7 -0
- package/templates/claude/rules/xylabs-architecture.md +8 -0
- package/templates/claude/rules/xylabs-build.md +9 -0
- package/templates/claude/rules/xylabs-git-workflow.md +7 -0
- package/templates/claude/rules/xylabs-naming.md +7 -0
- package/templates/claude/rules/xylabs-style.md +17 -0
- package/templates/claude/skills/xylabs-e2e-setup/SKILL.md +223 -0
- package/templates/gitignore/template.gitignore +51 -0
- package/templates/readme/README.body.md +11 -0
- package/templates/readme/README.template.md +22 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4979 @@
|
|
|
1
|
+
// src/actions/build.ts
|
|
2
|
+
import chalk11 from "chalk";
|
|
3
|
+
|
|
4
|
+
// src/lib/checkResult.ts
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
var checkResult = (name, result, level = "error", exitOnFail = false) => {
|
|
7
|
+
if (result) {
|
|
8
|
+
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
9
|
+
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
10
|
+
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
11
|
+
if (exitOnFail) {
|
|
12
|
+
process.exit(result);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/lib/claudeMdTemplate.ts
|
|
18
|
+
import {
|
|
19
|
+
readdirSync,
|
|
20
|
+
readFileSync,
|
|
21
|
+
statSync
|
|
22
|
+
} from "fs";
|
|
23
|
+
import { createRequire } from "module";
|
|
24
|
+
import PATH from "path";
|
|
25
|
+
var require2 = createRequire(import.meta.url);
|
|
26
|
+
var packageRoot = PATH.dirname(require2.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
27
|
+
var templatesDir = PATH.resolve(packageRoot, "templates", "claude");
|
|
28
|
+
var XYLABS_RULES_PREFIX = "xylabs-";
|
|
29
|
+
var XYLABS_COMMANDS_PREFIX = "xy-";
|
|
30
|
+
var LEGACY_COMMANDS_PREFIX = "xylabs-";
|
|
31
|
+
var XYLABS_SKILLS_PREFIX = "xylabs-";
|
|
32
|
+
var claudeMdRuleTemplates = () => {
|
|
33
|
+
const rulesDir = PATH.resolve(templatesDir, "rules");
|
|
34
|
+
const files = readdirSync(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const file of files) {
|
|
37
|
+
result[file] = readFileSync(PATH.resolve(rulesDir, file), "utf8");
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
var claudeCommandTemplates = () => {
|
|
42
|
+
const commandsDir = PATH.resolve(templatesDir, "commands");
|
|
43
|
+
const files = readdirSync(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
44
|
+
const result = {};
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
result[file] = readFileSync(PATH.resolve(commandsDir, file), "utf8");
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
var claudeSkillTemplates = () => {
|
|
51
|
+
const skillsDir = PATH.resolve(templatesDir, "skills");
|
|
52
|
+
const dirs = readdirSync(skillsDir).filter(
|
|
53
|
+
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync(PATH.resolve(skillsDir, f)).isDirectory()
|
|
54
|
+
);
|
|
55
|
+
const result = {};
|
|
56
|
+
for (const dir of dirs) {
|
|
57
|
+
const dirPath = PATH.resolve(skillsDir, dir);
|
|
58
|
+
const files = readdirSync(dirPath, { recursive: true, encoding: "utf8" });
|
|
59
|
+
result[dir] = {};
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
if (statSync(PATH.resolve(dirPath, file)).isFile()) {
|
|
62
|
+
result[dir][file] = readFileSync(PATH.resolve(dirPath, file), "utf8");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
var claudeMdProjectTemplate = () => readFileSync(PATH.resolve(templatesDir, "CLAUDE-project.md"), "utf8");
|
|
69
|
+
var claudeMdLocalTemplate = () => readFileSync(PATH.resolve(templatesDir, "CLAUDE-local.md"), "utf8");
|
|
70
|
+
|
|
71
|
+
// src/lib/createBuildConfig.ts
|
|
72
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
73
|
+
|
|
74
|
+
// src/lib/defaultBuildConfig.ts
|
|
75
|
+
var defaultBuildConfig = {
|
|
76
|
+
compilerOptions: {
|
|
77
|
+
rootDir: "src",
|
|
78
|
+
rootDirs: ["package.json"]
|
|
79
|
+
},
|
|
80
|
+
exclude: [
|
|
81
|
+
"**/build",
|
|
82
|
+
"**/dist",
|
|
83
|
+
"**/node_modules",
|
|
84
|
+
"**/*.spec.*",
|
|
85
|
+
"**/*.spec",
|
|
86
|
+
"**/*.stories.*",
|
|
87
|
+
"**/*.example.*",
|
|
88
|
+
"**/spec/*",
|
|
89
|
+
"**/stories/*"
|
|
90
|
+
],
|
|
91
|
+
include: ["src"]
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/lib/createBuildConfig.ts
|
|
95
|
+
var getGeneralTypescriptConfig = (location) => {
|
|
96
|
+
let generalConfig;
|
|
97
|
+
try {
|
|
98
|
+
generalConfig = readFileSync2(`${location}/tsconfig.json`, { encoding: "utf8" });
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return JSON.parse(generalConfig);
|
|
103
|
+
};
|
|
104
|
+
var createBuildConfig = (location, module, target, outDirSuffix) => {
|
|
105
|
+
const generalConfigObject = getGeneralTypescriptConfig(location);
|
|
106
|
+
if (generalConfigObject === false) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
...generalConfigObject,
|
|
111
|
+
compilerOptions: {
|
|
112
|
+
...defaultBuildConfig.compilerOptions,
|
|
113
|
+
...generalConfigObject.compilerOptions,
|
|
114
|
+
module,
|
|
115
|
+
outDir: `./${generalConfigObject.compilerOptions?.outDir ?? "dist"}/${outDirSuffix}`,
|
|
116
|
+
target
|
|
117
|
+
},
|
|
118
|
+
exclude: [...generalConfigObject.exclude ?? [], ...defaultBuildConfig.exclude],
|
|
119
|
+
include: [...generalConfigObject.include ?? [], ...defaultBuildConfig.include]
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/lib/deleteGlob.ts
|
|
124
|
+
import fs from "fs";
|
|
125
|
+
import { glob } from "glob";
|
|
126
|
+
var deleteGlob = (globPath) => {
|
|
127
|
+
const files = glob.sync(globPath);
|
|
128
|
+
for (const file of files) {
|
|
129
|
+
fs.rmSync(file, { recursive: true, force: true });
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/lib/dependencies/detectDuplicateDependencies.ts
|
|
134
|
+
import { execSync } from "child_process";
|
|
135
|
+
|
|
136
|
+
// src/pm/detectPackageManager.ts
|
|
137
|
+
import { existsSync } from "fs";
|
|
138
|
+
function detectPackageManager() {
|
|
139
|
+
if (existsSync("pnpm-lock.yaml") || existsSync("pnpm-workspace.yaml")) return "pnpm";
|
|
140
|
+
return "yarn";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/pm/registry.ts
|
|
144
|
+
var implementations = /* @__PURE__ */ new Map();
|
|
145
|
+
function registerPackageManager(pm) {
|
|
146
|
+
implementations.set(pm.name, pm);
|
|
147
|
+
}
|
|
148
|
+
function getPackageManager(name) {
|
|
149
|
+
const pmName = name ?? detectPackageManager();
|
|
150
|
+
const pm = implementations.get(pmName);
|
|
151
|
+
if (!pm) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`No package manager implementation registered for "${pmName}". Install @xylabs/ts-scripts-${pmName === "yarn" ? "yarn3" : pmName} and ensure it is imported.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return pm;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/lib/processEx.ts
|
|
160
|
+
import chalk2 from "chalk";
|
|
161
|
+
|
|
162
|
+
// src/lib/withError.ts
|
|
163
|
+
var withError = (ex, closure, predicate = (ex2) => !!ex2.name && !!ex2.message) => {
|
|
164
|
+
return predicate(ex) ? closure(ex) : void 0;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/lib/withErrnoException.ts
|
|
168
|
+
var withErrnoException = (ex, closure) => {
|
|
169
|
+
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/lib/processEx.ts
|
|
173
|
+
var processEx = (ex) => {
|
|
174
|
+
const error = typeof ex === "string" ? new Error(ex) : ex;
|
|
175
|
+
const exitCode = withErrnoException(error, (error2) => {
|
|
176
|
+
if (error2.code === "ENOENT") {
|
|
177
|
+
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
178
|
+
} else {
|
|
179
|
+
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
180
|
+
}
|
|
181
|
+
return error2.errno ?? -1;
|
|
182
|
+
}) ?? withError(error, (error2) => {
|
|
183
|
+
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
184
|
+
return -1;
|
|
185
|
+
}) ?? (() => {
|
|
186
|
+
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
187
|
+
return -1;
|
|
188
|
+
})();
|
|
189
|
+
process.exit(process.exitCode ?? exitCode);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/lib/safeExit.ts
|
|
193
|
+
var safeExit = (func, exitOnFail = true) => {
|
|
194
|
+
try {
|
|
195
|
+
const result = func();
|
|
196
|
+
if (result && exitOnFail) {
|
|
197
|
+
process.exit(result);
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
} catch (ex) {
|
|
201
|
+
return processEx(ex);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
var safeExitAsync = async (func, exitOnFail = true) => {
|
|
205
|
+
try {
|
|
206
|
+
const result = await func();
|
|
207
|
+
if (result && exitOnFail) {
|
|
208
|
+
process.exit(result);
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
} catch (ex) {
|
|
212
|
+
return processEx(ex);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/lib/dependencies/DuplicateDetector.ts
|
|
217
|
+
import { EOL } from "os";
|
|
218
|
+
import chalk3 from "chalk";
|
|
219
|
+
|
|
220
|
+
// src/lib/jsonFormatters.ts
|
|
221
|
+
var multiLineToJSONArray = (output) => {
|
|
222
|
+
const withCommas = output.replaceAll("\r\n", "").replaceAll("\n", ",");
|
|
223
|
+
const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1));
|
|
224
|
+
const collection = `[${cleanCollection}]`;
|
|
225
|
+
return JSON.parse(collection);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/lib/dependencies/DuplicateDetector.ts
|
|
229
|
+
var trimVirtualMeta = (value) => {
|
|
230
|
+
const virtualParts = value.split("virtual:");
|
|
231
|
+
if (virtualParts.length > 1) {
|
|
232
|
+
const hashParts = virtualParts[1].split("#");
|
|
233
|
+
return virtualParts[0] + hashParts[1];
|
|
234
|
+
} else {
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var trimObjectDependencyVirtualMeta = (obj) => {
|
|
239
|
+
const resultObj = {};
|
|
240
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
241
|
+
resultObj[trimVirtualMeta(key)] = {
|
|
242
|
+
descriptor: trimVirtualMeta(value.descriptor),
|
|
243
|
+
locator: trimVirtualMeta(value.locator)
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return resultObj;
|
|
247
|
+
};
|
|
248
|
+
var trimDependencyVirtualMeta = (dependencies) => {
|
|
249
|
+
return dependencies.map((dependency) => {
|
|
250
|
+
return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) };
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
var DuplicateDetector = class {
|
|
254
|
+
dependency;
|
|
255
|
+
dependencyEntries;
|
|
256
|
+
constructor(output, dependency) {
|
|
257
|
+
this.dependency = dependency;
|
|
258
|
+
this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output));
|
|
259
|
+
}
|
|
260
|
+
detect() {
|
|
261
|
+
const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency));
|
|
262
|
+
if (result.duplicateVersions.length > 0) {
|
|
263
|
+
console.log(chalk3.yellow(`${EOL}Duplicates found for: ${this.dependency}`));
|
|
264
|
+
const duplicateVersions = result.duplicateVersions.toString().replaceAll(",", `${EOL} `);
|
|
265
|
+
console.log(chalk3.grey(` ${duplicateVersions}`, EOL));
|
|
266
|
+
return 1;
|
|
267
|
+
} else {
|
|
268
|
+
console.log(`${this.dependency} - OK`);
|
|
269
|
+
return 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
detectReducer(acc, entry) {
|
|
273
|
+
const version = Object.entries(entry.children).map(([k]) => k)[0];
|
|
274
|
+
if (!acc.currentVersion) {
|
|
275
|
+
acc.currentVersion = version;
|
|
276
|
+
return acc;
|
|
277
|
+
}
|
|
278
|
+
if (acc.currentVersion && acc.currentVersion !== version && !version.includes("@virtual:")) {
|
|
279
|
+
if (acc.duplicateVersions.length === 0) {
|
|
280
|
+
acc.duplicateVersions.push(acc.currentVersion);
|
|
281
|
+
}
|
|
282
|
+
acc.duplicateVersions.push(version);
|
|
283
|
+
acc.duplicateVersions = [...new Set(acc.duplicateVersions)];
|
|
284
|
+
}
|
|
285
|
+
return acc;
|
|
286
|
+
}
|
|
287
|
+
resultsFactory = (dependency) => ({
|
|
288
|
+
currentVersion: void 0,
|
|
289
|
+
dependency,
|
|
290
|
+
duplicateVersions: []
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/lib/dependencies/detectDuplicateDependencies.ts
|
|
295
|
+
var detectDuplicateDependencies = (depsFromPackageJSON, DefaultDependencies2) => {
|
|
296
|
+
let exitCode = 0;
|
|
297
|
+
const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies2;
|
|
298
|
+
return safeExit(() => {
|
|
299
|
+
if (dependencies) {
|
|
300
|
+
for (const dependency of dependencies) {
|
|
301
|
+
let output;
|
|
302
|
+
try {
|
|
303
|
+
const pm = getPackageManager();
|
|
304
|
+
const cmd = `${pm.command} why ${dependency} --json`;
|
|
305
|
+
output = execSync(cmd).toString();
|
|
306
|
+
} catch (e) {
|
|
307
|
+
console.error(`Error running dependency check: ${e}`);
|
|
308
|
+
exitCode = 1;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (output) {
|
|
312
|
+
exitCode = new DuplicateDetector(output, dependency).detect();
|
|
313
|
+
} else {
|
|
314
|
+
console.log(`${dependency} - N/A`);
|
|
315
|
+
if (depsFromPackageJSON) {
|
|
316
|
+
exitCode = 1;
|
|
317
|
+
console.log(`\u{1F6A8} Library ${dependency} was requested in package.json but not found`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return exitCode;
|
|
322
|
+
} else {
|
|
323
|
+
console.log("\u{1F6A8} No dependencies where passed");
|
|
324
|
+
return exitCode;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/lib/file/constants.ts
|
|
330
|
+
var WINDOWS_NEWLINE_REGEX = /\r\n/g;
|
|
331
|
+
var CROSS_PLATFORM_NEWLINE = "\n";
|
|
332
|
+
|
|
333
|
+
// src/lib/file/fileLines.ts
|
|
334
|
+
import {
|
|
335
|
+
existsSync as existsSync2,
|
|
336
|
+
readFileSync as readFileSync3,
|
|
337
|
+
writeFileSync
|
|
338
|
+
} from "fs";
|
|
339
|
+
|
|
340
|
+
// src/lib/string/empty.ts
|
|
341
|
+
var empty = (value) => value?.trim().length === 0;
|
|
342
|
+
var notEmpty = (value) => !empty(value);
|
|
343
|
+
|
|
344
|
+
// src/lib/string/union.ts
|
|
345
|
+
var union = (a, b) => /* @__PURE__ */ new Set([...new Set(a), ...new Set(b)]);
|
|
346
|
+
|
|
347
|
+
// src/lib/file/ReadFileSyncOptions.ts
|
|
348
|
+
var defaultReadFileSyncOptions = { encoding: "utf8" };
|
|
349
|
+
|
|
350
|
+
// src/lib/file/fileLines.ts
|
|
351
|
+
var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync2(uri) ? readFileSync3(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
|
|
352
|
+
var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
|
|
353
|
+
var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
|
|
354
|
+
const existing = existsSync2(uri) ? readFileSync3(uri, options) : void 0;
|
|
355
|
+
const desired = lines.join(CROSS_PLATFORM_NEWLINE);
|
|
356
|
+
if (existing !== desired) writeFileSync(uri, desired, options);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// src/lib/file/tryReadFileSync.ts
|
|
360
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
|
|
361
|
+
var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
|
|
362
|
+
return existsSync3(uri) ? readFileSync4(uri, options) : void 0;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/lib/generateIgnoreFiles.ts
|
|
366
|
+
import chalk4 from "chalk";
|
|
367
|
+
|
|
368
|
+
// src/lib/initCwd.ts
|
|
369
|
+
function INIT_CWD() {
|
|
370
|
+
if (!process.env.INIT_CWD) console.error("Missing INIT_CWD");
|
|
371
|
+
return process.env.INIT_CWD;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/lib/generateIgnoreFiles.ts
|
|
375
|
+
var localeCompare = (a, b) => a.localeCompare(b);
|
|
376
|
+
var mergeEntries = (a, b) => [...union(a, b)].toSorted(localeCompare);
|
|
377
|
+
var generateIgnoreFiles = (filename2, pkg) => {
|
|
378
|
+
console.log(chalk4.green(`Generate ${filename2} Files`));
|
|
379
|
+
const cwd5 = INIT_CWD() ?? ".";
|
|
380
|
+
const pm = getPackageManager();
|
|
381
|
+
const singleWorkspace = pkg ? pm.findWorkspace(pkg) : void 0;
|
|
382
|
+
const workspaces = singleWorkspace ? [singleWorkspace] : pm.listWorkspaces();
|
|
383
|
+
const readEntries = (location) => readNonEmptyLines(`${location}/${filename2}`);
|
|
384
|
+
const writeEntries = (location, entries) => writeLines(`${location}/${filename2}`, entries);
|
|
385
|
+
const results = workspaces.map(({ location, name }) => {
|
|
386
|
+
try {
|
|
387
|
+
writeEntries(location, mergeEntries(readEntries(cwd5), readEntries(location)));
|
|
388
|
+
return 0;
|
|
389
|
+
} catch (ex) {
|
|
390
|
+
const error = ex;
|
|
391
|
+
console.error(`Generate ${filename2} Files [${name}] [${error.message}]`);
|
|
392
|
+
return 1;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
const succeeded = results.every((result) => result === 0);
|
|
396
|
+
return succeeded ? 0 : 1;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// src/lib/generateReadmeFiles.ts
|
|
400
|
+
import { execSync as execSync2 } from "child_process";
|
|
401
|
+
import FS, { readFileSync as readFileSync5 } from "fs";
|
|
402
|
+
import {
|
|
403
|
+
mkdir,
|
|
404
|
+
readFile,
|
|
405
|
+
writeFile
|
|
406
|
+
} from "fs/promises";
|
|
407
|
+
import { createRequire as createRequire2 } from "module";
|
|
408
|
+
import PATH2 from "path";
|
|
409
|
+
import { createInterface } from "readline";
|
|
410
|
+
import chalk5 from "chalk";
|
|
411
|
+
var require3 = createRequire2(import.meta.url);
|
|
412
|
+
var packageRoot2 = PATH2.dirname(require3.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
413
|
+
var readmeTemplatesDir = PATH2.resolve(packageRoot2, "templates", "readme");
|
|
414
|
+
function fillTemplate(template, data) {
|
|
415
|
+
const additionalData = { ...data, safeName: data.name.replaceAll("/", "__").replaceAll("@", "") };
|
|
416
|
+
return template.replaceAll(/\{\{(.*?)\}\}/g, (_, key) => additionalData[key.trim()] ?? "");
|
|
417
|
+
}
|
|
418
|
+
function generateTypedoc(packageLocation, entryPoints) {
|
|
419
|
+
const tempDir = PATH2.join(packageLocation, ".temp-typedoc");
|
|
420
|
+
try {
|
|
421
|
+
if (!FS.existsSync(tempDir)) {
|
|
422
|
+
FS.mkdirSync(tempDir, { recursive: true });
|
|
423
|
+
}
|
|
424
|
+
const typedocConfig = {
|
|
425
|
+
disableSources: true,
|
|
426
|
+
entryPointStrategy: "expand",
|
|
427
|
+
entryPoints: entryPoints.map((ep) => PATH2.resolve(packageLocation, ep)),
|
|
428
|
+
excludeExternals: true,
|
|
429
|
+
excludeInternal: true,
|
|
430
|
+
excludePrivate: true,
|
|
431
|
+
githubPages: false,
|
|
432
|
+
hideBreadcrumbs: true,
|
|
433
|
+
hideGenerator: true,
|
|
434
|
+
hidePageTitle: true,
|
|
435
|
+
out: tempDir,
|
|
436
|
+
plugin: ["typedoc-plugin-markdown"],
|
|
437
|
+
readme: "none",
|
|
438
|
+
skipErrorChecking: true,
|
|
439
|
+
sort: ["source-order"],
|
|
440
|
+
theme: "markdown",
|
|
441
|
+
useCodeBlocks: true
|
|
442
|
+
};
|
|
443
|
+
const typedocJsonPath = PATH2.join(tempDir, "typedoc.json");
|
|
444
|
+
FS.writeFileSync(typedocJsonPath, JSON.stringify(typedocConfig, null, 2));
|
|
445
|
+
try {
|
|
446
|
+
execSync2(`npx typedoc --options ${typedocJsonPath}`, {
|
|
447
|
+
cwd: process.cwd(),
|
|
448
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
449
|
+
});
|
|
450
|
+
} catch {
|
|
451
|
+
return "";
|
|
452
|
+
}
|
|
453
|
+
return consolidateMarkdown(tempDir);
|
|
454
|
+
} catch {
|
|
455
|
+
return "";
|
|
456
|
+
} finally {
|
|
457
|
+
try {
|
|
458
|
+
FS.rmSync(tempDir, { force: true, recursive: true });
|
|
459
|
+
} catch {
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function consolidateMarkdown(tempDir) {
|
|
464
|
+
let consolidated = "## Reference\n\n";
|
|
465
|
+
const mainReadmePath = PATH2.join(tempDir, "README.md");
|
|
466
|
+
if (FS.existsSync(mainReadmePath)) {
|
|
467
|
+
const mainContent = FS.readFileSync(mainReadmePath, "utf8").replace(/^---(.|\n)*?---\n/, "").replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
|
|
468
|
+
consolidated += mainContent + "\n\n";
|
|
469
|
+
}
|
|
470
|
+
consolidated += processDirectory(tempDir);
|
|
471
|
+
return consolidated.replaceAll(/\n\n\n+/g, "\n\n").replaceAll(/^#### /gm, "### ").replaceAll(/^##### /gm, "#### ").replaceAll(/^###### /gm, "##### ");
|
|
472
|
+
}
|
|
473
|
+
function processDirectory(dir, level = 0) {
|
|
474
|
+
const indent = " ".repeat(level);
|
|
475
|
+
let content = "";
|
|
476
|
+
try {
|
|
477
|
+
const items = FS.readdirSync(dir, { withFileTypes: true });
|
|
478
|
+
for (const item of items) {
|
|
479
|
+
if (item.isDirectory()) continue;
|
|
480
|
+
if (item.name === "README.md" || !item.name.endsWith(".md")) continue;
|
|
481
|
+
const fileContent = FS.readFileSync(PATH2.join(dir, item.name), "utf8").replace(/^---(.|\n)*?---\n/, "");
|
|
482
|
+
const moduleName = item.name.replace(".md", "");
|
|
483
|
+
content += `
|
|
484
|
+
|
|
485
|
+
${indent}### <a id="${moduleName}"></a>${moduleName}
|
|
486
|
+
|
|
487
|
+
`;
|
|
488
|
+
content += fileContent.replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
|
|
489
|
+
}
|
|
490
|
+
for (const item of items) {
|
|
491
|
+
if (!item.isDirectory()) continue;
|
|
492
|
+
if (item.name === "spec" || item.name.includes(".spec")) continue;
|
|
493
|
+
content += `
|
|
494
|
+
|
|
495
|
+
${indent}### ${item.name}
|
|
496
|
+
`;
|
|
497
|
+
content += processDirectory(PATH2.join(dir, item.name), level + 1);
|
|
498
|
+
}
|
|
499
|
+
} catch {
|
|
500
|
+
}
|
|
501
|
+
return content;
|
|
502
|
+
}
|
|
503
|
+
function askConfirmation(question) {
|
|
504
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
505
|
+
return new Promise((resolve) => {
|
|
506
|
+
rl.question(question, (answer) => {
|
|
507
|
+
rl.close();
|
|
508
|
+
resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
var DEFAULT_README_TEMPLATE = readFileSync5(PATH2.resolve(readmeTemplatesDir, "README.template.md"), "utf8");
|
|
513
|
+
var DEFAULT_README_BODY = readFileSync5(PATH2.resolve(readmeTemplatesDir, "README.body.md"), "utf8");
|
|
514
|
+
function applyLogoConfig(template, logoUrl, logoLinkUrl) {
|
|
515
|
+
let result = template;
|
|
516
|
+
if (logoUrl) {
|
|
517
|
+
result = result.replace(/\[logo]: .+/, `[logo]: ${logoUrl}`);
|
|
518
|
+
if (logoLinkUrl) {
|
|
519
|
+
result = result.replace(/\[!\[logo]\[]][^)]*\)/, `[![logo][]](${logoLinkUrl})`);
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
result = result.replace(/\[!\[logo]\[]][^\n]*\n*/, "");
|
|
523
|
+
result = result.replace(/\[logo]: [^\n]*\n?/, "");
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
function resolveTemplatePath(templatePath) {
|
|
528
|
+
const cwd5 = INIT_CWD() ?? ".";
|
|
529
|
+
return templatePath ?? PATH2.join(cwd5, ".xy", "README.template.md");
|
|
530
|
+
}
|
|
531
|
+
async function loadOrCreateTemplate(resolvedTemplatePath) {
|
|
532
|
+
try {
|
|
533
|
+
const template = await readFile(resolvedTemplatePath, "utf8");
|
|
534
|
+
return { created: false, template };
|
|
535
|
+
} catch {
|
|
536
|
+
console.log(chalk5.yellow(`Template not found: ${resolvedTemplatePath}`));
|
|
537
|
+
const shouldCreate = await askConfirmation("Would you like to create a stock template? (y/N) ");
|
|
538
|
+
if (!shouldCreate) {
|
|
539
|
+
throw new Error("Template creation declined");
|
|
540
|
+
}
|
|
541
|
+
const template = DEFAULT_README_TEMPLATE;
|
|
542
|
+
await scaffoldTemplate(resolvedTemplatePath, template);
|
|
543
|
+
return { created: true, template };
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
async function scaffoldTemplate(resolvedTemplatePath, template) {
|
|
547
|
+
const xyDir = PATH2.dirname(resolvedTemplatePath);
|
|
548
|
+
await mkdir(xyDir, { recursive: true });
|
|
549
|
+
await writeFile(resolvedTemplatePath, template);
|
|
550
|
+
console.log(chalk5.green(`Created template: ${resolvedTemplatePath}`));
|
|
551
|
+
const bodyPath = PATH2.join(xyDir, "README.body.md");
|
|
552
|
+
await writeFile(bodyPath, DEFAULT_README_BODY);
|
|
553
|
+
console.log(chalk5.green(`Created body template: ${bodyPath}`));
|
|
554
|
+
}
|
|
555
|
+
async function resolveBody(location, defaultBody) {
|
|
556
|
+
const localBodyPath = PATH2.join(location, "README.body.md");
|
|
557
|
+
try {
|
|
558
|
+
return await readFile(localBodyPath, "utf8");
|
|
559
|
+
} catch {
|
|
560
|
+
return defaultBody;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
async function generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose) {
|
|
564
|
+
try {
|
|
565
|
+
const pkgJsonPath = PATH2.join(location, "package.json");
|
|
566
|
+
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf8"));
|
|
567
|
+
const body = await resolveBody(location, defaultBody);
|
|
568
|
+
const typedocContent = typedoc ? generateTypedoc(location, ["src/index*.ts"]) : "";
|
|
569
|
+
const readmeContent = fillTemplate(template, {
|
|
570
|
+
...pkgJson,
|
|
571
|
+
body,
|
|
572
|
+
typedoc: typedocContent
|
|
573
|
+
});
|
|
574
|
+
await writeFile(PATH2.join(location, "README.md"), readmeContent);
|
|
575
|
+
if (verbose) console.log(chalk5.green(` ${name}`));
|
|
576
|
+
return true;
|
|
577
|
+
} catch (ex) {
|
|
578
|
+
const error = ex;
|
|
579
|
+
console.warn(chalk5.yellow(` Skipped ${location}: ${error.message}`));
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
async function generateReadmeFiles({
|
|
584
|
+
logoLinkUrl,
|
|
585
|
+
logoUrl,
|
|
586
|
+
pkg,
|
|
587
|
+
templatePath,
|
|
588
|
+
typedoc = false,
|
|
589
|
+
verbose = false
|
|
590
|
+
}) {
|
|
591
|
+
console.log(chalk5.green("Generate README Files"));
|
|
592
|
+
const resolvedTemplatePath = resolveTemplatePath(templatePath);
|
|
593
|
+
let template;
|
|
594
|
+
let templateCreated;
|
|
595
|
+
try {
|
|
596
|
+
({ template, created: templateCreated } = await loadOrCreateTemplate(resolvedTemplatePath));
|
|
597
|
+
} catch {
|
|
598
|
+
return 1;
|
|
599
|
+
}
|
|
600
|
+
template = applyLogoConfig(template, logoUrl, logoLinkUrl);
|
|
601
|
+
if (templateCreated) {
|
|
602
|
+
console.log(chalk5.green("Generating README files for all packages..."));
|
|
603
|
+
}
|
|
604
|
+
const xyDir = PATH2.dirname(resolvedTemplatePath);
|
|
605
|
+
const xyBodyPath = PATH2.join(xyDir, "README.body.md");
|
|
606
|
+
let defaultBody;
|
|
607
|
+
try {
|
|
608
|
+
defaultBody = await readFile(xyBodyPath, "utf8");
|
|
609
|
+
} catch {
|
|
610
|
+
defaultBody = DEFAULT_README_BODY;
|
|
611
|
+
}
|
|
612
|
+
const pm = getPackageManager();
|
|
613
|
+
const singleWorkspace = pkg && !templateCreated ? pm.findWorkspace(pkg) : void 0;
|
|
614
|
+
const workspaces = singleWorkspace ? [singleWorkspace] : pm.listWorkspaces();
|
|
615
|
+
let failed = false;
|
|
616
|
+
for (const { location, name } of workspaces) {
|
|
617
|
+
const success = await generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose);
|
|
618
|
+
if (!success) failed = true;
|
|
619
|
+
}
|
|
620
|
+
return failed ? 1 : 0;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// src/lib/gitignoreTemplate.ts
|
|
624
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
625
|
+
import { createRequire as createRequire3 } from "module";
|
|
626
|
+
import PATH3 from "path";
|
|
627
|
+
var require4 = createRequire3(import.meta.url);
|
|
628
|
+
var packageRoot3 = PATH3.dirname(require4.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
629
|
+
var templatesDir2 = PATH3.resolve(packageRoot3, "templates", "gitignore");
|
|
630
|
+
var gitignoreTemplate = () => readFileSync6(PATH3.resolve(templatesDir2, "template.gitignore"), "utf8");
|
|
631
|
+
|
|
632
|
+
// src/lib/loadConfig.ts
|
|
633
|
+
import chalk6 from "chalk";
|
|
634
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
635
|
+
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
636
|
+
import deepmerge from "deepmerge";
|
|
637
|
+
var config;
|
|
638
|
+
var loadConfig = async (params) => {
|
|
639
|
+
if (config === void 0) {
|
|
640
|
+
const cosmicConfigResult = await cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } }).search();
|
|
641
|
+
config = cosmicConfigResult?.config;
|
|
642
|
+
const configFilePath = cosmicConfigResult?.filepath;
|
|
643
|
+
if (configFilePath !== void 0) {
|
|
644
|
+
console.log(chalk6.green(`Loaded config from ${configFilePath}`));
|
|
645
|
+
if (config.verbose) {
|
|
646
|
+
console.log(chalk6.gray(`${JSON.stringify(config, null, 2)}`));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return deepmerge(config, params ?? {});
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// src/lib/parsedPackageJSON.ts
|
|
654
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
655
|
+
var parsedPackageJSON = (path15) => {
|
|
656
|
+
const pathToPackageJSON = path15 ?? process.env.npm_package_json ?? "";
|
|
657
|
+
const packageJSON = readFileSync7(pathToPackageJSON).toString();
|
|
658
|
+
return JSON.parse(packageJSON);
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// src/lib/runSteps.ts
|
|
662
|
+
import { spawnSync } from "child_process";
|
|
663
|
+
import { existsSync as existsSync4 } from "fs";
|
|
664
|
+
import chalk7 from "chalk";
|
|
665
|
+
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
666
|
+
return safeExit(() => {
|
|
667
|
+
const pkgName = process.env.npm_package_name;
|
|
668
|
+
console.log(chalk7.green(`${name} [${pkgName}]`));
|
|
669
|
+
let totalStatus = 0;
|
|
670
|
+
for (const [i, [command, args, config2]] of steps.entries()) {
|
|
671
|
+
if (messages?.[i]) {
|
|
672
|
+
console.log(chalk7.gray(messages?.[i]));
|
|
673
|
+
}
|
|
674
|
+
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
675
|
+
if (command === "node" && !existsSync4(argList[0])) {
|
|
676
|
+
throw new Error(`File not found [${argList[0]}]`);
|
|
677
|
+
}
|
|
678
|
+
const status = spawnSync(command, Array.isArray(args) ? args : args.split(" "), {
|
|
679
|
+
...config2,
|
|
680
|
+
encoding: "utf8",
|
|
681
|
+
env: { FORCE_COLOR: "3", ...process.env },
|
|
682
|
+
shell: true,
|
|
683
|
+
stdio: "inherit"
|
|
684
|
+
}).status ?? 0;
|
|
685
|
+
checkResult(name, status, "error", exitOnFail);
|
|
686
|
+
totalStatus += status ?? 0;
|
|
687
|
+
}
|
|
688
|
+
return totalStatus;
|
|
689
|
+
}, !!exitOnFail);
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// src/lib/runStepsAsync.ts
|
|
693
|
+
import { spawn } from "child_process";
|
|
694
|
+
import { existsSync as existsSync5 } from "fs";
|
|
695
|
+
import chalk8 from "chalk";
|
|
696
|
+
var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
697
|
+
return new Promise((resolve) => {
|
|
698
|
+
const [command, args, config2] = step;
|
|
699
|
+
if (message) {
|
|
700
|
+
console.log(chalk8.gray(message));
|
|
701
|
+
}
|
|
702
|
+
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
703
|
+
if (command === "node" && !existsSync5(argList[0])) {
|
|
704
|
+
throw new Error(`File not found [${argList[0]}]`);
|
|
705
|
+
}
|
|
706
|
+
spawn(command, Array.isArray(args) ? args : args.split(" "), {
|
|
707
|
+
...config2,
|
|
708
|
+
env: { FORCE_COLOR: "3", ...process.env },
|
|
709
|
+
shell: true,
|
|
710
|
+
stdio: "inherit"
|
|
711
|
+
}).on("close", (code) => {
|
|
712
|
+
if (code) {
|
|
713
|
+
console.error(
|
|
714
|
+
chalk8.red(
|
|
715
|
+
`Command Exited With Non-Zero Result [${chalk8.gray(code)}] | ${chalk8.yellow(command)} ${chalk8.white(
|
|
716
|
+
Array.isArray(args) ? args.join(" ") : args
|
|
717
|
+
)}`
|
|
718
|
+
)
|
|
719
|
+
);
|
|
720
|
+
checkResult(name, code, "error", exitOnFail);
|
|
721
|
+
resolve(code);
|
|
722
|
+
} else {
|
|
723
|
+
resolve(0);
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
var runStepsAsync = async (name, steps, exitOnFail = true, messages) => {
|
|
729
|
+
return await safeExitAsync(async () => {
|
|
730
|
+
const pkgName = process.env.npm_package_name;
|
|
731
|
+
console.log(chalk8.green(`${name} [${pkgName}]`));
|
|
732
|
+
let result = 0;
|
|
733
|
+
for (const [i, step] of steps.entries()) {
|
|
734
|
+
result += await runStepAsync(name, step, exitOnFail, messages?.[i]);
|
|
735
|
+
}
|
|
736
|
+
return result;
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
// src/lib/runXy.ts
|
|
741
|
+
var runXy = (command) => {
|
|
742
|
+
const pm = getPackageManager();
|
|
743
|
+
return runSteps(
|
|
744
|
+
`XY [${command}]`,
|
|
745
|
+
[pm.runXy([command, ...process.argv.filter((value, index) => index > 1 ? value : void 0)])]
|
|
746
|
+
);
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// src/lib/runXyWithWarning.ts
|
|
750
|
+
import chalk9 from "chalk";
|
|
751
|
+
var runXyWithWarning = (command) => {
|
|
752
|
+
const pm = getPackageManager();
|
|
753
|
+
const commandString = `${pm.command} ${command}`;
|
|
754
|
+
const commandXyString = `${pm.command} xy ${command}`;
|
|
755
|
+
console.warn(chalk9.yellow(`WARNING: [${chalk9.white(commandString)}] is deprecated for XY Labs Scripts.`));
|
|
756
|
+
console.warn(chalk9.gray(`Did you mean [${chalk9.magenta(commandXyString)}]?`));
|
|
757
|
+
return 1;
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// src/lib/tryRunLocalScript.ts
|
|
761
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
762
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
763
|
+
import PATH4 from "path";
|
|
764
|
+
import chalk10 from "chalk";
|
|
765
|
+
function tryRunLocalScript(commandName) {
|
|
766
|
+
if (process.env.XY_LOCAL_SCRIPT === "1") return void 0;
|
|
767
|
+
const rootPkgPath = PATH4.resolve(process.cwd(), "package.json");
|
|
768
|
+
let rootPkg;
|
|
769
|
+
try {
|
|
770
|
+
rootPkg = JSON.parse(readFileSync8(rootPkgPath, "utf8"));
|
|
771
|
+
} catch {
|
|
772
|
+
return void 0;
|
|
773
|
+
}
|
|
774
|
+
if (!rootPkg.scripts?.[commandName]) return void 0;
|
|
775
|
+
console.log(chalk10.blue(`Delegating "${commandName}" to local script`));
|
|
776
|
+
const pm = getPackageManager();
|
|
777
|
+
const result = spawnSync2(pm.command, ["run", commandName], {
|
|
778
|
+
cwd: process.cwd(),
|
|
779
|
+
encoding: "utf8",
|
|
780
|
+
env: {
|
|
781
|
+
FORCE_COLOR: "3",
|
|
782
|
+
...process.env,
|
|
783
|
+
XY_LOCAL_SCRIPT: "1"
|
|
784
|
+
},
|
|
785
|
+
shell: true,
|
|
786
|
+
stdio: "inherit"
|
|
787
|
+
});
|
|
788
|
+
return result.status ?? 1;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// src/actions/build.ts
|
|
792
|
+
var build = async ({
|
|
793
|
+
incremental,
|
|
794
|
+
jobs,
|
|
795
|
+
target,
|
|
796
|
+
verbose,
|
|
797
|
+
pkg
|
|
798
|
+
}) => {
|
|
799
|
+
const start = Date.now();
|
|
800
|
+
const pkgOptions = pkg === void 0 ? [] : [pkg];
|
|
801
|
+
const incrementalOptions = incremental ? ["-i"] : [];
|
|
802
|
+
const verboseOptions = verbose ? ["-v"] : [];
|
|
803
|
+
const targetOptions = target === void 0 ? [] : ["-t", target];
|
|
804
|
+
const jobsOptions = jobs === void 0 ? [] : ["-j", `${jobs}`];
|
|
805
|
+
if (jobs !== void 0) {
|
|
806
|
+
console.log(chalk11.blue(`Jobs set to [${jobs}]`));
|
|
807
|
+
}
|
|
808
|
+
const pm = getPackageManager();
|
|
809
|
+
const result = await runStepsAsync(`Build${incremental ? "-Incremental" : ""} [${pkg ?? "All"}]`, [
|
|
810
|
+
pm.runXy(["compile", ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions, "--types", "tsup"]),
|
|
811
|
+
pm.runXy(["publint", ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]),
|
|
812
|
+
pm.runXy(["deplint", ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]),
|
|
813
|
+
pm.runXy(["lint", ...pkgOptions, ...verboseOptions, ...incrementalOptions])
|
|
814
|
+
]);
|
|
815
|
+
console.log(`${chalk11.gray("Built in")} [${chalk11.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk11.gray("seconds")}`);
|
|
816
|
+
return result;
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
// src/actions/claude-clean.ts
|
|
820
|
+
import {
|
|
821
|
+
existsSync as existsSync6,
|
|
822
|
+
readdirSync as readdirSync2,
|
|
823
|
+
rmSync,
|
|
824
|
+
unlinkSync
|
|
825
|
+
} from "fs";
|
|
826
|
+
import PATH5 from "path";
|
|
827
|
+
import chalk12 from "chalk";
|
|
828
|
+
function removeFile(filePath, label) {
|
|
829
|
+
if (existsSync6(filePath)) {
|
|
830
|
+
unlinkSync(filePath);
|
|
831
|
+
console.log(chalk12.yellow(` Removed ${label}`));
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
function removeDir(dirPath, label) {
|
|
837
|
+
if (existsSync6(dirPath)) {
|
|
838
|
+
rmSync(dirPath, { recursive: true });
|
|
839
|
+
console.log(chalk12.yellow(` Removed ${label}`));
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
function claudeClean() {
|
|
845
|
+
console.log(chalk12.green("Clean Claude configuration"));
|
|
846
|
+
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
847
|
+
let removed = 0;
|
|
848
|
+
const rootFiles = ["CLAUDE.md", "CLAUDE.local.md"];
|
|
849
|
+
for (const file of rootFiles) {
|
|
850
|
+
if (removeFile(PATH5.resolve(cwd5, file), file)) removed++;
|
|
851
|
+
}
|
|
852
|
+
if (removeDir(PATH5.resolve(cwd5, ".claude"), ".claude/")) removed++;
|
|
853
|
+
const packagesDir = PATH5.resolve(cwd5, "packages");
|
|
854
|
+
if (existsSync6(packagesDir)) {
|
|
855
|
+
const findClaudeFiles = (dir, prefix) => {
|
|
856
|
+
const entries = readdirSync2(dir, { withFileTypes: true });
|
|
857
|
+
for (const entry of entries) {
|
|
858
|
+
const fullPath = PATH5.resolve(dir, entry.name);
|
|
859
|
+
const label = `${prefix}${entry.name}`;
|
|
860
|
+
if (entry.isFile() && (entry.name === "CLAUDE.md" || entry.name === "CLAUDE.local.md")) {
|
|
861
|
+
if (removeFile(fullPath, label)) removed++;
|
|
862
|
+
} else if (entry.isDirectory() && entry.name === ".claude") {
|
|
863
|
+
if (removeDir(fullPath, `${label}/`)) removed++;
|
|
864
|
+
} else if (entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist") {
|
|
865
|
+
findClaudeFiles(fullPath, `${label}/`);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
findClaudeFiles(packagesDir, "packages/");
|
|
870
|
+
}
|
|
871
|
+
if (removed > 0) {
|
|
872
|
+
console.log(chalk12.green(` Removed ${removed} item(s)`));
|
|
873
|
+
} else {
|
|
874
|
+
console.log(chalk12.gray(" Nothing to clean"));
|
|
875
|
+
}
|
|
876
|
+
return 0;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// src/actions/claude-commands.ts
|
|
880
|
+
import {
|
|
881
|
+
existsSync as existsSync7,
|
|
882
|
+
mkdirSync,
|
|
883
|
+
readdirSync as readdirSync3,
|
|
884
|
+
readFileSync as readFileSync9,
|
|
885
|
+
unlinkSync as unlinkSync2,
|
|
886
|
+
writeFileSync as writeFileSync2
|
|
887
|
+
} from "fs";
|
|
888
|
+
import PATH6 from "path";
|
|
889
|
+
import chalk13 from "chalk";
|
|
890
|
+
var syncCommandFiles = (commandsDir) => {
|
|
891
|
+
const templates = claudeCommandTemplates();
|
|
892
|
+
const templateNames = new Set(Object.keys(templates));
|
|
893
|
+
let updated = 0;
|
|
894
|
+
let created = 0;
|
|
895
|
+
for (const [filename2, content] of Object.entries(templates)) {
|
|
896
|
+
const targetPath = PATH6.resolve(commandsDir, filename2);
|
|
897
|
+
const existing = existsSync7(targetPath) ? readFileSync9(targetPath, "utf8") : void 0;
|
|
898
|
+
if (existing === content) continue;
|
|
899
|
+
writeFileSync2(targetPath, content, "utf8");
|
|
900
|
+
if (existing) {
|
|
901
|
+
updated++;
|
|
902
|
+
} else {
|
|
903
|
+
created++;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return {
|
|
907
|
+
created,
|
|
908
|
+
templateNames,
|
|
909
|
+
updated
|
|
910
|
+
};
|
|
911
|
+
};
|
|
912
|
+
var removeStaleCommands = (commandsDir, templateNames) => {
|
|
913
|
+
const existingCommands = readdirSync3(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
914
|
+
let removed = 0;
|
|
915
|
+
for (const file of existingCommands) {
|
|
916
|
+
if (!templateNames.has(file)) {
|
|
917
|
+
unlinkSync2(PATH6.resolve(commandsDir, file));
|
|
918
|
+
removed++;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return removed;
|
|
922
|
+
};
|
|
923
|
+
var removeLegacyCommands = (commandsDir) => {
|
|
924
|
+
const legacyFiles = readdirSync3(commandsDir).filter((f) => f.startsWith(LEGACY_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
925
|
+
for (const file of legacyFiles) {
|
|
926
|
+
unlinkSync2(PATH6.resolve(commandsDir, file));
|
|
927
|
+
}
|
|
928
|
+
return legacyFiles.length;
|
|
929
|
+
};
|
|
930
|
+
var logCommandsResult = (created, updated, removed) => {
|
|
931
|
+
if (created || updated || removed) {
|
|
932
|
+
const parts = [
|
|
933
|
+
created ? `${created} created` : "",
|
|
934
|
+
updated ? `${updated} updated` : "",
|
|
935
|
+
removed ? `${removed} removed` : ""
|
|
936
|
+
].filter(Boolean);
|
|
937
|
+
console.log(chalk13.green(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: ${parts.join(", ")}`));
|
|
938
|
+
} else {
|
|
939
|
+
console.log(chalk13.gray(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: already up to date`));
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
var claudeCommands = () => {
|
|
943
|
+
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
944
|
+
const commandsDir = PATH6.resolve(cwd5, ".claude", "commands");
|
|
945
|
+
mkdirSync(commandsDir, { recursive: true });
|
|
946
|
+
const legacy = removeLegacyCommands(commandsDir);
|
|
947
|
+
const {
|
|
948
|
+
created,
|
|
949
|
+
templateNames,
|
|
950
|
+
updated
|
|
951
|
+
} = syncCommandFiles(commandsDir);
|
|
952
|
+
const removed = removeStaleCommands(commandsDir, templateNames);
|
|
953
|
+
logCommandsResult(created, updated, removed + legacy);
|
|
954
|
+
return 0;
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
// src/actions/claude-rules.ts
|
|
958
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
959
|
+
import {
|
|
960
|
+
existsSync as existsSync8,
|
|
961
|
+
mkdirSync as mkdirSync2,
|
|
962
|
+
readdirSync as readdirSync4,
|
|
963
|
+
readFileSync as readFileSync10,
|
|
964
|
+
unlinkSync as unlinkSync3,
|
|
965
|
+
writeFileSync as writeFileSync3
|
|
966
|
+
} from "fs";
|
|
967
|
+
import PATH7 from "path";
|
|
968
|
+
import chalk14 from "chalk";
|
|
969
|
+
var syncRuleFiles = (rulesDir) => {
|
|
970
|
+
const templates = claudeMdRuleTemplates();
|
|
971
|
+
const templateNames = new Set(Object.keys(templates));
|
|
972
|
+
let updated = 0;
|
|
973
|
+
let created = 0;
|
|
974
|
+
for (const [filename2, content] of Object.entries(templates)) {
|
|
975
|
+
const targetPath = PATH7.resolve(rulesDir, filename2);
|
|
976
|
+
const existing = existsSync8(targetPath) ? readFileSync10(targetPath, "utf8") : void 0;
|
|
977
|
+
if (existing === content) continue;
|
|
978
|
+
writeFileSync3(targetPath, content, "utf8");
|
|
979
|
+
if (existing) {
|
|
980
|
+
updated++;
|
|
981
|
+
} else {
|
|
982
|
+
created++;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return {
|
|
986
|
+
created,
|
|
987
|
+
templateNames,
|
|
988
|
+
updated
|
|
989
|
+
};
|
|
990
|
+
};
|
|
991
|
+
var removeStaleRules = (rulesDir, templateNames) => {
|
|
992
|
+
const existingRules = readdirSync4(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
|
|
993
|
+
let removed = 0;
|
|
994
|
+
for (const file of existingRules) {
|
|
995
|
+
if (!templateNames.has(file)) {
|
|
996
|
+
unlinkSync3(PATH7.resolve(rulesDir, file));
|
|
997
|
+
removed++;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return removed;
|
|
1001
|
+
};
|
|
1002
|
+
var logRulesResult = (created, updated, removed) => {
|
|
1003
|
+
if (created || updated || removed) {
|
|
1004
|
+
const parts = [
|
|
1005
|
+
created ? `${created} created` : "",
|
|
1006
|
+
updated ? `${updated} updated` : "",
|
|
1007
|
+
removed ? `${removed} removed` : ""
|
|
1008
|
+
].filter(Boolean);
|
|
1009
|
+
console.log(chalk14.green(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: ${parts.join(", ")}`));
|
|
1010
|
+
} else {
|
|
1011
|
+
console.log(chalk14.gray(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: already up to date`));
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
var ensureProjectClaudeMd = (cwd5, force) => {
|
|
1015
|
+
const projectPath = PATH7.resolve(cwd5, "CLAUDE.md");
|
|
1016
|
+
if (!existsSync8(projectPath) || force) {
|
|
1017
|
+
if (force && existsSync8(projectPath)) {
|
|
1018
|
+
console.log(chalk14.yellow("Regenerating CLAUDE.md"));
|
|
1019
|
+
}
|
|
1020
|
+
console.log(chalk14.green("Generating CLAUDE.md via claude /init..."));
|
|
1021
|
+
const result = spawnSync3("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
|
|
1022
|
+
cwd: cwd5,
|
|
1023
|
+
shell: true,
|
|
1024
|
+
stdio: "inherit"
|
|
1025
|
+
});
|
|
1026
|
+
if (result.status !== 0) {
|
|
1027
|
+
console.error(chalk14.red("claude /init failed \u2014 is Claude Code installed?"));
|
|
1028
|
+
return 1;
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
console.log(chalk14.gray("CLAUDE.md already exists (skipped, use --force to regenerate)"));
|
|
1032
|
+
}
|
|
1033
|
+
return 0;
|
|
1034
|
+
};
|
|
1035
|
+
var ensureLocalClaudeMd = (cwd5) => {
|
|
1036
|
+
const localPath = PATH7.resolve(cwd5, "CLAUDE.local.md");
|
|
1037
|
+
if (existsSync8(localPath)) {
|
|
1038
|
+
console.log(chalk14.gray("CLAUDE.local.md already exists (skipped)"));
|
|
1039
|
+
} else {
|
|
1040
|
+
writeFileSync3(localPath, claudeMdLocalTemplate(), "utf8");
|
|
1041
|
+
console.log(chalk14.green("Generated CLAUDE.local.md"));
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
var claudeRules = ({ force } = {}) => {
|
|
1045
|
+
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
1046
|
+
const rulesDir = PATH7.resolve(cwd5, ".claude", "rules");
|
|
1047
|
+
mkdirSync2(rulesDir, { recursive: true });
|
|
1048
|
+
const {
|
|
1049
|
+
created,
|
|
1050
|
+
templateNames,
|
|
1051
|
+
updated
|
|
1052
|
+
} = syncRuleFiles(rulesDir);
|
|
1053
|
+
const removed = removeStaleRules(rulesDir, templateNames);
|
|
1054
|
+
logRulesResult(created, updated, removed);
|
|
1055
|
+
const claudeMdResult = ensureProjectClaudeMd(cwd5, force);
|
|
1056
|
+
ensureLocalClaudeMd(cwd5);
|
|
1057
|
+
return claudeMdResult ?? 0;
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
// src/actions/claude-settings.ts
|
|
1061
|
+
import {
|
|
1062
|
+
existsSync as existsSync9,
|
|
1063
|
+
mkdirSync as mkdirSync3,
|
|
1064
|
+
writeFileSync as writeFileSync4
|
|
1065
|
+
} from "fs";
|
|
1066
|
+
import PATH8 from "path";
|
|
1067
|
+
import { createInterface as createInterface2 } from "readline";
|
|
1068
|
+
import chalk15 from "chalk";
|
|
1069
|
+
var DEFAULT_SETTINGS = {
|
|
1070
|
+
permissions: {
|
|
1071
|
+
allow: [
|
|
1072
|
+
"Bash(git *)",
|
|
1073
|
+
"Bash(yarn *)",
|
|
1074
|
+
"Bash(npx *)",
|
|
1075
|
+
"Bash(node *)",
|
|
1076
|
+
"Bash(ls *)",
|
|
1077
|
+
"Bash(mkdir *)",
|
|
1078
|
+
"Bash(cp *)",
|
|
1079
|
+
"Bash(mv *)",
|
|
1080
|
+
"Bash(rm *)",
|
|
1081
|
+
"Bash(cat *)",
|
|
1082
|
+
"Bash(head *)",
|
|
1083
|
+
"Bash(tail *)",
|
|
1084
|
+
"Bash(echo *)",
|
|
1085
|
+
"Bash(pwd)",
|
|
1086
|
+
"Bash(which *)",
|
|
1087
|
+
"Bash(grep *)",
|
|
1088
|
+
"Bash(find *)",
|
|
1089
|
+
"Bash(npm view *)",
|
|
1090
|
+
"Bash(gh *)",
|
|
1091
|
+
"Read",
|
|
1092
|
+
"Edit",
|
|
1093
|
+
"Write",
|
|
1094
|
+
"Glob",
|
|
1095
|
+
"Grep",
|
|
1096
|
+
"Skill"
|
|
1097
|
+
],
|
|
1098
|
+
deny: [
|
|
1099
|
+
"Bash(git push --force *)",
|
|
1100
|
+
"Bash(git reset --hard *)",
|
|
1101
|
+
"Bash(rm -rf /*)"
|
|
1102
|
+
]
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
function askConfirmation2(question) {
|
|
1106
|
+
const rl = createInterface2({ input: process.stdin, output: process.stdout });
|
|
1107
|
+
return new Promise((resolve) => {
|
|
1108
|
+
rl.question(question, (answer) => {
|
|
1109
|
+
rl.close();
|
|
1110
|
+
resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
|
|
1111
|
+
});
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
async function claudeSettings() {
|
|
1115
|
+
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
1116
|
+
const claudeDir = PATH8.resolve(cwd5, ".claude");
|
|
1117
|
+
const settingsPath = PATH8.resolve(claudeDir, "settings.local.json");
|
|
1118
|
+
mkdirSync3(claudeDir, { recursive: true });
|
|
1119
|
+
if (existsSync9(settingsPath)) {
|
|
1120
|
+
const confirmed = await askConfirmation2(
|
|
1121
|
+
chalk15.yellow(`${settingsPath} already exists. Replace it? (y/N) `)
|
|
1122
|
+
);
|
|
1123
|
+
if (!confirmed) {
|
|
1124
|
+
console.log(chalk15.gray("Skipped \u2014 existing settings.local.json preserved"));
|
|
1125
|
+
return 0;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
writeFileSync4(settingsPath, `${JSON.stringify(DEFAULT_SETTINGS, null, 2)}
|
|
1129
|
+
`, "utf8");
|
|
1130
|
+
console.log(chalk15.green("Generated .claude/settings.local.json"));
|
|
1131
|
+
return 0;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
// src/actions/claude-skills.ts
|
|
1135
|
+
import {
|
|
1136
|
+
existsSync as existsSync10,
|
|
1137
|
+
mkdirSync as mkdirSync4,
|
|
1138
|
+
readdirSync as readdirSync5,
|
|
1139
|
+
readFileSync as readFileSync11,
|
|
1140
|
+
rmSync as rmSync2,
|
|
1141
|
+
statSync as statSync2,
|
|
1142
|
+
writeFileSync as writeFileSync5
|
|
1143
|
+
} from "fs";
|
|
1144
|
+
import PATH9 from "path";
|
|
1145
|
+
import chalk16 from "chalk";
|
|
1146
|
+
var syncSkillFiles = (skillsDir) => {
|
|
1147
|
+
const templates = claudeSkillTemplates();
|
|
1148
|
+
const templateNames = new Set(Object.keys(templates));
|
|
1149
|
+
let updated = 0;
|
|
1150
|
+
let created = 0;
|
|
1151
|
+
for (const [skillName, files] of Object.entries(templates)) {
|
|
1152
|
+
const skillDir = PATH9.resolve(skillsDir, skillName);
|
|
1153
|
+
mkdirSync4(skillDir, { recursive: true });
|
|
1154
|
+
for (const [filename2, content] of Object.entries(files)) {
|
|
1155
|
+
const targetPath = PATH9.resolve(skillDir, filename2);
|
|
1156
|
+
mkdirSync4(PATH9.dirname(targetPath), { recursive: true });
|
|
1157
|
+
const existing = existsSync10(targetPath) ? readFileSync11(targetPath, "utf8") : void 0;
|
|
1158
|
+
if (existing === content) continue;
|
|
1159
|
+
writeFileSync5(targetPath, content, "utf8");
|
|
1160
|
+
if (existing) {
|
|
1161
|
+
updated++;
|
|
1162
|
+
} else {
|
|
1163
|
+
created++;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return {
|
|
1168
|
+
created,
|
|
1169
|
+
templateNames,
|
|
1170
|
+
updated
|
|
1171
|
+
};
|
|
1172
|
+
};
|
|
1173
|
+
var removeStaleSkills = (skillsDir, templateNames) => {
|
|
1174
|
+
const existingSkills = readdirSync5(skillsDir).filter(
|
|
1175
|
+
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync2(PATH9.resolve(skillsDir, f)).isDirectory()
|
|
1176
|
+
);
|
|
1177
|
+
let removed = 0;
|
|
1178
|
+
for (const dir of existingSkills) {
|
|
1179
|
+
if (!templateNames.has(dir)) {
|
|
1180
|
+
rmSync2(PATH9.resolve(skillsDir, dir), { recursive: true });
|
|
1181
|
+
removed++;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
return removed;
|
|
1185
|
+
};
|
|
1186
|
+
var logSkillsResult = (created, updated, removed) => {
|
|
1187
|
+
if (created || updated || removed) {
|
|
1188
|
+
const parts = [
|
|
1189
|
+
created ? `${created} created` : "",
|
|
1190
|
+
updated ? `${updated} updated` : "",
|
|
1191
|
+
removed ? `${removed} removed` : ""
|
|
1192
|
+
].filter(Boolean);
|
|
1193
|
+
console.log(chalk16.green(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: ${parts.join(", ")}`));
|
|
1194
|
+
} else {
|
|
1195
|
+
console.log(chalk16.gray(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: already up to date`));
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
var claudeSkills = () => {
|
|
1199
|
+
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
1200
|
+
const skillsDir = PATH9.resolve(cwd5, ".claude", "skills");
|
|
1201
|
+
mkdirSync4(skillsDir, { recursive: true });
|
|
1202
|
+
const {
|
|
1203
|
+
created,
|
|
1204
|
+
templateNames,
|
|
1205
|
+
updated
|
|
1206
|
+
} = syncSkillFiles(skillsDir);
|
|
1207
|
+
const removed = removeStaleSkills(skillsDir, templateNames);
|
|
1208
|
+
logSkillsResult(created, updated, removed);
|
|
1209
|
+
return 0;
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
// src/actions/clean.ts
|
|
1213
|
+
var clean = async ({ verbose, pkg }) => {
|
|
1214
|
+
return pkg ? await cleanPackage({ pkg, verbose }) : cleanAll({ verbose });
|
|
1215
|
+
};
|
|
1216
|
+
var cleanPackage = ({ pkg }) => {
|
|
1217
|
+
const pm = getPackageManager();
|
|
1218
|
+
return runStepsAsync(`Clean [${pkg}]`, [pm.runInWorkspace(pkg, "package-clean")]);
|
|
1219
|
+
};
|
|
1220
|
+
var cleanAll = ({ verbose }) => {
|
|
1221
|
+
const pm = getPackageManager();
|
|
1222
|
+
return runStepsAsync("Clean", [pm.foreachWorkspace("package-clean", [], { jobs: 64, verbose })]);
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1225
|
+
// src/actions/clean-docs.ts
|
|
1226
|
+
import path from "path";
|
|
1227
|
+
import chalk17 from "chalk";
|
|
1228
|
+
var cleanDocs = () => {
|
|
1229
|
+
const pkgName = process.env.npm_package_name;
|
|
1230
|
+
console.log(chalk17.green(`Cleaning Docs [${pkgName}]`));
|
|
1231
|
+
for (const { location } of getPackageManager().listWorkspaces()) deleteGlob(path.join(location, "docs"));
|
|
1232
|
+
return 0;
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
// src/actions/clean-eslint.ts
|
|
1236
|
+
import path2 from "path";
|
|
1237
|
+
import chalk18 from "chalk";
|
|
1238
|
+
var cleanESLint = () => {
|
|
1239
|
+
const pkg = process.env.INIT_CWD ?? ".";
|
|
1240
|
+
const pkgName = process.env.npm_package_name;
|
|
1241
|
+
console.log(chalk18.green(`Cleaning ESLint [${pkgName}]`));
|
|
1242
|
+
deleteGlob(path2.join(pkg, ".eslintcache"));
|
|
1243
|
+
return 0;
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
// src/actions/compile.ts
|
|
1247
|
+
import chalk19 from "chalk";
|
|
1248
|
+
var compile = ({
|
|
1249
|
+
verbose,
|
|
1250
|
+
target,
|
|
1251
|
+
pkg,
|
|
1252
|
+
incremental,
|
|
1253
|
+
publint: publint2,
|
|
1254
|
+
jobs
|
|
1255
|
+
}) => {
|
|
1256
|
+
return pkg ? compilePackage({
|
|
1257
|
+
pkg,
|
|
1258
|
+
publint: publint2,
|
|
1259
|
+
target,
|
|
1260
|
+
verbose
|
|
1261
|
+
}) : compileAll({
|
|
1262
|
+
incremental,
|
|
1263
|
+
jobs,
|
|
1264
|
+
publint: publint2,
|
|
1265
|
+
target,
|
|
1266
|
+
verbose
|
|
1267
|
+
});
|
|
1268
|
+
};
|
|
1269
|
+
var compilePackage = ({ target, pkg }) => {
|
|
1270
|
+
const pm = getPackageManager();
|
|
1271
|
+
const targetOptions = target ? ["-t", target] : [];
|
|
1272
|
+
return runSteps(
|
|
1273
|
+
`Compile [${pkg}]`,
|
|
1274
|
+
[pm.runInWorkspace(pkg, "package-compile", targetOptions)]
|
|
1275
|
+
);
|
|
1276
|
+
};
|
|
1277
|
+
var compileAll = ({
|
|
1278
|
+
jobs,
|
|
1279
|
+
verbose,
|
|
1280
|
+
target,
|
|
1281
|
+
incremental
|
|
1282
|
+
}) => {
|
|
1283
|
+
const pm = getPackageManager();
|
|
1284
|
+
const start = Date.now();
|
|
1285
|
+
const targetOptions = target ? ["-t", target] : [];
|
|
1286
|
+
if (jobs) {
|
|
1287
|
+
console.log(chalk19.blue(`Jobs set to [${jobs}]`));
|
|
1288
|
+
}
|
|
1289
|
+
const result = runSteps(`Compile${incremental ? "-Incremental" : ""} [All]`, [
|
|
1290
|
+
pm.foreachWorkspace("package-compile", targetOptions, {
|
|
1291
|
+
incremental,
|
|
1292
|
+
jobs,
|
|
1293
|
+
topological: true,
|
|
1294
|
+
verbose
|
|
1295
|
+
})
|
|
1296
|
+
]);
|
|
1297
|
+
console.log(`${chalk19.gray("Compiled in")} [${chalk19.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk19.gray("seconds")}`);
|
|
1298
|
+
return result;
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
// src/actions/copy-assets.ts
|
|
1302
|
+
import path3 from "path/posix";
|
|
1303
|
+
import chalk20 from "chalk";
|
|
1304
|
+
import cpy from "cpy";
|
|
1305
|
+
var copyPackageTargetAssets = async (target, name, location) => {
|
|
1306
|
+
try {
|
|
1307
|
+
const values = await cpy(
|
|
1308
|
+
["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
|
|
1309
|
+
`../dist/${target}`,
|
|
1310
|
+
{
|
|
1311
|
+
cwd: path3.join(process.cwd(), location, "src"),
|
|
1312
|
+
flat: false
|
|
1313
|
+
}
|
|
1314
|
+
);
|
|
1315
|
+
for (const value of values) {
|
|
1316
|
+
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
1317
|
+
}
|
|
1318
|
+
return 0;
|
|
1319
|
+
} catch (reason) {
|
|
1320
|
+
console.log(`Copy Failed: ${name}: ${reason}`);
|
|
1321
|
+
return 1;
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
var copyTargetAssets = async (target, pkg) => {
|
|
1325
|
+
const workspaces = getPackageManager().listWorkspaces();
|
|
1326
|
+
console.log(chalk20.green(`Copying Assets [${target.toUpperCase()}]`));
|
|
1327
|
+
const workspaceList = workspaces.filter(({ name }) => {
|
|
1328
|
+
return pkg === void 0 || name === pkg;
|
|
1329
|
+
});
|
|
1330
|
+
if (workspaceList.length === 0) {
|
|
1331
|
+
console.error(`Package not found [${pkg}]`);
|
|
1332
|
+
} else {
|
|
1333
|
+
const results = await Promise.all(
|
|
1334
|
+
workspaceList.map(async (workspace) => {
|
|
1335
|
+
const { location, name } = workspace;
|
|
1336
|
+
return await copyPackageTargetAssets(target, name, location);
|
|
1337
|
+
})
|
|
1338
|
+
);
|
|
1339
|
+
return results.reduce((prev, result) => prev || result, 0);
|
|
1340
|
+
}
|
|
1341
|
+
return 0;
|
|
1342
|
+
};
|
|
1343
|
+
var copyAssets = async ({ target, pkg }) => {
|
|
1344
|
+
switch (target) {
|
|
1345
|
+
case "esm": {
|
|
1346
|
+
return await copyTargetAssets("esm", pkg);
|
|
1347
|
+
}
|
|
1348
|
+
case "cjs": {
|
|
1349
|
+
return await copyTargetAssets("cjs", pkg);
|
|
1350
|
+
}
|
|
1351
|
+
default: {
|
|
1352
|
+
return await copyTargetAssets("esm", pkg) || await copyTargetAssets("cjs", pkg);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
// src/actions/cycle.ts
|
|
1358
|
+
import { cruise } from "dependency-cruiser";
|
|
1359
|
+
var cycle = async ({ verbose, pkg } = {}) => {
|
|
1360
|
+
return pkg ? cyclePackage({ pkg, verbose }) : await cycleAll({ verbose });
|
|
1361
|
+
};
|
|
1362
|
+
var cyclePackage = ({ pkg, verbose }) => {
|
|
1363
|
+
const pm = getPackageManager();
|
|
1364
|
+
const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
|
|
1365
|
+
return runSteps(
|
|
1366
|
+
`Cycle [${pkg}]`,
|
|
1367
|
+
[pm.runInWorkspace(pkg, "package-cycle", verboseOptions)]
|
|
1368
|
+
);
|
|
1369
|
+
};
|
|
1370
|
+
var cycleAll = async ({ verbose = false }) => {
|
|
1371
|
+
const pkgName = process.env.npm_package_name;
|
|
1372
|
+
const cruiseOptions = {
|
|
1373
|
+
ruleSet: {
|
|
1374
|
+
forbidden: [
|
|
1375
|
+
{
|
|
1376
|
+
name: "no-circular",
|
|
1377
|
+
severity: "error",
|
|
1378
|
+
comment: "This dependency creates a circular reference",
|
|
1379
|
+
from: {},
|
|
1380
|
+
to: { circular: true }
|
|
1381
|
+
}
|
|
1382
|
+
]
|
|
1383
|
+
},
|
|
1384
|
+
exclude: "node_modules|packages/.*/packages",
|
|
1385
|
+
validate: true,
|
|
1386
|
+
doNotFollow: { path: "node_modules|packages/.*/packages" },
|
|
1387
|
+
tsPreCompilationDeps: false,
|
|
1388
|
+
combinedDependencies: true,
|
|
1389
|
+
outputType: verbose ? "text" : "err"
|
|
1390
|
+
};
|
|
1391
|
+
const target = "**/packages/*/src";
|
|
1392
|
+
console.log(`Checking for circular dependencies in ${target}...`);
|
|
1393
|
+
const result = await cruise([target], cruiseOptions);
|
|
1394
|
+
if (result.output) {
|
|
1395
|
+
console.log(result.output);
|
|
1396
|
+
}
|
|
1397
|
+
if (result.exitCode === 0) {
|
|
1398
|
+
console.log(`${pkgName} \u2705 No dependency violations`);
|
|
1399
|
+
} else {
|
|
1400
|
+
console.error(`${pkgName} \u274C Dependency violations found`);
|
|
1401
|
+
}
|
|
1402
|
+
return result.exitCode;
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
// src/actions/dead.ts
|
|
1406
|
+
var dead = () => {
|
|
1407
|
+
return runSteps("Dead", [["ts-prune", ["-p", "tsconfig.json"]]]);
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
// src/actions/deplint/deplint.ts
|
|
1411
|
+
import chalk26 from "chalk";
|
|
1412
|
+
|
|
1413
|
+
// src/actions/deplint/findFiles.ts
|
|
1414
|
+
import fs2 from "fs";
|
|
1415
|
+
|
|
1416
|
+
// src/actions/deplint/findFilesByGlob.ts
|
|
1417
|
+
import { globSync } from "glob";
|
|
1418
|
+
function findFilesByGlob(cwd5, pattern, ignore) {
|
|
1419
|
+
return globSync(pattern, {
|
|
1420
|
+
cwd: cwd5,
|
|
1421
|
+
absolute: true,
|
|
1422
|
+
ignore,
|
|
1423
|
+
nodir: true
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// src/actions/deplint/findFiles.ts
|
|
1428
|
+
var codeExtensions = "*.{ts,tsx,mts,cts,js,mjs,cjs}";
|
|
1429
|
+
function getWorkspaceIgnores(location) {
|
|
1430
|
+
try {
|
|
1431
|
+
const raw = fs2.readFileSync(`${location}/package.json`, "utf8");
|
|
1432
|
+
const pkg = JSON.parse(raw);
|
|
1433
|
+
return pkg.workspaces ?? [];
|
|
1434
|
+
} catch {
|
|
1435
|
+
return [];
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
function findFiles(location) {
|
|
1439
|
+
const workspaceIgnores = getWorkspaceIgnores(location).map((w) => `${w}/**`);
|
|
1440
|
+
const ignore = ["**/node_modules/**", "dist/**", ...workspaceIgnores];
|
|
1441
|
+
const allFiles = findFilesByGlob(location, `./**/${codeExtensions}`, ignore);
|
|
1442
|
+
const distFiles = [
|
|
1443
|
+
...findFilesByGlob(location, "./dist/**/*.d.ts"),
|
|
1444
|
+
...findFilesByGlob(location, `./dist/**/${codeExtensions}`)
|
|
1445
|
+
];
|
|
1446
|
+
return { allFiles, distFiles };
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// src/actions/deplint/getDependenciesFromPackageJson.ts
|
|
1450
|
+
import fs3 from "fs";
|
|
1451
|
+
import path4 from "path";
|
|
1452
|
+
function getDependenciesFromPackageJson(packageJsonPath) {
|
|
1453
|
+
const packageJsonFullPath = path4.resolve(packageJsonPath);
|
|
1454
|
+
const rawContent = fs3.readFileSync(packageJsonFullPath, "utf8");
|
|
1455
|
+
const packageJson = JSON.parse(rawContent);
|
|
1456
|
+
const dependencies = packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
|
|
1457
|
+
const devDependencies = packageJson.devDependencies ? Object.keys(packageJson.devDependencies) : [];
|
|
1458
|
+
const peerDependencies = packageJson.peerDependencies ? Object.keys(packageJson.peerDependencies) : [];
|
|
1459
|
+
return {
|
|
1460
|
+
dependencies,
|
|
1461
|
+
devDependencies,
|
|
1462
|
+
peerDependencies
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// src/actions/deplint/getExtendsFromTsconfigs.ts
|
|
1467
|
+
import fs4 from "fs";
|
|
1468
|
+
import { globSync as globSync2 } from "glob";
|
|
1469
|
+
|
|
1470
|
+
// src/actions/deplint/getBasePackageName.ts
|
|
1471
|
+
function getBasePackageName(importName) {
|
|
1472
|
+
const importNameScrubbed = importName.replaceAll('"', "").trim();
|
|
1473
|
+
if (importNameScrubbed.startsWith("@")) {
|
|
1474
|
+
const parts = importNameScrubbed.split("/");
|
|
1475
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
|
|
1476
|
+
}
|
|
1477
|
+
return importNameScrubbed.split("/")[0];
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
// src/actions/deplint/getExtendsFromTsconfigs.ts
|
|
1481
|
+
var isExternalReference = (ref) => !ref.startsWith(".") && !ref.startsWith("/");
|
|
1482
|
+
function parseExtendsField(value) {
|
|
1483
|
+
if (typeof value === "string") return [value];
|
|
1484
|
+
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
1485
|
+
return [];
|
|
1486
|
+
}
|
|
1487
|
+
function getExtendsFromTsconfigs(location) {
|
|
1488
|
+
const tsconfigFiles = globSync2("./tsconfig*.json", { cwd: location, absolute: true });
|
|
1489
|
+
const packages = /* @__PURE__ */ new Set();
|
|
1490
|
+
for (const file of tsconfigFiles) {
|
|
1491
|
+
try {
|
|
1492
|
+
const content = fs4.readFileSync(file, "utf8");
|
|
1493
|
+
const cleaned = content.replaceAll(/\/\/.*/g, "").replaceAll(/,\s*([}\]])/g, "$1");
|
|
1494
|
+
const parsed = JSON.parse(cleaned);
|
|
1495
|
+
const refs = parseExtendsField(parsed.extends);
|
|
1496
|
+
for (const ref of refs) {
|
|
1497
|
+
if (isExternalReference(ref)) {
|
|
1498
|
+
packages.add(getBasePackageName(ref));
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
} catch {
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
return [...packages];
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
// src/actions/deplint/getImportsFromFile.ts
|
|
1508
|
+
import fs5 from "fs";
|
|
1509
|
+
import path5 from "path";
|
|
1510
|
+
import ts from "typescript";
|
|
1511
|
+
function isTypeOnlyImportClause(clause) {
|
|
1512
|
+
if (clause === void 0) {
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
if ("phaseModifier" in clause) {
|
|
1516
|
+
const mod = clause.phaseModifier;
|
|
1517
|
+
const kind = typeof mod === "number" ? mod : mod?.kind;
|
|
1518
|
+
return kind === ts.SyntaxKind.TypeKeyword;
|
|
1519
|
+
}
|
|
1520
|
+
return clause.isTypeOnly;
|
|
1521
|
+
}
|
|
1522
|
+
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
1523
|
+
const sourceCode = fs5.readFileSync(filePath, "utf8");
|
|
1524
|
+
const isMjsFile = filePath.endsWith(".mjs");
|
|
1525
|
+
const sourceFile = ts.createSourceFile(
|
|
1526
|
+
path5.basename(filePath),
|
|
1527
|
+
sourceCode,
|
|
1528
|
+
ts.ScriptTarget.Latest,
|
|
1529
|
+
true,
|
|
1530
|
+
isMjsFile ? ts.ScriptKind.JS : void 0
|
|
1531
|
+
);
|
|
1532
|
+
const imports = [];
|
|
1533
|
+
const typeImports = [];
|
|
1534
|
+
const isDeclarationFile2 = filePath.endsWith(".d.ts");
|
|
1535
|
+
function visit(node) {
|
|
1536
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
1537
|
+
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
1538
|
+
const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
|
|
1539
|
+
if (typeof moduleSpecifier === "string") {
|
|
1540
|
+
const trimmed = moduleSpecifier.replaceAll("'", "").replaceAll('"', "").trim();
|
|
1541
|
+
if (isTypeImport || isDeclarationFile2) {
|
|
1542
|
+
typeImports.push(trimmed);
|
|
1543
|
+
} else {
|
|
1544
|
+
imports.push(trimmed);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
} else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
1548
|
+
const [arg] = node.arguments;
|
|
1549
|
+
if (ts.isStringLiteral(arg)) {
|
|
1550
|
+
imports.push(arg.text);
|
|
1551
|
+
}
|
|
1552
|
+
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) {
|
|
1553
|
+
imports.push(node.arguments[0].text);
|
|
1554
|
+
}
|
|
1555
|
+
ts.forEachChild(node, visit);
|
|
1556
|
+
}
|
|
1557
|
+
visit(sourceFile);
|
|
1558
|
+
for (const ref of sourceFile.typeReferenceDirectives) {
|
|
1559
|
+
typeImports.push(ref.fileName);
|
|
1560
|
+
}
|
|
1561
|
+
const importsStartsWithExcludes = [".", "#", "node:"];
|
|
1562
|
+
const isValidImport = (imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
|
|
1563
|
+
const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
|
|
1564
|
+
const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
|
|
1565
|
+
for (const imp of cleanedImports) {
|
|
1566
|
+
importPaths[imp] = importPaths[imp] ?? [];
|
|
1567
|
+
importPaths[imp].push(filePath);
|
|
1568
|
+
}
|
|
1569
|
+
for (const imp of cleanedTypeImports) {
|
|
1570
|
+
typeImportPaths[imp] = typeImportPaths[imp] ?? [];
|
|
1571
|
+
typeImportPaths[imp].push(filePath);
|
|
1572
|
+
}
|
|
1573
|
+
return [cleanedImports, cleanedTypeImports];
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
// src/actions/deplint/getExternalImportsFromFiles.ts
|
|
1577
|
+
var internalImportPrefixes = [".", "#", "node:"];
|
|
1578
|
+
var removeInternalImports = (imports) => {
|
|
1579
|
+
return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
|
|
1580
|
+
};
|
|
1581
|
+
var isDeclarationFile = (file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts");
|
|
1582
|
+
function getExternalImportsFromFiles({
|
|
1583
|
+
allFiles,
|
|
1584
|
+
distFiles,
|
|
1585
|
+
tsconfigExtends = []
|
|
1586
|
+
}) {
|
|
1587
|
+
const allImportPaths = {};
|
|
1588
|
+
const distImportPaths = {};
|
|
1589
|
+
const distTypeImportPaths = {};
|
|
1590
|
+
for (const path15 of allFiles) getImportsFromFile(path15, allImportPaths, allImportPaths).flat();
|
|
1591
|
+
const distTypeFiles = distFiles.filter(isDeclarationFile);
|
|
1592
|
+
const distCodeFiles = distFiles.filter((file) => !isDeclarationFile(file));
|
|
1593
|
+
for (const path15 of distCodeFiles) getImportsFromFile(path15, distImportPaths, distImportPaths).flat();
|
|
1594
|
+
for (const path15 of distTypeFiles) getImportsFromFile(path15, distTypeImportPaths, distTypeImportPaths).flat();
|
|
1595
|
+
const allImports = Object.keys(allImportPaths);
|
|
1596
|
+
const distImports = Object.keys(distImportPaths);
|
|
1597
|
+
const externalAllImports = removeInternalImports(allImports);
|
|
1598
|
+
const externalDistImports = removeInternalImports(distImports);
|
|
1599
|
+
const externalDistTypeImports = removeInternalImports(Object.keys(distTypeImportPaths));
|
|
1600
|
+
for (const ext of tsconfigExtends) {
|
|
1601
|
+
if (!externalAllImports.includes(ext)) externalAllImports.push(ext);
|
|
1602
|
+
}
|
|
1603
|
+
return {
|
|
1604
|
+
allImportPaths,
|
|
1605
|
+
allImports,
|
|
1606
|
+
distImportPaths,
|
|
1607
|
+
distImports,
|
|
1608
|
+
externalAllImports,
|
|
1609
|
+
externalDistImports,
|
|
1610
|
+
externalDistTypeImports
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
1615
|
+
import { builtinModules } from "module";
|
|
1616
|
+
import chalk21 from "chalk";
|
|
1617
|
+
function isRuntimeImportListed(imp, name, dependencies, peerDependencies) {
|
|
1618
|
+
return dependencies.includes(imp) || imp === name || peerDependencies.includes(imp) || builtinModules.includes(imp);
|
|
1619
|
+
}
|
|
1620
|
+
function isTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies) {
|
|
1621
|
+
return dependencies.includes(imp) || imp === name || dependencies.includes(`@types/${imp}`) || peerDependencies.includes(imp) || peerDependencies.includes(`@types/${imp}`) || devDependencies.includes(`@types/${imp}`) || builtinModules.includes(imp);
|
|
1622
|
+
}
|
|
1623
|
+
function logMissing(name, imp, importPaths) {
|
|
1624
|
+
console.log(`[${chalk21.blue(name)}] Missing dependency in package.json: ${chalk21.red(imp)}`);
|
|
1625
|
+
if (importPaths[imp]) {
|
|
1626
|
+
console.log(` ${importPaths[imp].join("\n ")}`);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
function getUnlistedDependencies({ name, location }, {
|
|
1630
|
+
dependencies,
|
|
1631
|
+
devDependencies,
|
|
1632
|
+
peerDependencies
|
|
1633
|
+
}, {
|
|
1634
|
+
externalDistImports,
|
|
1635
|
+
externalDistTypeImports,
|
|
1636
|
+
distImportPaths
|
|
1637
|
+
}) {
|
|
1638
|
+
let unlistedDependencies = 0;
|
|
1639
|
+
for (const imp of externalDistImports) {
|
|
1640
|
+
if (!isRuntimeImportListed(imp, name, dependencies, peerDependencies)) {
|
|
1641
|
+
unlistedDependencies++;
|
|
1642
|
+
logMissing(name, imp, distImportPaths);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
for (const imp of externalDistTypeImports) {
|
|
1646
|
+
if (!isTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies)) {
|
|
1647
|
+
unlistedDependencies++;
|
|
1648
|
+
logMissing(name, imp, distImportPaths);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (unlistedDependencies > 0) {
|
|
1652
|
+
const packageLocation = `${location}/package.json`;
|
|
1653
|
+
console.log(` ${chalk21.yellow(packageLocation)}
|
|
1654
|
+
`);
|
|
1655
|
+
}
|
|
1656
|
+
return unlistedDependencies;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
1660
|
+
import { builtinModules as builtinModules2 } from "module";
|
|
1661
|
+
import chalk22 from "chalk";
|
|
1662
|
+
function getUnlistedDevDependencies({ name, location }, {
|
|
1663
|
+
devDependencies,
|
|
1664
|
+
dependencies,
|
|
1665
|
+
peerDependencies
|
|
1666
|
+
}, {
|
|
1667
|
+
allImportPaths,
|
|
1668
|
+
externalAllImports,
|
|
1669
|
+
distImports
|
|
1670
|
+
}) {
|
|
1671
|
+
let unlistedDevDependencies = 0;
|
|
1672
|
+
for (const imp of externalAllImports) {
|
|
1673
|
+
if (!distImports.includes(imp) && imp !== name && !dependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(imp) && !peerDependencies.includes(`@types/${imp}`) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`) && !builtinModules2.includes(imp)) {
|
|
1674
|
+
unlistedDevDependencies++;
|
|
1675
|
+
console.log(`[${chalk22.blue(name)}] Missing devDependency in package.json: ${chalk22.red(imp)}`);
|
|
1676
|
+
if (allImportPaths[imp]) {
|
|
1677
|
+
console.log(` ${allImportPaths[imp].join("\n ")}`);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
if (unlistedDevDependencies > 0) {
|
|
1682
|
+
const packageLocation = `${location}/package.json`;
|
|
1683
|
+
console.log(` ${chalk22.yellow(packageLocation)}
|
|
1684
|
+
`);
|
|
1685
|
+
}
|
|
1686
|
+
return unlistedDevDependencies;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
1690
|
+
import chalk23 from "chalk";
|
|
1691
|
+
function getUnusedDependencies({ name, location }, { dependencies }, {
|
|
1692
|
+
externalDistImports,
|
|
1693
|
+
externalDistTypeImports,
|
|
1694
|
+
externalAllImports
|
|
1695
|
+
}, exclude) {
|
|
1696
|
+
let unusedDependencies = 0;
|
|
1697
|
+
for (const dep of dependencies) {
|
|
1698
|
+
if (exclude?.has(dep)) continue;
|
|
1699
|
+
if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
|
|
1700
|
+
unusedDependencies++;
|
|
1701
|
+
if (externalAllImports.includes(dep)) {
|
|
1702
|
+
console.log(`[${chalk23.blue(name)}] dependency should be devDependency in package.json: ${chalk23.red(dep)}`);
|
|
1703
|
+
} else {
|
|
1704
|
+
console.log(`[${chalk23.blue(name)}] Unused dependency in package.json: ${chalk23.red(dep)}`);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
if (unusedDependencies > 0) {
|
|
1709
|
+
const packageLocation = `${location}/package.json`;
|
|
1710
|
+
console.log(` ${chalk23.yellow(packageLocation)}
|
|
1711
|
+
`);
|
|
1712
|
+
}
|
|
1713
|
+
return unusedDependencies;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
|
|
1717
|
+
import chalk24 from "chalk";
|
|
1718
|
+
|
|
1719
|
+
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
1720
|
+
import fs8 from "fs";
|
|
1721
|
+
import path8 from "path";
|
|
1722
|
+
import ts2 from "typescript";
|
|
1723
|
+
|
|
1724
|
+
// src/actions/deplint/getScriptReferencedPackages.ts
|
|
1725
|
+
import fs7 from "fs";
|
|
1726
|
+
import path7 from "path";
|
|
1727
|
+
|
|
1728
|
+
// src/actions/deplint/getRequiredPeerDependencies.ts
|
|
1729
|
+
import fs6 from "fs";
|
|
1730
|
+
import path6 from "path";
|
|
1731
|
+
function findDepPackageJson(location, dep) {
|
|
1732
|
+
let dir = location;
|
|
1733
|
+
while (true) {
|
|
1734
|
+
const candidate = path6.join(dir, "node_modules", dep, "package.json");
|
|
1735
|
+
if (fs6.existsSync(candidate)) return candidate;
|
|
1736
|
+
const parent = path6.dirname(dir);
|
|
1737
|
+
if (parent === dir) return void 0;
|
|
1738
|
+
dir = parent;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
function getRequiredPeerDependencies(location, allDeps) {
|
|
1742
|
+
const required = /* @__PURE__ */ new Set();
|
|
1743
|
+
for (const dep of allDeps) {
|
|
1744
|
+
const depPkgPath = findDepPackageJson(location, dep);
|
|
1745
|
+
if (!depPkgPath) continue;
|
|
1746
|
+
try {
|
|
1747
|
+
const raw = fs6.readFileSync(depPkgPath, "utf8");
|
|
1748
|
+
const pkg = JSON.parse(raw);
|
|
1749
|
+
if (pkg.peerDependencies) {
|
|
1750
|
+
for (const peer of Object.keys(pkg.peerDependencies)) {
|
|
1751
|
+
required.add(peer);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
} catch {
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
return required;
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
// src/actions/deplint/getScriptReferencedPackages.ts
|
|
1761
|
+
function getBinNames(location, dep) {
|
|
1762
|
+
const depPkgPath = findDepPackageJson(location, dep);
|
|
1763
|
+
if (!depPkgPath) return [];
|
|
1764
|
+
try {
|
|
1765
|
+
const raw = fs7.readFileSync(depPkgPath, "utf8");
|
|
1766
|
+
const pkg = JSON.parse(raw);
|
|
1767
|
+
if (!pkg.bin) return [];
|
|
1768
|
+
if (typeof pkg.bin === "string") return [pkg.name?.split("/").pop() ?? dep];
|
|
1769
|
+
return Object.keys(pkg.bin);
|
|
1770
|
+
} catch {
|
|
1771
|
+
return [];
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
function tokenizeScript(script) {
|
|
1775
|
+
return script.split(/[&|;$()"`\s]+/).map((t) => t.trim()).filter(Boolean);
|
|
1776
|
+
}
|
|
1777
|
+
function getScriptReferencedPackages(location, allDeps) {
|
|
1778
|
+
const pkgPath = path7.join(location, "package.json");
|
|
1779
|
+
let scripts = {};
|
|
1780
|
+
try {
|
|
1781
|
+
const raw = fs7.readFileSync(pkgPath, "utf8");
|
|
1782
|
+
const pkg = JSON.parse(raw);
|
|
1783
|
+
scripts = pkg.scripts ?? {};
|
|
1784
|
+
} catch {
|
|
1785
|
+
return /* @__PURE__ */ new Set();
|
|
1786
|
+
}
|
|
1787
|
+
const scriptText = Object.values(scripts).join(" ");
|
|
1788
|
+
const tokens = new Set(tokenizeScript(scriptText));
|
|
1789
|
+
const binToPackage = /* @__PURE__ */ new Map();
|
|
1790
|
+
for (const dep of allDeps) {
|
|
1791
|
+
const bins = getBinNames(location, dep);
|
|
1792
|
+
for (const bin of bins) {
|
|
1793
|
+
binToPackage.set(bin, dep);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
1797
|
+
for (const token of tokens) {
|
|
1798
|
+
const baseName = getBasePackageName(token);
|
|
1799
|
+
if (allDeps.includes(baseName)) {
|
|
1800
|
+
referenced.add(baseName);
|
|
1801
|
+
}
|
|
1802
|
+
const pkg = binToPackage.get(token);
|
|
1803
|
+
if (pkg) {
|
|
1804
|
+
referenced.add(pkg);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return referenced;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
1811
|
+
var shellCommandFunctions = /* @__PURE__ */ new Set(["execSync", "exec"]);
|
|
1812
|
+
var directExecFunctions = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
|
|
1813
|
+
var allExecFunctions = /* @__PURE__ */ new Set([...shellCommandFunctions, ...directExecFunctions]);
|
|
1814
|
+
function getCommandTokensFromFile(filePath) {
|
|
1815
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
1816
|
+
let sourceCode;
|
|
1817
|
+
try {
|
|
1818
|
+
sourceCode = fs8.readFileSync(filePath, "utf8");
|
|
1819
|
+
} catch {
|
|
1820
|
+
return tokens;
|
|
1821
|
+
}
|
|
1822
|
+
const isMjsFile = filePath.endsWith(".mjs");
|
|
1823
|
+
const sourceFile = ts2.createSourceFile(
|
|
1824
|
+
path8.basename(filePath),
|
|
1825
|
+
sourceCode,
|
|
1826
|
+
ts2.ScriptTarget.Latest,
|
|
1827
|
+
true,
|
|
1828
|
+
isMjsFile ? ts2.ScriptKind.JS : void 0
|
|
1829
|
+
);
|
|
1830
|
+
function visit(node) {
|
|
1831
|
+
if (ts2.isCallExpression(node) && node.arguments.length > 0) {
|
|
1832
|
+
const fnName = getFunctionName(node.expression);
|
|
1833
|
+
if (fnName && allExecFunctions.has(fnName)) {
|
|
1834
|
+
const firstArg = node.arguments[0];
|
|
1835
|
+
if (ts2.isStringLiteral(firstArg) || ts2.isNoSubstitutionTemplateLiteral(firstArg)) {
|
|
1836
|
+
const value = firstArg.text;
|
|
1837
|
+
if (shellCommandFunctions.has(fnName)) {
|
|
1838
|
+
for (const token of tokenizeScript(value)) {
|
|
1839
|
+
tokens.add(token);
|
|
1840
|
+
}
|
|
1841
|
+
} else {
|
|
1842
|
+
tokens.add(value);
|
|
1843
|
+
}
|
|
1844
|
+
} else if (ts2.isTemplateExpression(firstArg)) {
|
|
1845
|
+
const head = firstArg.head.text;
|
|
1846
|
+
if (head) {
|
|
1847
|
+
for (const token of tokenizeScript(head)) {
|
|
1848
|
+
tokens.add(token);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
ts2.forEachChild(node, visit);
|
|
1855
|
+
}
|
|
1856
|
+
visit(sourceFile);
|
|
1857
|
+
return tokens;
|
|
1858
|
+
}
|
|
1859
|
+
function getFunctionName(expr) {
|
|
1860
|
+
if (ts2.isIdentifier(expr)) {
|
|
1861
|
+
return expr.text;
|
|
1862
|
+
}
|
|
1863
|
+
if (ts2.isPropertyAccessExpression(expr) && ts2.isIdentifier(expr.name)) {
|
|
1864
|
+
return expr.name.text;
|
|
1865
|
+
}
|
|
1866
|
+
return void 0;
|
|
1867
|
+
}
|
|
1868
|
+
function getCliReferencedPackagesFromFiles(allFiles, location, allDeps) {
|
|
1869
|
+
const allTokens = /* @__PURE__ */ new Set();
|
|
1870
|
+
for (const file of allFiles) {
|
|
1871
|
+
for (const token of getCommandTokensFromFile(file)) {
|
|
1872
|
+
allTokens.add(token);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
if (allTokens.size === 0) return /* @__PURE__ */ new Set();
|
|
1876
|
+
const binToPackage = /* @__PURE__ */ new Map();
|
|
1877
|
+
for (const dep of allDeps) {
|
|
1878
|
+
for (const bin of getBinNames(location, dep)) {
|
|
1879
|
+
binToPackage.set(bin, dep);
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
1883
|
+
for (const token of allTokens) {
|
|
1884
|
+
const baseName = getBasePackageName(token);
|
|
1885
|
+
if (allDeps.includes(baseName)) {
|
|
1886
|
+
referenced.add(baseName);
|
|
1887
|
+
}
|
|
1888
|
+
const pkg = binToPackage.get(token);
|
|
1889
|
+
if (pkg) {
|
|
1890
|
+
referenced.add(pkg);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
return referenced;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
// src/actions/deplint/implicitDevDependencies.ts
|
|
1897
|
+
import fs9 from "fs";
|
|
1898
|
+
var hasFileWithExtension = (files, extensions) => files.some((f) => extensions.some((ext) => f.endsWith(ext)));
|
|
1899
|
+
var tsExtensions = [".ts", ".tsx", ".mts", ".cts"];
|
|
1900
|
+
var hasTypescriptFiles = ({ allFiles }) => hasFileWithExtension(allFiles, tsExtensions);
|
|
1901
|
+
var decoratorPattern = /^\s*@[a-zA-Z]\w*/m;
|
|
1902
|
+
var hasDecorators = ({ allFiles }) => allFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
|
|
1903
|
+
try {
|
|
1904
|
+
const content = fs9.readFileSync(file, "utf8");
|
|
1905
|
+
return decoratorPattern.test(content);
|
|
1906
|
+
} catch {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
});
|
|
1910
|
+
var importPlugins = /* @__PURE__ */ new Set(["eslint-plugin-import-x", "eslint-plugin-import"]);
|
|
1911
|
+
function hasImportPlugin({ location, allDependencies }) {
|
|
1912
|
+
if (allDependencies.some((d) => importPlugins.has(d))) return true;
|
|
1913
|
+
for (const dep of allDependencies) {
|
|
1914
|
+
const pkgPath = findDepPackageJson(location, dep);
|
|
1915
|
+
if (!pkgPath) continue;
|
|
1916
|
+
try {
|
|
1917
|
+
const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
|
|
1918
|
+
const transitiveDeps = [
|
|
1919
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
1920
|
+
...Object.keys(pkg.peerDependencies ?? {})
|
|
1921
|
+
];
|
|
1922
|
+
if (transitiveDeps.some((d) => importPlugins.has(d))) return true;
|
|
1923
|
+
} catch {
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
return false;
|
|
1927
|
+
}
|
|
1928
|
+
var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
|
|
1929
|
+
var rules = [
|
|
1930
|
+
{
|
|
1931
|
+
package: "typescript",
|
|
1932
|
+
isNeeded: hasTypescriptFiles
|
|
1933
|
+
},
|
|
1934
|
+
{
|
|
1935
|
+
package: "eslint-import-resolver-typescript",
|
|
1936
|
+
isNeeded: (context) => hasTypescriptFiles(context) && context.allDependencies.includes("eslint") && hasImportPlugin(context)
|
|
1937
|
+
},
|
|
1938
|
+
{
|
|
1939
|
+
package: "tslib",
|
|
1940
|
+
isNeeded: hasDecorators
|
|
1941
|
+
},
|
|
1942
|
+
{
|
|
1943
|
+
package: "@vitest/coverage-v8",
|
|
1944
|
+
isNeeded: hasVitest
|
|
1945
|
+
}
|
|
1946
|
+
];
|
|
1947
|
+
function getImplicitDevDependencies(context) {
|
|
1948
|
+
const implicit = /* @__PURE__ */ new Set();
|
|
1949
|
+
for (const rule of rules) {
|
|
1950
|
+
if (rule.isNeeded(context)) {
|
|
1951
|
+
implicit.add(rule.package);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
return implicit;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
|
|
1958
|
+
var allExternalImports = ({
|
|
1959
|
+
externalAllImports,
|
|
1960
|
+
externalDistImports,
|
|
1961
|
+
externalDistTypeImports
|
|
1962
|
+
}) => {
|
|
1963
|
+
return /* @__PURE__ */ new Set([
|
|
1964
|
+
...externalAllImports,
|
|
1965
|
+
...externalDistImports,
|
|
1966
|
+
...externalDistTypeImports
|
|
1967
|
+
]);
|
|
1968
|
+
};
|
|
1969
|
+
function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs) {
|
|
1970
|
+
if (implicitDeps.has(dep)) return true;
|
|
1971
|
+
if (requiredPeers.has(dep)) return true;
|
|
1972
|
+
if (scriptRefs.has(dep)) return true;
|
|
1973
|
+
if (cliRefs.has(dep)) return true;
|
|
1974
|
+
if (dep.startsWith("@types/")) {
|
|
1975
|
+
const baseName = dep.replace(/^@types\//, "");
|
|
1976
|
+
return allImports.has(baseName) || allImports.has(dep) || implicitDeps.has(baseName);
|
|
1977
|
+
}
|
|
1978
|
+
return allImports.has(dep);
|
|
1979
|
+
}
|
|
1980
|
+
function getUnusedDevDependencies({ name, location }, {
|
|
1981
|
+
devDependencies,
|
|
1982
|
+
dependencies,
|
|
1983
|
+
peerDependencies
|
|
1984
|
+
}, sourceParams, fileContext, exclude) {
|
|
1985
|
+
const allImports = allExternalImports(sourceParams);
|
|
1986
|
+
const allDeps = [...dependencies, ...devDependencies, ...peerDependencies];
|
|
1987
|
+
const implicitDeps = getImplicitDevDependencies({
|
|
1988
|
+
...fileContext,
|
|
1989
|
+
allDependencies: allDeps,
|
|
1990
|
+
location
|
|
1991
|
+
});
|
|
1992
|
+
const requiredPeers = getRequiredPeerDependencies(location, allDeps);
|
|
1993
|
+
const scriptRefs = getScriptReferencedPackages(location, allDeps);
|
|
1994
|
+
const cliRefs = getCliReferencedPackagesFromFiles(fileContext.allFiles, location, allDeps);
|
|
1995
|
+
let unusedDevDependencies = 0;
|
|
1996
|
+
for (const dep of devDependencies) {
|
|
1997
|
+
if (exclude?.has(dep)) continue;
|
|
1998
|
+
if (dependencies.includes(dep) || peerDependencies.includes(dep)) continue;
|
|
1999
|
+
if (!isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs)) {
|
|
2000
|
+
unusedDevDependencies++;
|
|
2001
|
+
console.log(`[${chalk24.blue(name)}] Unused devDependency in package.json: ${chalk24.red(dep)}`);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
if (unusedDevDependencies > 0) {
|
|
2005
|
+
const packageLocation = `${location}/package.json`;
|
|
2006
|
+
console.log(` ${chalk24.yellow(packageLocation)}
|
|
2007
|
+
`);
|
|
2008
|
+
}
|
|
2009
|
+
return unusedDevDependencies;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
2013
|
+
import chalk25 from "chalk";
|
|
2014
|
+
function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports, externalDistTypeImports }, exclude) {
|
|
2015
|
+
let unusedDependencies = 0;
|
|
2016
|
+
for (const dep of peerDependencies) {
|
|
2017
|
+
if (exclude?.has(dep)) continue;
|
|
2018
|
+
if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
|
|
2019
|
+
unusedDependencies++;
|
|
2020
|
+
if (dependencies.includes(dep)) {
|
|
2021
|
+
console.log(`[${chalk25.blue(name)}] Unused peerDependency [already a dependency] in package.json: ${chalk25.red(dep)}`);
|
|
2022
|
+
} else {
|
|
2023
|
+
console.log(`[${chalk25.blue(name)}] Unused peerDependency in package.json: ${chalk25.red(dep)}`);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
if (unusedDependencies > 0) {
|
|
2028
|
+
const packageLocation = `${location}/package.json`;
|
|
2029
|
+
console.log(` ${chalk25.yellow(packageLocation)}
|
|
2030
|
+
`);
|
|
2031
|
+
}
|
|
2032
|
+
return unusedDependencies;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
// src/actions/deplint/checkPackage/checkPackage.ts
|
|
2036
|
+
function logVerbose(name, location, allFiles, distFiles, tsconfigExtends) {
|
|
2037
|
+
console.info(`Checking package: ${name} at ${location}`);
|
|
2038
|
+
console.info(`All files: ${allFiles.length}, Distribution files: ${distFiles.length}`);
|
|
2039
|
+
for (const file of allFiles) {
|
|
2040
|
+
console.info(`File: ${file}`);
|
|
2041
|
+
}
|
|
2042
|
+
for (const file of distFiles) {
|
|
2043
|
+
console.info(`Distribution file: ${file}`);
|
|
2044
|
+
}
|
|
2045
|
+
for (const ext of tsconfigExtends) {
|
|
2046
|
+
console.info(`Tsconfig extends: ${ext}`);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
function checkPackage({
|
|
2050
|
+
name,
|
|
2051
|
+
location,
|
|
2052
|
+
deps = false,
|
|
2053
|
+
devDeps = false,
|
|
2054
|
+
exclude,
|
|
2055
|
+
peerDeps = false,
|
|
2056
|
+
verbose = false
|
|
2057
|
+
}) {
|
|
2058
|
+
const { allFiles, distFiles } = findFiles(location);
|
|
2059
|
+
const tsconfigExtends = getExtendsFromTsconfigs(location);
|
|
2060
|
+
if (verbose) {
|
|
2061
|
+
logVerbose(name, location, allFiles, distFiles, tsconfigExtends);
|
|
2062
|
+
}
|
|
2063
|
+
const checkDeps = deps || !(deps || devDeps || peerDeps);
|
|
2064
|
+
const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
|
|
2065
|
+
const checkPeerDeps = peerDeps;
|
|
2066
|
+
const sourceParams = getExternalImportsFromFiles({
|
|
2067
|
+
allFiles,
|
|
2068
|
+
distFiles,
|
|
2069
|
+
tsconfigExtends
|
|
2070
|
+
});
|
|
2071
|
+
const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
2072
|
+
const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
2073
|
+
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
|
|
2074
|
+
const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
2075
|
+
const fileContext = { allFiles, distFiles };
|
|
2076
|
+
const unusedDevDependencies = checkDevDeps ? getUnusedDevDependencies({ name, location }, packageParams, sourceParams, fileContext, exclude) : 0;
|
|
2077
|
+
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
|
|
2078
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedDevDependencies + unusedPeerDependencies;
|
|
2079
|
+
return totalErrors;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
// src/actions/deplint/deplint.ts
|
|
2083
|
+
var deplint = async ({
|
|
2084
|
+
pkg,
|
|
2085
|
+
deps,
|
|
2086
|
+
devDeps,
|
|
2087
|
+
peerDeps,
|
|
2088
|
+
verbose,
|
|
2089
|
+
cliExclude
|
|
2090
|
+
}) => {
|
|
2091
|
+
const config2 = await loadConfig();
|
|
2092
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
2093
|
+
...config2.deplint?.exclude ?? [],
|
|
2094
|
+
...cliExclude ?? []
|
|
2095
|
+
]);
|
|
2096
|
+
let totalErrors = 0;
|
|
2097
|
+
if (pkg === void 0) {
|
|
2098
|
+
const workspaces = getPackageManager().listWorkspaces();
|
|
2099
|
+
console.info("Deplint Started...");
|
|
2100
|
+
for (const workspace of workspaces) {
|
|
2101
|
+
totalErrors += checkPackage({
|
|
2102
|
+
...workspace,
|
|
2103
|
+
deps,
|
|
2104
|
+
devDeps,
|
|
2105
|
+
exclude,
|
|
2106
|
+
peerDeps,
|
|
2107
|
+
verbose
|
|
2108
|
+
});
|
|
2109
|
+
}
|
|
2110
|
+
} else {
|
|
2111
|
+
const workspace = getPackageManager().findWorkspace(pkg);
|
|
2112
|
+
if (!workspace) {
|
|
2113
|
+
console.error(chalk26.red(`Workspace not found: ${pkg}`));
|
|
2114
|
+
return 1;
|
|
2115
|
+
}
|
|
2116
|
+
const { location, name } = workspace;
|
|
2117
|
+
console.info(`Running Deplint for ${name}`);
|
|
2118
|
+
totalErrors += checkPackage({
|
|
2119
|
+
name,
|
|
2120
|
+
location,
|
|
2121
|
+
devDeps,
|
|
2122
|
+
deps,
|
|
2123
|
+
exclude,
|
|
2124
|
+
peerDeps,
|
|
2125
|
+
verbose
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
if (totalErrors > 0) {
|
|
2129
|
+
console.warn(`Deplint: Found ${chalk26.red(totalErrors)} dependency problems. ${chalk26.red("\u2716")}`);
|
|
2130
|
+
} else {
|
|
2131
|
+
console.info(`Deplint: Found no dependency problems. ${chalk26.green("\u2714")}`);
|
|
2132
|
+
}
|
|
2133
|
+
return 0;
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
// src/actions/dupdeps.ts
|
|
2137
|
+
import chalk27 from "chalk";
|
|
2138
|
+
var dupdeps = () => {
|
|
2139
|
+
console.log(chalk27.green("Checking all Dependencies for Duplicates"));
|
|
2140
|
+
const pkg = parsedPackageJSON();
|
|
2141
|
+
const allDependencies = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
2142
|
+
const dependencies = Object.keys(allDependencies);
|
|
2143
|
+
return detectDuplicateDependencies(dependencies);
|
|
2144
|
+
};
|
|
2145
|
+
|
|
2146
|
+
// src/actions/lint.ts
|
|
2147
|
+
import chalk28 from "chalk";
|
|
2148
|
+
var lintPackage = ({
|
|
2149
|
+
pkg,
|
|
2150
|
+
fix: fix2,
|
|
2151
|
+
verbose
|
|
2152
|
+
}) => {
|
|
2153
|
+
console.log(chalk28.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
2154
|
+
const start = Date.now();
|
|
2155
|
+
const pm = getPackageManager();
|
|
2156
|
+
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
2157
|
+
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
2158
|
+
]);
|
|
2159
|
+
console.log(chalk28.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk28.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk28.gray("seconds")}`));
|
|
2160
|
+
return result;
|
|
2161
|
+
};
|
|
2162
|
+
var lint = ({
|
|
2163
|
+
pkg,
|
|
2164
|
+
verbose,
|
|
2165
|
+
incremental,
|
|
2166
|
+
fix: fix2
|
|
2167
|
+
} = {}) => {
|
|
2168
|
+
return pkg === void 0 ? lintAllPackages({
|
|
2169
|
+
verbose,
|
|
2170
|
+
incremental,
|
|
2171
|
+
fix: fix2
|
|
2172
|
+
}) : lintPackage({
|
|
2173
|
+
pkg,
|
|
2174
|
+
fix: fix2,
|
|
2175
|
+
verbose
|
|
2176
|
+
});
|
|
2177
|
+
};
|
|
2178
|
+
var lintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
2179
|
+
console.log(chalk28.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
2180
|
+
const start = Date.now();
|
|
2181
|
+
const fixOptions = fix2 ? ["--fix"] : [];
|
|
2182
|
+
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
2183
|
+
["eslint", ["--cache", "--cache-location", ".eslintcache", "--cache-strategy", "content", ...fixOptions]]
|
|
2184
|
+
]);
|
|
2185
|
+
console.log(chalk28.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk28.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk28.gray("seconds")}`));
|
|
2186
|
+
return result;
|
|
2187
|
+
};
|
|
2188
|
+
|
|
2189
|
+
// src/actions/fix.ts
|
|
2190
|
+
var fix = (params) => {
|
|
2191
|
+
return lint({ ...params, fix: true });
|
|
2192
|
+
};
|
|
2193
|
+
|
|
2194
|
+
// src/actions/gen-docs.ts
|
|
2195
|
+
var genDocs = ({ pkg, incremental }) => {
|
|
2196
|
+
return pkg ? genDocsPackage({ pkg }) : genDocsAll({ incremental });
|
|
2197
|
+
};
|
|
2198
|
+
var genDocsPackage = ({ pkg }) => {
|
|
2199
|
+
const pm = getPackageManager();
|
|
2200
|
+
return runSteps(`GenDocs [${pkg}]`, [pm.runInWorkspace(pkg, "package-gen-docs")]);
|
|
2201
|
+
};
|
|
2202
|
+
var genDocsAll = ({ incremental }) => {
|
|
2203
|
+
const pm = getPackageManager();
|
|
2204
|
+
return runSteps(`GenDocs [All${incremental ? "-Incremental" : ""}]`, [
|
|
2205
|
+
pm.foreachWorkspace("package-gen-docs", [], { incremental })
|
|
2206
|
+
]);
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2209
|
+
// src/actions/gitignore.ts
|
|
2210
|
+
import { unlinkSync as unlinkSync4 } from "fs";
|
|
2211
|
+
import chalk29 from "chalk";
|
|
2212
|
+
var COMMENT_PREFIX = "#";
|
|
2213
|
+
var isComment = (line) => line.startsWith(COMMENT_PREFIX);
|
|
2214
|
+
var isNegation = (line) => line.startsWith("!");
|
|
2215
|
+
function parseTemplateSections(lines) {
|
|
2216
|
+
const sections = [];
|
|
2217
|
+
let current = [];
|
|
2218
|
+
for (const line of lines) {
|
|
2219
|
+
if (isComment(line)) {
|
|
2220
|
+
if (current.length > 0) {
|
|
2221
|
+
sections.push(current);
|
|
2222
|
+
}
|
|
2223
|
+
current = [line];
|
|
2224
|
+
} else {
|
|
2225
|
+
current.push(line);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
if (current.length > 0) {
|
|
2229
|
+
sections.push(current);
|
|
2230
|
+
}
|
|
2231
|
+
return sections;
|
|
2232
|
+
}
|
|
2233
|
+
function mergeWithTemplate(existing, templateContent) {
|
|
2234
|
+
const templateLines = templateContent.split("\n").filter((line) => line.trim().length > 0);
|
|
2235
|
+
const sections = parseTemplateSections(templateLines);
|
|
2236
|
+
const existingEntries = new Set(existing.filter((line) => !isComment(line)));
|
|
2237
|
+
const templateEntries = new Set(templateLines.filter((line) => !isComment(line)));
|
|
2238
|
+
const customEntries = [...existingEntries].filter((entry) => !templateEntries.has(entry));
|
|
2239
|
+
const result = [];
|
|
2240
|
+
for (const section of sections) {
|
|
2241
|
+
for (const line of section) {
|
|
2242
|
+
result.push(line);
|
|
2243
|
+
}
|
|
2244
|
+
result.push("");
|
|
2245
|
+
}
|
|
2246
|
+
if (customEntries.length > 0) {
|
|
2247
|
+
result.push("# Custom");
|
|
2248
|
+
const sorted = [...union(customEntries, [])].toSorted((a, b) => {
|
|
2249
|
+
if (isNegation(a) && !isNegation(b)) return 1;
|
|
2250
|
+
if (!isNegation(a) && isNegation(b)) return -1;
|
|
2251
|
+
return a.localeCompare(b);
|
|
2252
|
+
});
|
|
2253
|
+
for (const entry of sorted) {
|
|
2254
|
+
result.push(entry);
|
|
2255
|
+
}
|
|
2256
|
+
result.push("");
|
|
2257
|
+
}
|
|
2258
|
+
return result;
|
|
2259
|
+
}
|
|
2260
|
+
function removePackageGitignores(cwd5) {
|
|
2261
|
+
let removed = 0;
|
|
2262
|
+
const workspaces = getPackageManager().listWorkspaces();
|
|
2263
|
+
for (const { location } of workspaces) {
|
|
2264
|
+
if (location === ".") continue;
|
|
2265
|
+
const filePath = `${cwd5}/${location}/.gitignore`;
|
|
2266
|
+
try {
|
|
2267
|
+
unlinkSync4(filePath);
|
|
2268
|
+
console.log(chalk29.yellow(` Removed ${location}/.gitignore`));
|
|
2269
|
+
removed++;
|
|
2270
|
+
} catch {
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
return removed;
|
|
2274
|
+
}
|
|
2275
|
+
var gitignoreGen = gitignore;
|
|
2276
|
+
function gitignore() {
|
|
2277
|
+
console.log(chalk29.green("Generate .gitignore"));
|
|
2278
|
+
const cwd5 = INIT_CWD() ?? ".";
|
|
2279
|
+
const gitignorePath = `${cwd5}/.gitignore`;
|
|
2280
|
+
try {
|
|
2281
|
+
const templateContent = gitignoreTemplate();
|
|
2282
|
+
const existing = readNonEmptyLines(gitignorePath);
|
|
2283
|
+
const merged = mergeWithTemplate(existing, templateContent);
|
|
2284
|
+
writeLines(gitignorePath, merged);
|
|
2285
|
+
console.log(chalk29.green(" Root .gitignore updated"));
|
|
2286
|
+
const removed = removePackageGitignores(cwd5);
|
|
2287
|
+
if (removed > 0) {
|
|
2288
|
+
console.log(chalk29.green(` Removed ${removed} package .gitignore file(s)`));
|
|
2289
|
+
}
|
|
2290
|
+
return 0;
|
|
2291
|
+
} catch (ex) {
|
|
2292
|
+
const error = ex;
|
|
2293
|
+
console.error(chalk29.red(`Generate .gitignore failed: ${error.message}`));
|
|
2294
|
+
return 1;
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
// src/actions/gitlint.ts
|
|
2299
|
+
import chalk30 from "chalk";
|
|
2300
|
+
import ParseGitConfig from "parse-git-config";
|
|
2301
|
+
var gitlint = () => {
|
|
2302
|
+
console.log(`
|
|
2303
|
+
Gitlint Start [${process.cwd()}]
|
|
2304
|
+
`);
|
|
2305
|
+
let valid = 0;
|
|
2306
|
+
let warnings = 0;
|
|
2307
|
+
const errors = 0;
|
|
2308
|
+
const gitConfig = ParseGitConfig.sync();
|
|
2309
|
+
const warn = (message) => {
|
|
2310
|
+
console.warn(chalk30.yellow(`Warning: ${message}`));
|
|
2311
|
+
warnings++;
|
|
2312
|
+
};
|
|
2313
|
+
if (gitConfig.core.ignorecase) {
|
|
2314
|
+
warn("Please set core.ignorecase to FALSE in .git/config file [run yarn gitlint-fix]");
|
|
2315
|
+
} else {
|
|
2316
|
+
valid++;
|
|
2317
|
+
}
|
|
2318
|
+
if (gitConfig.core.autocrlf === false) {
|
|
2319
|
+
valid++;
|
|
2320
|
+
} else {
|
|
2321
|
+
warn("Please set core.autocrlf to FALSE in .git/config file [run yarn gitlint-fix]");
|
|
2322
|
+
}
|
|
2323
|
+
if (gitConfig.core.eol === "lf") {
|
|
2324
|
+
valid++;
|
|
2325
|
+
} else {
|
|
2326
|
+
warn('Please set core.eol to "lf" in .git/config file [run yarn gitlint-fix]');
|
|
2327
|
+
}
|
|
2328
|
+
const resultMessages = [];
|
|
2329
|
+
if (valid > 0) {
|
|
2330
|
+
resultMessages.push(chalk30.green(`Passed: ${valid}`));
|
|
2331
|
+
}
|
|
2332
|
+
if (warnings > 0) {
|
|
2333
|
+
resultMessages.push(chalk30.yellow(`Warnings: ${warnings}`));
|
|
2334
|
+
}
|
|
2335
|
+
if (errors > 0) {
|
|
2336
|
+
resultMessages.push(chalk30.red(` Errors: ${errors}`));
|
|
2337
|
+
}
|
|
2338
|
+
console.warn(`Gitlint Finish [ ${resultMessages.join(" | ")} ]
|
|
2339
|
+
`);
|
|
2340
|
+
return warnings + errors === 0 ? 1 : 0;
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
// src/actions/gitlint-fix.ts
|
|
2344
|
+
import { execSync as execSync3 } from "child_process";
|
|
2345
|
+
import chalk31 from "chalk";
|
|
2346
|
+
import ParseGitConfig2 from "parse-git-config";
|
|
2347
|
+
var gitlintFix = () => {
|
|
2348
|
+
console.log(`
|
|
2349
|
+
Gitlint Fix Start [${process.cwd()}]
|
|
2350
|
+
`);
|
|
2351
|
+
const gitConfig = ParseGitConfig2.sync();
|
|
2352
|
+
if (gitConfig.core.ignorecase) {
|
|
2353
|
+
execSync3("git config core.ignorecase false", { stdio: "inherit" });
|
|
2354
|
+
console.warn(chalk31.yellow("\nGitlint Fix: Updated core.ignorecase to be false\n"));
|
|
2355
|
+
}
|
|
2356
|
+
if (gitConfig.core.autocrlf !== false) {
|
|
2357
|
+
execSync3("git config core.autocrlf false", { stdio: "inherit" });
|
|
2358
|
+
console.warn(chalk31.yellow("\nGitlint Fix: Updated core.autocrlf to be false\n"));
|
|
2359
|
+
}
|
|
2360
|
+
if (gitConfig.core.eol !== "lf") {
|
|
2361
|
+
execSync3("git config core.eol lf", { stdio: "inherit" });
|
|
2362
|
+
console.warn(chalk31.yellow('\nGitlint Fix: Updated core.eol to be "lf"\n'));
|
|
2363
|
+
}
|
|
2364
|
+
return 1;
|
|
2365
|
+
};
|
|
2366
|
+
|
|
2367
|
+
// src/actions/knip.ts
|
|
2368
|
+
var knip = () => {
|
|
2369
|
+
return runSteps("Knip", [["knip", ["--dependencies", "--no-exit-code"]]]);
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
// src/actions/license.ts
|
|
2373
|
+
import chalk32 from "chalk";
|
|
2374
|
+
import { init } from "license-checker";
|
|
2375
|
+
var license = async (pkg) => {
|
|
2376
|
+
const workspaces = getPackageManager().listWorkspaces();
|
|
2377
|
+
const workspaceList = workspaces.filter(({ name }) => {
|
|
2378
|
+
return pkg === void 0 || name === pkg;
|
|
2379
|
+
});
|
|
2380
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
2381
|
+
"MIT",
|
|
2382
|
+
"MIT*",
|
|
2383
|
+
"ISC",
|
|
2384
|
+
"Apache-2.0",
|
|
2385
|
+
"BSD",
|
|
2386
|
+
"BSD*",
|
|
2387
|
+
"BSD-2-Clause",
|
|
2388
|
+
"BSD-3-Clause",
|
|
2389
|
+
"CC-BY-4.0",
|
|
2390
|
+
"Unlicense",
|
|
2391
|
+
"CC-BY-3.0",
|
|
2392
|
+
"CC0-1.0",
|
|
2393
|
+
"LGPL-3.0-only",
|
|
2394
|
+
"LGPL-3.0",
|
|
2395
|
+
"LGPL-3.0-or-later",
|
|
2396
|
+
"Python-2.0"
|
|
2397
|
+
]);
|
|
2398
|
+
console.log(chalk32.green("License Checker"));
|
|
2399
|
+
return (await Promise.all(
|
|
2400
|
+
workspaceList.map(({ location, name }) => {
|
|
2401
|
+
return new Promise((resolve) => {
|
|
2402
|
+
init({ production: true, start: location }, (error, packages) => {
|
|
2403
|
+
if (error) {
|
|
2404
|
+
console.error(chalk32.red(`License Checker [${name}] Error`));
|
|
2405
|
+
console.error(chalk32.gray(error));
|
|
2406
|
+
console.log("\n");
|
|
2407
|
+
resolve(1);
|
|
2408
|
+
} else {
|
|
2409
|
+
console.log(chalk32.green(`License Checker [${name}]`));
|
|
2410
|
+
let count = 0;
|
|
2411
|
+
for (const [name2, info] of Object.entries(packages)) {
|
|
2412
|
+
const licenses = Array.isArray(info.licenses) ? info.licenses : [info.licenses];
|
|
2413
|
+
for (let license2 of licenses) {
|
|
2414
|
+
if (license2) {
|
|
2415
|
+
const processedLicense = license2[0] === "(" && license2.at(-1) === ")" ? license2.slice(1, -2) : license2;
|
|
2416
|
+
const orLicenses = processedLicense.split(" OR ");
|
|
2417
|
+
let orLicenseFound = false;
|
|
2418
|
+
for (const orLicense of orLicenses) {
|
|
2419
|
+
if (exclude.has(orLicense)) {
|
|
2420
|
+
orLicenseFound = true;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
if (!orLicenseFound) {
|
|
2424
|
+
count++;
|
|
2425
|
+
console.warn(chalk32.yellow(`${name2}: Package License not allowed [${license2}]`));
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
console.log("\n");
|
|
2431
|
+
resolve(count);
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
});
|
|
2435
|
+
})
|
|
2436
|
+
)).reduce((prev, value) => prev || value, 0);
|
|
2437
|
+
};
|
|
2438
|
+
|
|
2439
|
+
// src/actions/lintlint.ts
|
|
2440
|
+
import { readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "fs";
|
|
2441
|
+
import PATH10 from "path";
|
|
2442
|
+
import chalk33 from "chalk";
|
|
2443
|
+
import { findUp } from "find-up";
|
|
2444
|
+
function parseRuleValue(value) {
|
|
2445
|
+
if (typeof value === "string") {
|
|
2446
|
+
return { level: value };
|
|
2447
|
+
}
|
|
2448
|
+
if (typeof value === "number") {
|
|
2449
|
+
return { level: String(value) };
|
|
2450
|
+
}
|
|
2451
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
2452
|
+
return {
|
|
2453
|
+
level: String(value[0]),
|
|
2454
|
+
options: value.length > 1 ? value.slice(1) : void 0
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
return void 0;
|
|
2458
|
+
}
|
|
2459
|
+
function normalizeLevel(level) {
|
|
2460
|
+
if (level === "0" || level === "off") return "off";
|
|
2461
|
+
if (level === "1" || level === "warn") return "warn";
|
|
2462
|
+
if (level === "2" || level === "error") return "error";
|
|
2463
|
+
return level;
|
|
2464
|
+
}
|
|
2465
|
+
function rulesMatch(a, b) {
|
|
2466
|
+
if (normalizeLevel(a.level) !== normalizeLevel(b.level)) return false;
|
|
2467
|
+
return JSON.stringify(a.options) === JSON.stringify(b.options);
|
|
2468
|
+
}
|
|
2469
|
+
function formatRule(entry) {
|
|
2470
|
+
if (entry.options) {
|
|
2471
|
+
return JSON.stringify([entry.level, ...entry.options]);
|
|
2472
|
+
}
|
|
2473
|
+
return JSON.stringify([entry.level]);
|
|
2474
|
+
}
|
|
2475
|
+
function mergeRulesFromBlocks(blocks) {
|
|
2476
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2477
|
+
for (const block of blocks) {
|
|
2478
|
+
if (!block.rules) continue;
|
|
2479
|
+
for (const [name, value] of Object.entries(block.rules)) {
|
|
2480
|
+
const parsed = parseRuleValue(value);
|
|
2481
|
+
if (parsed) merged.set(name, parsed);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
return merged;
|
|
2485
|
+
}
|
|
2486
|
+
function detectSharedPackage(source) {
|
|
2487
|
+
if (source.includes("@xylabs/eslint-config-react-flat")) return "@xylabs/eslint-config-react-flat";
|
|
2488
|
+
if (source.includes("@xylabs/eslint-config-flat")) return "@xylabs/eslint-config-flat";
|
|
2489
|
+
return void 0;
|
|
2490
|
+
}
|
|
2491
|
+
function extractLocalRuleBlocks(source) {
|
|
2492
|
+
const blocks = [];
|
|
2493
|
+
const ruleBlockRegex = /\{\s*(?:files\s*:\s*\[.*?\]\s*,\s*)?rules\s*:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/g;
|
|
2494
|
+
let match;
|
|
2495
|
+
while ((match = ruleBlockRegex.exec(source)) !== null) {
|
|
2496
|
+
blocks.push(match[1]);
|
|
2497
|
+
}
|
|
2498
|
+
return blocks;
|
|
2499
|
+
}
|
|
2500
|
+
function extractRulesFromSourceBlocks(blocks) {
|
|
2501
|
+
const rules2 = /* @__PURE__ */ new Map();
|
|
2502
|
+
for (const block of blocks) {
|
|
2503
|
+
const ruleRegex = /['"]([^'"]+)['"]\s*:\s*(\[[\s\S]*?\](?=\s*,|\s*$))/gm;
|
|
2504
|
+
let match;
|
|
2505
|
+
while ((match = ruleRegex.exec(block)) !== null) {
|
|
2506
|
+
rules2.set(match[1], match[2]);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
return rules2;
|
|
2510
|
+
}
|
|
2511
|
+
async function resolveSharedConfig(configDir, sharedPkg) {
|
|
2512
|
+
try {
|
|
2513
|
+
const sharedModule = await import(sharedPkg);
|
|
2514
|
+
const config2 = sharedModule.config ?? sharedModule.default;
|
|
2515
|
+
if (Array.isArray(config2)) return config2;
|
|
2516
|
+
return [];
|
|
2517
|
+
} catch {
|
|
2518
|
+
const distPath = PATH10.resolve(configDir, "node_modules", sharedPkg, "dist", "node", "index.mjs");
|
|
2519
|
+
try {
|
|
2520
|
+
const sharedModule = await import(distPath);
|
|
2521
|
+
const config2 = sharedModule.config ?? sharedModule.default;
|
|
2522
|
+
if (Array.isArray(config2)) return config2;
|
|
2523
|
+
} catch {
|
|
2524
|
+
const neutralPath = PATH10.resolve(configDir, "node_modules", sharedPkg, "dist", "neutral", "index.mjs");
|
|
2525
|
+
const sharedModule = await import(neutralPath);
|
|
2526
|
+
const config2 = sharedModule.config ?? sharedModule.default;
|
|
2527
|
+
if (Array.isArray(config2)) return config2;
|
|
2528
|
+
}
|
|
2529
|
+
return [];
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
async function loadSharedRules(configDir, sharedPkg, verbose) {
|
|
2533
|
+
const sharedBlocks = await resolveSharedConfig(configDir, sharedPkg);
|
|
2534
|
+
const sharedRules = mergeRulesFromBlocks(sharedBlocks);
|
|
2535
|
+
if (verbose) {
|
|
2536
|
+
console.log(chalk33.gray(`Shared config defines ${sharedRules.size} rules`));
|
|
2537
|
+
}
|
|
2538
|
+
if (sharedRules.size === 0) {
|
|
2539
|
+
console.error(chalk33.red("Could not load rules from shared config. Is it installed and built?"));
|
|
2540
|
+
return void 0;
|
|
2541
|
+
}
|
|
2542
|
+
return sharedRules;
|
|
2543
|
+
}
|
|
2544
|
+
async function loadLocalRules(eslintConfigPath, source, verbose) {
|
|
2545
|
+
const localModule = await import(eslintConfigPath);
|
|
2546
|
+
const localConfig = localModule.default ?? localModule;
|
|
2547
|
+
const localBlocks = Array.isArray(localConfig) ? localConfig : [localConfig];
|
|
2548
|
+
const resolved = mergeRulesFromBlocks(localBlocks);
|
|
2549
|
+
const localRuleBlocks = extractLocalRuleBlocks(source);
|
|
2550
|
+
const explicit = extractRulesFromSourceBlocks(localRuleBlocks);
|
|
2551
|
+
if (verbose) {
|
|
2552
|
+
console.log(chalk33.gray(`Local config has ${explicit.size} explicit rule setting(s)`));
|
|
2553
|
+
}
|
|
2554
|
+
return { explicit, resolved };
|
|
2555
|
+
}
|
|
2556
|
+
function compareRules(explicitRuleNames, allResolvedRules, sharedRules) {
|
|
2557
|
+
const redundant = [];
|
|
2558
|
+
const overrides = [];
|
|
2559
|
+
const additions = [];
|
|
2560
|
+
for (const ruleName of explicitRuleNames.keys()) {
|
|
2561
|
+
const resolvedEntry = allResolvedRules.get(ruleName);
|
|
2562
|
+
const sharedEntry = sharedRules.get(ruleName);
|
|
2563
|
+
if (!resolvedEntry) continue;
|
|
2564
|
+
if (!sharedEntry) {
|
|
2565
|
+
additions.push({ local: resolvedEntry, rule: ruleName });
|
|
2566
|
+
} else if (rulesMatch(resolvedEntry, sharedEntry)) {
|
|
2567
|
+
redundant.push({
|
|
2568
|
+
local: resolvedEntry,
|
|
2569
|
+
rule: ruleName,
|
|
2570
|
+
shared: sharedEntry
|
|
2571
|
+
});
|
|
2572
|
+
} else {
|
|
2573
|
+
overrides.push({
|
|
2574
|
+
local: resolvedEntry,
|
|
2575
|
+
rule: ruleName,
|
|
2576
|
+
shared: sharedEntry
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
return {
|
|
2581
|
+
additions,
|
|
2582
|
+
overrides,
|
|
2583
|
+
redundant
|
|
2584
|
+
};
|
|
2585
|
+
}
|
|
2586
|
+
function reportResults({
|
|
2587
|
+
additions,
|
|
2588
|
+
overrides,
|
|
2589
|
+
redundant
|
|
2590
|
+
}, verbose) {
|
|
2591
|
+
if (redundant.length > 0) {
|
|
2592
|
+
console.log(chalk33.yellow(`
|
|
2593
|
+
${redundant.length} redundant rule(s) (same as shared config \u2014 can be removed):`));
|
|
2594
|
+
for (const { rule, local } of redundant) {
|
|
2595
|
+
console.log(chalk33.yellow(` ${rule}: ${formatRule(local)}`));
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
if (overrides.length > 0) {
|
|
2599
|
+
console.log(chalk33.cyan(`
|
|
2600
|
+
${overrides.length} rule override(s) (different from shared config):`));
|
|
2601
|
+
for (const {
|
|
2602
|
+
rule,
|
|
2603
|
+
local,
|
|
2604
|
+
shared
|
|
2605
|
+
} of overrides) {
|
|
2606
|
+
console.log(chalk33.cyan(` ${rule}:`));
|
|
2607
|
+
console.log(chalk33.gray(` shared: ${formatRule(shared)}`));
|
|
2608
|
+
console.log(chalk33.white(` local: ${formatRule(local)}`));
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
if (additions.length > 0 && verbose) {
|
|
2612
|
+
console.log(chalk33.gray(`
|
|
2613
|
+
${additions.length} local addition(s) (not in shared config):`));
|
|
2614
|
+
for (const { rule, local } of additions) {
|
|
2615
|
+
console.log(chalk33.gray(` ${rule}: ${formatRule(local)}`));
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
if (redundant.length === 0 && overrides.length === 0) {
|
|
2619
|
+
console.log(chalk33.green("No redundant or overridden rules found"));
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
function fixRedundantRules(eslintConfigPath, source, redundant) {
|
|
2623
|
+
let updated = source;
|
|
2624
|
+
for (const { rule } of redundant) {
|
|
2625
|
+
const escaped = rule.replaceAll("/", String.raw`\/`);
|
|
2626
|
+
const pattern = new RegExp(String.raw`[ \t]*['"]${escaped}['"]\s*:\s*\[[^\]]*\],?[ \t]*\n?`, "g");
|
|
2627
|
+
updated = updated.replace(pattern, "");
|
|
2628
|
+
}
|
|
2629
|
+
updated = updated.replaceAll(/\n{3,}/g, "\n\n");
|
|
2630
|
+
if (updated !== source) {
|
|
2631
|
+
writeFileSync6(eslintConfigPath, updated, "utf8");
|
|
2632
|
+
console.log(chalk33.green(`
|
|
2633
|
+
Fixed: removed ${redundant.length} redundant rule(s)`));
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
async function lintlint({ fix: fix2, verbose } = {}) {
|
|
2637
|
+
const eslintConfigPath = await findUp("eslint.config.mjs");
|
|
2638
|
+
if (!eslintConfigPath) {
|
|
2639
|
+
console.error(chalk33.red("No eslint.config.mjs found"));
|
|
2640
|
+
return 1;
|
|
2641
|
+
}
|
|
2642
|
+
const configDir = PATH10.dirname(eslintConfigPath);
|
|
2643
|
+
if (verbose) {
|
|
2644
|
+
console.log(chalk33.gray(`Found config: ${eslintConfigPath}`));
|
|
2645
|
+
}
|
|
2646
|
+
const source = readFileSync12(eslintConfigPath, "utf8");
|
|
2647
|
+
const sharedPkg = detectSharedPackage(source);
|
|
2648
|
+
if (!sharedPkg) {
|
|
2649
|
+
console.log(chalk33.yellow("No @xylabs/eslint-config-flat or @xylabs/eslint-config-react-flat imports found"));
|
|
2650
|
+
return 0;
|
|
2651
|
+
}
|
|
2652
|
+
if (verbose) {
|
|
2653
|
+
console.log(chalk33.gray(`Shared package: ${sharedPkg}`));
|
|
2654
|
+
}
|
|
2655
|
+
const sharedRules = await loadSharedRules(configDir, sharedPkg, !!verbose);
|
|
2656
|
+
if (!sharedRules) return 1;
|
|
2657
|
+
const { explicit, resolved } = await loadLocalRules(eslintConfigPath, source, !!verbose);
|
|
2658
|
+
const results = compareRules(explicit, resolved, sharedRules);
|
|
2659
|
+
reportResults(results, !!verbose);
|
|
2660
|
+
if (results.redundant.length > 0 && fix2) {
|
|
2661
|
+
fixRedundantRules(eslintConfigPath, source, results.redundant);
|
|
2662
|
+
}
|
|
2663
|
+
return results.redundant.length > 0 && !fix2 ? 1 : 0;
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
// src/actions/npmignore-gen.ts
|
|
2667
|
+
var filename = ".npmignore";
|
|
2668
|
+
var npmignoreGen = (pkg) => generateIgnoreFiles(filename, pkg);
|
|
2669
|
+
|
|
2670
|
+
// src/actions/package/clean-outputs.ts
|
|
2671
|
+
import path9 from "path";
|
|
2672
|
+
import chalk34 from "chalk";
|
|
2673
|
+
var packageCleanOutputs = () => {
|
|
2674
|
+
const pkg = process.env.INIT_CWD ?? ".";
|
|
2675
|
+
const pkgName = process.env.npm_package_name;
|
|
2676
|
+
const folders = [path9.join(pkg, "dist"), path9.join(pkg, "build"), path9.join(pkg, "docs")];
|
|
2677
|
+
console.log(chalk34.green(`Cleaning Outputs [${pkgName}]`));
|
|
2678
|
+
for (let folder of folders) {
|
|
2679
|
+
deleteGlob(folder);
|
|
2680
|
+
}
|
|
2681
|
+
return 0;
|
|
2682
|
+
};
|
|
2683
|
+
|
|
2684
|
+
// src/actions/package/clean-typescript.ts
|
|
2685
|
+
import path10 from "path";
|
|
2686
|
+
import chalk35 from "chalk";
|
|
2687
|
+
var packageCleanTypescript = () => {
|
|
2688
|
+
const pkg = process.env.INIT_CWD ?? ".";
|
|
2689
|
+
const pkgName = process.env.npm_package_name;
|
|
2690
|
+
console.log(chalk35.green(`Cleaning Typescript [${pkgName}]`));
|
|
2691
|
+
const files = [path10.join(pkg, "*.tsbuildinfo"), path10.join(pkg, ".tsconfig.*"), path10.join(pkg, ".eslintcache")];
|
|
2692
|
+
for (let file of files) {
|
|
2693
|
+
deleteGlob(file);
|
|
2694
|
+
}
|
|
2695
|
+
return 0;
|
|
2696
|
+
};
|
|
2697
|
+
|
|
2698
|
+
// src/actions/package/clean.ts
|
|
2699
|
+
var packageClean = async () => {
|
|
2700
|
+
return (await Promise.all([packageCleanOutputs(), packageCleanTypescript()])).reduce((prev, value) => prev + value, 0);
|
|
2701
|
+
};
|
|
2702
|
+
|
|
2703
|
+
// src/actions/package/compile/compile.ts
|
|
2704
|
+
import chalk40 from "chalk";
|
|
2705
|
+
|
|
2706
|
+
// src/actions/package/compile/packageCompileTsup.ts
|
|
2707
|
+
import chalk39 from "chalk";
|
|
2708
|
+
import { build as build2, defineConfig } from "tsup";
|
|
2709
|
+
|
|
2710
|
+
// src/actions/package/compile/inputs.ts
|
|
2711
|
+
import chalk36 from "chalk";
|
|
2712
|
+
import { glob as glob2 } from "glob";
|
|
2713
|
+
var getAllInputs = (srcDir, verbose = false) => {
|
|
2714
|
+
return [...glob2.sync(`${srcDir}/**/*.ts`, { posix: true }).map((file) => {
|
|
2715
|
+
const result = file.slice(Math.max(0, srcDir.length + 1));
|
|
2716
|
+
if (verbose) {
|
|
2717
|
+
console.log(chalk36.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
|
|
2718
|
+
}
|
|
2719
|
+
return result;
|
|
2720
|
+
}), ...glob2.sync(`${srcDir}/**/*.tsx`, { posix: true }).map((file) => {
|
|
2721
|
+
const result = file.slice(Math.max(0, srcDir.length + 1));
|
|
2722
|
+
if (verbose) {
|
|
2723
|
+
console.log(chalk36.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
|
|
2724
|
+
}
|
|
2725
|
+
return result;
|
|
2726
|
+
})];
|
|
2727
|
+
};
|
|
2728
|
+
|
|
2729
|
+
// src/actions/package/compile/buildEntries.ts
|
|
2730
|
+
var isSpecOrStory = (entry) => {
|
|
2731
|
+
return entry.includes(".spec.") || entry.includes(".stories.") || entry.startsWith("spec/") || entry.includes("/spec/") || entry.startsWith("stories/") || entry.includes("/stories/") || entry === "spec.ts" || entry.endsWith("/spec.ts") || entry === "stories.ts" || entry.endsWith("/stories.ts");
|
|
2732
|
+
};
|
|
2733
|
+
var buildEntries = (srcDir, entryMode = "single", options, excludeSpecAndStories = true, verbose = false) => {
|
|
2734
|
+
let entries = [];
|
|
2735
|
+
switch (entryMode) {
|
|
2736
|
+
case "platform": {
|
|
2737
|
+
entries = ["index-node.ts", "index-browser.ts"];
|
|
2738
|
+
break;
|
|
2739
|
+
}
|
|
2740
|
+
case "all": {
|
|
2741
|
+
entries = (excludeSpecAndStories ? getAllInputs(srcDir).filter((entry) => !isSpecOrStory(entry)) : getAllInputs(srcDir)).filter((entry) => !entry.endsWith(".d.ts"));
|
|
2742
|
+
break;
|
|
2743
|
+
}
|
|
2744
|
+
case "custom": {
|
|
2745
|
+
entries = [];
|
|
2746
|
+
break;
|
|
2747
|
+
}
|
|
2748
|
+
default: {
|
|
2749
|
+
entries = ["index.ts"];
|
|
2750
|
+
break;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
if (typeof options !== "boolean" && Array.isArray(options?.entry)) {
|
|
2754
|
+
entries.push(...options.entry);
|
|
2755
|
+
}
|
|
2756
|
+
if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`);
|
|
2757
|
+
return entries;
|
|
2758
|
+
};
|
|
2759
|
+
|
|
2760
|
+
// src/actions/package/compile/deepMerge.ts
|
|
2761
|
+
function deepMerge(target, source) {
|
|
2762
|
+
if (!source || typeof source !== "object") return target;
|
|
2763
|
+
for (const key of Object.keys(source)) {
|
|
2764
|
+
if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key])) {
|
|
2765
|
+
if (!target[key] || typeof target[key] !== "object") {
|
|
2766
|
+
target[key] = {};
|
|
2767
|
+
}
|
|
2768
|
+
deepMerge(target[key], source[key]);
|
|
2769
|
+
} else {
|
|
2770
|
+
target[key] = source[key];
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
return target;
|
|
2774
|
+
}
|
|
2775
|
+
function deepMergeObjects(objects) {
|
|
2776
|
+
const result = {};
|
|
2777
|
+
for (const obj of objects) {
|
|
2778
|
+
deepMerge(result, obj);
|
|
2779
|
+
}
|
|
2780
|
+
return result;
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
// src/actions/package/compile/packageCompileTsc.ts
|
|
2784
|
+
import { cwd as cwd2 } from "process";
|
|
2785
|
+
import chalk37 from "chalk";
|
|
2786
|
+
import { createProgramFromConfig } from "tsc-prog";
|
|
2787
|
+
import ts3, {
|
|
2788
|
+
DiagnosticCategory,
|
|
2789
|
+
formatDiagnosticsWithColorAndContext,
|
|
2790
|
+
getPreEmitDiagnostics,
|
|
2791
|
+
sys
|
|
2792
|
+
} from "typescript";
|
|
2793
|
+
|
|
2794
|
+
// src/actions/package/compile/getCompilerOptions.ts
|
|
2795
|
+
import { cwd } from "process";
|
|
2796
|
+
import deepmerge2 from "deepmerge";
|
|
2797
|
+
import { getTsconfig } from "get-tsconfig";
|
|
2798
|
+
var getCompilerOptions = (options = {}, fileName = "tsconfig.json") => {
|
|
2799
|
+
const resolvedTsConfigCompilerOptions = getTsconfig(cwd(), fileName)?.config?.compilerOptions ?? {};
|
|
2800
|
+
return deepmerge2(resolvedTsConfigCompilerOptions, options);
|
|
2801
|
+
};
|
|
2802
|
+
|
|
2803
|
+
// src/actions/package/compile/packageCompileTsc.ts
|
|
2804
|
+
var packageCompileTsc = (platform, entries, srcDir = "src", outDir = "dist", compilerOptionsParam, verbose = false) => {
|
|
2805
|
+
const pkg = process.env.INIT_CWD ?? cwd2();
|
|
2806
|
+
if (verbose) {
|
|
2807
|
+
console.log(chalk37.cyan(`Validating code START: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2808
|
+
}
|
|
2809
|
+
const configFilePath = ts3.findConfigFile(
|
|
2810
|
+
"./",
|
|
2811
|
+
// search path
|
|
2812
|
+
ts3.sys.fileExists,
|
|
2813
|
+
"tsconfig.json"
|
|
2814
|
+
);
|
|
2815
|
+
if (configFilePath === void 0) {
|
|
2816
|
+
throw new Error("Could not find tsconfig.json");
|
|
2817
|
+
}
|
|
2818
|
+
const compilerOptions = {
|
|
2819
|
+
...getCompilerOptions({
|
|
2820
|
+
removeComments: false,
|
|
2821
|
+
skipDefaultLibCheck: true,
|
|
2822
|
+
skipLibCheck: true,
|
|
2823
|
+
sourceMap: false
|
|
2824
|
+
}),
|
|
2825
|
+
...compilerOptionsParam,
|
|
2826
|
+
outDir: `${outDir}/${platform}`,
|
|
2827
|
+
emitDeclarationOnly: true,
|
|
2828
|
+
noEmit: false
|
|
2829
|
+
};
|
|
2830
|
+
console.log(chalk37.cyan(`Validating Files: ${entries.length}`));
|
|
2831
|
+
if (verbose) {
|
|
2832
|
+
for (const entry of entries) {
|
|
2833
|
+
console.log(chalk37.grey(`Validating: ${entry}`));
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
try {
|
|
2837
|
+
if (entries.length > 0) {
|
|
2838
|
+
const program = createProgramFromConfig({
|
|
2839
|
+
configFilePath,
|
|
2840
|
+
basePath: pkg ?? cwd2(),
|
|
2841
|
+
compilerOptions,
|
|
2842
|
+
files: entries.map((entry) => `${srcDir}/${entry}`),
|
|
2843
|
+
include: [`${srcDir}/**/*.*`]
|
|
2844
|
+
});
|
|
2845
|
+
const diagnostics = getPreEmitDiagnostics(program);
|
|
2846
|
+
if (diagnostics.length > 0) {
|
|
2847
|
+
const formattedDiagnostics = formatDiagnosticsWithColorAndContext(
|
|
2848
|
+
diagnostics,
|
|
2849
|
+
{
|
|
2850
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
2851
|
+
getCurrentDirectory: () => srcDir,
|
|
2852
|
+
getNewLine: () => sys.newLine
|
|
2853
|
+
}
|
|
2854
|
+
);
|
|
2855
|
+
console.error(formattedDiagnostics);
|
|
2856
|
+
}
|
|
2857
|
+
const nonEmitPatterns = [".stories.", "/stories/", "/stories.", ".spec.", "/spec/", "/spec.", ".example."];
|
|
2858
|
+
program.emit(void 0, (fileName, text, writeByteOrderMark) => {
|
|
2859
|
+
if (nonEmitPatterns.some((pattern) => fileName.includes(pattern))) {
|
|
2860
|
+
return;
|
|
2861
|
+
}
|
|
2862
|
+
ts3.sys.writeFile(fileName, text, writeByteOrderMark);
|
|
2863
|
+
});
|
|
2864
|
+
return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory.Error ? 1 : 0), 0);
|
|
2865
|
+
}
|
|
2866
|
+
return 0;
|
|
2867
|
+
} finally {
|
|
2868
|
+
if (verbose) {
|
|
2869
|
+
console.log(chalk37.cyan(`Validating code FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
};
|
|
2873
|
+
|
|
2874
|
+
// src/actions/package/compile/packageCompileTscTypes.ts
|
|
2875
|
+
import path11 from "path";
|
|
2876
|
+
import { cwd as cwd3 } from "process";
|
|
2877
|
+
import chalk38 from "chalk";
|
|
2878
|
+
import { rollup } from "rollup";
|
|
2879
|
+
import dts from "rollup-plugin-dts";
|
|
2880
|
+
import nodeExternals from "rollup-plugin-node-externals";
|
|
2881
|
+
var ignoredWarningCodes = /* @__PURE__ */ new Set(["EMPTY_BUNDLE", "UNRESOLVED_IMPORT"]);
|
|
2882
|
+
async function bundleDts(inputPath, outputPath, platform, options, verbose = false) {
|
|
2883
|
+
const pkg = process.env.INIT_CWD ?? cwd3();
|
|
2884
|
+
const tsconfigPath = path11.resolve(pkg, "tsconfig.json");
|
|
2885
|
+
const nodePlugIns = platform === "node" ? [nodeExternals()] : [];
|
|
2886
|
+
try {
|
|
2887
|
+
const bundle = await rollup({
|
|
2888
|
+
input: inputPath,
|
|
2889
|
+
plugins: [dts({
|
|
2890
|
+
...options,
|
|
2891
|
+
tsconfig: tsconfigPath,
|
|
2892
|
+
compilerOptions: {
|
|
2893
|
+
emitDeclarationOnly: true,
|
|
2894
|
+
noEmit: false,
|
|
2895
|
+
declarationMap: true
|
|
2896
|
+
}
|
|
2897
|
+
}), ...nodePlugIns],
|
|
2898
|
+
onwarn(warning, warn) {
|
|
2899
|
+
if (ignoredWarningCodes.has(warning.code ?? "")) {
|
|
2900
|
+
return;
|
|
2901
|
+
}
|
|
2902
|
+
console.warn(chalk38.yellow(`[${warning.code}] ${warning.message}`));
|
|
2903
|
+
console.warn(chalk38.gray(inputPath));
|
|
2904
|
+
warn(warning);
|
|
2905
|
+
}
|
|
2906
|
+
});
|
|
2907
|
+
await bundle.write({
|
|
2908
|
+
file: outputPath,
|
|
2909
|
+
format: "es"
|
|
2910
|
+
});
|
|
2911
|
+
} catch (ex) {
|
|
2912
|
+
const error = ex;
|
|
2913
|
+
console.warn(chalk38.red(error));
|
|
2914
|
+
console.warn(chalk38.gray(inputPath));
|
|
2915
|
+
}
|
|
2916
|
+
if (verbose) {
|
|
2917
|
+
console.log(`Bundled declarations written to ${outputPath}`);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
var packageCompileTscTypes = async (entries, outDir, platform, srcDir = "build", verbose = false) => {
|
|
2921
|
+
if (verbose) {
|
|
2922
|
+
console.log(chalk38.cyan(`Compiling Types START [${platform}]: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2923
|
+
console.log(`Entries: ${entries.join(", ")}`);
|
|
2924
|
+
}
|
|
2925
|
+
const pkg = process.env.INIT_CWD ?? cwd3();
|
|
2926
|
+
const srcRoot = `${pkg}/${srcDir}/${platform}`;
|
|
2927
|
+
const entryNameToTypeName = (entry) => {
|
|
2928
|
+
const splitEntryName = entry.split(".");
|
|
2929
|
+
const newEntryExtension = "d." + splitEntryName.at(-1);
|
|
2930
|
+
return [...splitEntryName.slice(0, -1), newEntryExtension].join(".");
|
|
2931
|
+
};
|
|
2932
|
+
const compilerOptions = getCompilerOptions({
|
|
2933
|
+
removeComments: false,
|
|
2934
|
+
skipDefaultLibCheck: true,
|
|
2935
|
+
skipLibCheck: true,
|
|
2936
|
+
declarationMap: true,
|
|
2937
|
+
emitDeclarationOnly: true,
|
|
2938
|
+
noEmit: true
|
|
2939
|
+
});
|
|
2940
|
+
const entryNames = entries.map((entry) => entry.split(`${srcDir}/`).at(-1) ?? entry);
|
|
2941
|
+
await Promise.all(entryNames.map(async (entryName) => {
|
|
2942
|
+
const entryTypeName = entryNameToTypeName(entryName);
|
|
2943
|
+
await bundleDts(`${srcRoot}/${entryTypeName}`, `${outDir}/${entryTypeName}`, platform, { compilerOptions }, verbose);
|
|
2944
|
+
}));
|
|
2945
|
+
if (verbose) {
|
|
2946
|
+
console.log(chalk38.cyan(`Compiling Types FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2947
|
+
}
|
|
2948
|
+
return 0;
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2951
|
+
// src/actions/package/compile/packageCompileTsup.ts
|
|
2952
|
+
var compileFolder = async (srcDir, entries, buildDir, options, bundleTypes = false, verbose) => {
|
|
2953
|
+
const outDir = options?.outDir ?? "dist";
|
|
2954
|
+
if (verbose) {
|
|
2955
|
+
console.log(`compileFolder [${srcDir}, ${options?.outDir}]`);
|
|
2956
|
+
}
|
|
2957
|
+
if (entries.length === 0) {
|
|
2958
|
+
console.warn(chalk39.yellow(`No entries found in ${srcDir} to compile`));
|
|
2959
|
+
return 0;
|
|
2960
|
+
}
|
|
2961
|
+
if (verbose) {
|
|
2962
|
+
console.log(chalk39.gray(`buildDir [${buildDir}]`));
|
|
2963
|
+
}
|
|
2964
|
+
const validationResult = packageCompileTsc(options?.platform ?? "neutral", entries, srcDir, buildDir, void 0, verbose);
|
|
2965
|
+
if (validationResult !== 0) {
|
|
2966
|
+
console.error(chalk39.red(`Compile:Validation had ${validationResult} errors`));
|
|
2967
|
+
return validationResult;
|
|
2968
|
+
}
|
|
2969
|
+
const optionsParams = tsupOptions([{
|
|
2970
|
+
bundle: true,
|
|
2971
|
+
cjsInterop: true,
|
|
2972
|
+
clean: false,
|
|
2973
|
+
dts: false,
|
|
2974
|
+
format: ["esm"],
|
|
2975
|
+
outDir,
|
|
2976
|
+
silent: true,
|
|
2977
|
+
sourcemap: true,
|
|
2978
|
+
splitting: false,
|
|
2979
|
+
tsconfig: "tsconfig.json",
|
|
2980
|
+
...options,
|
|
2981
|
+
entry: entries.map((entry) => `${srcDir}/${entry}`)
|
|
2982
|
+
}]);
|
|
2983
|
+
const optionsResult = defineConfig(optionsParams);
|
|
2984
|
+
const optionsList = (await Promise.all(
|
|
2985
|
+
(Array.isArray(optionsResult) ? optionsResult : [optionsResult]).flatMap(async (options2) => {
|
|
2986
|
+
const result = typeof options2 === "function" ? await options2({}) : [options2];
|
|
2987
|
+
return Array.isArray(result) ? result : [result];
|
|
2988
|
+
})
|
|
2989
|
+
)).flat();
|
|
2990
|
+
if (verbose) {
|
|
2991
|
+
console.log(chalk39.cyan(`TSUP:build:start [${srcDir}]`));
|
|
2992
|
+
console.log(chalk39.gray(`TSUP:build:options [${JSON.stringify(optionsList, null, 2)}]`));
|
|
2993
|
+
}
|
|
2994
|
+
await Promise.all(optionsList.map((options2) => build2(options2)));
|
|
2995
|
+
if (verbose) {
|
|
2996
|
+
console.log(chalk39.cyan(`TSUP:build:stop [${srcDir}]`));
|
|
2997
|
+
}
|
|
2998
|
+
if (bundleTypes) {
|
|
2999
|
+
await packageCompileTscTypes(entries, outDir, options?.platform ?? "neutral", buildDir, verbose);
|
|
3000
|
+
}
|
|
3001
|
+
return 0;
|
|
3002
|
+
};
|
|
3003
|
+
var tsupOptions = (options = []) => {
|
|
3004
|
+
const standardLoaders = {
|
|
3005
|
+
".gif": "copy",
|
|
3006
|
+
".html": "copy",
|
|
3007
|
+
".jpg": "copy",
|
|
3008
|
+
".json": "json",
|
|
3009
|
+
".png": "copy",
|
|
3010
|
+
".svg": "text",
|
|
3011
|
+
".webp": "copy"
|
|
3012
|
+
};
|
|
3013
|
+
const standardOptions = {
|
|
3014
|
+
bundle: true,
|
|
3015
|
+
format: ["esm"],
|
|
3016
|
+
loader: standardLoaders,
|
|
3017
|
+
outExtension: ({ format }) => format === "esm" ? { js: ".mjs" } : { js: ".cjs" },
|
|
3018
|
+
skipNodeModulesBundle: true,
|
|
3019
|
+
sourcemap: true,
|
|
3020
|
+
target: "esnext"
|
|
3021
|
+
};
|
|
3022
|
+
return deepMergeObjects([standardOptions, ...options]);
|
|
3023
|
+
};
|
|
3024
|
+
var packageCompileTsup = async (config2) => {
|
|
3025
|
+
const compile2 = config2?.compile;
|
|
3026
|
+
const verbose = config2?.verbose ?? false;
|
|
3027
|
+
const outDirAsBuildDir = compile2?.outDirAsBuildDir ?? true;
|
|
3028
|
+
const bundleTypes = compile2?.bundleTypes ?? false;
|
|
3029
|
+
if (verbose) {
|
|
3030
|
+
console.log("Compiling with TSUP");
|
|
3031
|
+
}
|
|
3032
|
+
const compileForNode = compile2?.node ?? { src: {} };
|
|
3033
|
+
const compileForBrowser = compile2?.browser ?? { src: {} };
|
|
3034
|
+
const compileForNeutral = compile2?.neutral ?? { src: {} };
|
|
3035
|
+
return (await Promise.all(
|
|
3036
|
+
Object.entries(compileForNode).map(async ([srcDir, options]) => {
|
|
3037
|
+
const optionsObject = typeof options === "object" ? options : {};
|
|
3038
|
+
const inEsBuildOptions = typeof compile2?.node?.esbuildOptions === "object" ? compile2?.node?.esbuildOptions : {};
|
|
3039
|
+
const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
|
|
3040
|
+
const platform = "node";
|
|
3041
|
+
const rootOutDir = optionsObject.outDir ?? "dist";
|
|
3042
|
+
const outDir = rootOutDir + "/" + platform;
|
|
3043
|
+
return typeof srcDir === "string" ? await compileFolder(
|
|
3044
|
+
srcDir,
|
|
3045
|
+
entry,
|
|
3046
|
+
outDirAsBuildDir ? rootOutDir : "build",
|
|
3047
|
+
tsupOptions([
|
|
3048
|
+
inEsBuildOptions,
|
|
3049
|
+
compile2?.tsup?.options ?? {},
|
|
3050
|
+
typeof options === "object" ? options : {},
|
|
3051
|
+
{ platform: "node", outDir }
|
|
3052
|
+
]),
|
|
3053
|
+
bundleTypes,
|
|
3054
|
+
verbose
|
|
3055
|
+
) : 0;
|
|
3056
|
+
})
|
|
3057
|
+
)).reduce((prev, value) => prev + value, 0) + (await Promise.all(
|
|
3058
|
+
Object.entries(compileForBrowser).map(async ([srcDir, options]) => {
|
|
3059
|
+
const optionsObject = typeof options === "object" ? options : {};
|
|
3060
|
+
const inEsBuildOptions = typeof compile2?.browser?.esbuildOptions === "object" ? compile2?.browser?.esbuildOptions : {};
|
|
3061
|
+
const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
|
|
3062
|
+
const platform = "browser";
|
|
3063
|
+
const rootOutDir = optionsObject.outDir ?? "dist";
|
|
3064
|
+
const outDir = rootOutDir + "/" + platform;
|
|
3065
|
+
return typeof srcDir === "string" ? await compileFolder(
|
|
3066
|
+
srcDir,
|
|
3067
|
+
entry,
|
|
3068
|
+
outDirAsBuildDir ? rootOutDir : "build",
|
|
3069
|
+
tsupOptions([
|
|
3070
|
+
inEsBuildOptions,
|
|
3071
|
+
compile2?.tsup?.options ?? {},
|
|
3072
|
+
typeof options === "object" ? options : {},
|
|
3073
|
+
{ platform: "browser", outDir }
|
|
3074
|
+
]),
|
|
3075
|
+
bundleTypes,
|
|
3076
|
+
verbose
|
|
3077
|
+
) : 0;
|
|
3078
|
+
})
|
|
3079
|
+
)).reduce((prev, value) => prev + value, 0) + (await Promise.all(
|
|
3080
|
+
Object.entries(compileForNeutral).map(async ([srcDir, options]) => {
|
|
3081
|
+
const optionsObject = typeof options === "object" ? options : {};
|
|
3082
|
+
const inEsBuildOptions = typeof compile2?.neutral?.esbuildOptions === "object" ? compile2?.neutral?.esbuildOptions : {};
|
|
3083
|
+
const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
|
|
3084
|
+
const platform = "neutral";
|
|
3085
|
+
const rootOutDir = optionsObject.outDir ?? "dist";
|
|
3086
|
+
const outDir = rootOutDir + "/" + platform;
|
|
3087
|
+
return typeof srcDir === "string" ? await compileFolder(
|
|
3088
|
+
srcDir,
|
|
3089
|
+
entry,
|
|
3090
|
+
outDirAsBuildDir ? rootOutDir : "build",
|
|
3091
|
+
tsupOptions([
|
|
3092
|
+
inEsBuildOptions,
|
|
3093
|
+
compile2?.tsup?.options ?? {},
|
|
3094
|
+
typeof options === "object" ? options : {},
|
|
3095
|
+
{ platform: "neutral", outDir }
|
|
3096
|
+
]),
|
|
3097
|
+
bundleTypes,
|
|
3098
|
+
verbose
|
|
3099
|
+
) : 0;
|
|
3100
|
+
})
|
|
3101
|
+
)).reduce((prev, value) => prev + value, 0) + 0;
|
|
3102
|
+
};
|
|
3103
|
+
|
|
3104
|
+
// src/actions/package/compile/compile.ts
|
|
3105
|
+
var packageCompile = async (inConfig = {}) => {
|
|
3106
|
+
const pkg = process.env.INIT_CWD;
|
|
3107
|
+
console.log(chalk40.green(`Compiling ${pkg}`));
|
|
3108
|
+
const config2 = await loadConfig(inConfig);
|
|
3109
|
+
return await packageCompileTsup(config2);
|
|
3110
|
+
};
|
|
3111
|
+
|
|
3112
|
+
// src/actions/package/copy-assets.ts
|
|
3113
|
+
import path12 from "path/posix";
|
|
3114
|
+
import chalk41 from "chalk";
|
|
3115
|
+
import cpy2 from "cpy";
|
|
3116
|
+
var copyTargetAssets2 = async (target, name, location) => {
|
|
3117
|
+
try {
|
|
3118
|
+
const values = await cpy2(
|
|
3119
|
+
["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
|
|
3120
|
+
`../dist/${target}`,
|
|
3121
|
+
{
|
|
3122
|
+
cwd: path12.join(location, "src"),
|
|
3123
|
+
flat: false
|
|
3124
|
+
}
|
|
3125
|
+
);
|
|
3126
|
+
if (values.length > 0) {
|
|
3127
|
+
console.log(chalk41.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`));
|
|
3128
|
+
}
|
|
3129
|
+
for (const value of values) {
|
|
3130
|
+
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
3131
|
+
}
|
|
3132
|
+
return 0;
|
|
3133
|
+
} catch (ex) {
|
|
3134
|
+
const error = ex;
|
|
3135
|
+
console.log(`Copy Assets Failed: ${name}: ${error.message}`);
|
|
3136
|
+
return 1;
|
|
3137
|
+
}
|
|
3138
|
+
};
|
|
3139
|
+
var packageCopyAssets = async ({ target }) => {
|
|
3140
|
+
const pkg = process.env.INIT_CWD ?? "./";
|
|
3141
|
+
const pkgName = process.env.npm_package_name ?? "Unknown";
|
|
3142
|
+
switch (target) {
|
|
3143
|
+
case "esm": {
|
|
3144
|
+
return await copyTargetAssets2("esm", pkgName, pkg);
|
|
3145
|
+
}
|
|
3146
|
+
case "cjs": {
|
|
3147
|
+
return await copyTargetAssets2("cjs", pkgName, pkg);
|
|
3148
|
+
}
|
|
3149
|
+
default: {
|
|
3150
|
+
return await copyTargetAssets2("esm", pkgName, pkg) || await copyTargetAssets2("cjs", pkgName, pkg);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
};
|
|
3154
|
+
|
|
3155
|
+
// src/actions/package/cycle.ts
|
|
3156
|
+
import { cruise as cruise2 } from "dependency-cruiser";
|
|
3157
|
+
var packageCycle = async () => {
|
|
3158
|
+
const pkg = process.env.INIT_CWD;
|
|
3159
|
+
const pkgName = process.env.npm_package_name;
|
|
3160
|
+
const cruiseOptions = {
|
|
3161
|
+
ruleSet: {
|
|
3162
|
+
forbidden: [
|
|
3163
|
+
{
|
|
3164
|
+
name: "no-circular",
|
|
3165
|
+
severity: "error",
|
|
3166
|
+
comment: "This dependency creates a circular reference",
|
|
3167
|
+
from: {},
|
|
3168
|
+
to: { circular: true }
|
|
3169
|
+
}
|
|
3170
|
+
]
|
|
3171
|
+
},
|
|
3172
|
+
exclude: "node_modules|packages/.*/packages",
|
|
3173
|
+
validate: true,
|
|
3174
|
+
doNotFollow: { path: "node_modules|packages/.*/packages" },
|
|
3175
|
+
tsPreCompilationDeps: false,
|
|
3176
|
+
combinedDependencies: true,
|
|
3177
|
+
outputType: "err"
|
|
3178
|
+
};
|
|
3179
|
+
const target = `${pkg}/src`;
|
|
3180
|
+
console.log(`Checking for circular dependencies in ${target}...`);
|
|
3181
|
+
const result = await cruise2([target], cruiseOptions);
|
|
3182
|
+
console.log(result.output);
|
|
3183
|
+
if (result.exitCode === 0) {
|
|
3184
|
+
console.log(`${pkgName} \u2705 No dependency violations`);
|
|
3185
|
+
} else {
|
|
3186
|
+
console.error(`${pkgName} \u274C Dependency violations found`);
|
|
3187
|
+
}
|
|
3188
|
+
return result.exitCode;
|
|
3189
|
+
};
|
|
3190
|
+
|
|
3191
|
+
// src/actions/package/gen-docs.ts
|
|
3192
|
+
import { existsSync as existsSync11 } from "fs";
|
|
3193
|
+
import path13 from "path";
|
|
3194
|
+
import chalk42 from "chalk";
|
|
3195
|
+
import {
|
|
3196
|
+
Application,
|
|
3197
|
+
ArgumentsReader,
|
|
3198
|
+
TSConfigReader,
|
|
3199
|
+
TypeDocReader
|
|
3200
|
+
} from "typedoc";
|
|
3201
|
+
var ExitCodes = {
|
|
3202
|
+
CompileError: 3,
|
|
3203
|
+
ExceptionThrown: 6,
|
|
3204
|
+
NoEntryPoints: 2,
|
|
3205
|
+
Ok: 0,
|
|
3206
|
+
OptionError: 1,
|
|
3207
|
+
OutputError: 5,
|
|
3208
|
+
ValidationError: 4
|
|
3209
|
+
};
|
|
3210
|
+
var packageGenDocs = async () => {
|
|
3211
|
+
const pkg = process.env.INIT_CWD;
|
|
3212
|
+
if (pkg !== void 0 && !existsSync11(path13.join(pkg, "typedoc.json"))) {
|
|
3213
|
+
return;
|
|
3214
|
+
}
|
|
3215
|
+
const app = await Application.bootstrap({
|
|
3216
|
+
entryPointStrategy: "merge",
|
|
3217
|
+
entryPoints: [`${pkg}/src/**/*.ts`, `${pkg}/packages/*/dist/docs.json`],
|
|
3218
|
+
excludeExternals: true,
|
|
3219
|
+
json: `${pkg}/dist/docs.json`,
|
|
3220
|
+
logLevel: "Error",
|
|
3221
|
+
tsconfig: `${pkg}/tsconfig.json`
|
|
3222
|
+
});
|
|
3223
|
+
app.options.addReader(new ArgumentsReader(0));
|
|
3224
|
+
app.options.addReader(new TypeDocReader());
|
|
3225
|
+
app.options.addReader(new TSConfigReader());
|
|
3226
|
+
app.options.addReader(new ArgumentsReader(300));
|
|
3227
|
+
return await runTypeDoc(app);
|
|
3228
|
+
};
|
|
3229
|
+
var runTypeDoc = async (app) => {
|
|
3230
|
+
const pkgName = process.env.npm_package_name;
|
|
3231
|
+
if (app.options.getValue("version")) {
|
|
3232
|
+
console.log(app.toString());
|
|
3233
|
+
return ExitCodes.Ok;
|
|
3234
|
+
}
|
|
3235
|
+
if (app.options.getValue("showConfig")) {
|
|
3236
|
+
console.log(app.options.getRawValues());
|
|
3237
|
+
return ExitCodes.Ok;
|
|
3238
|
+
}
|
|
3239
|
+
if (app.logger.hasErrors()) {
|
|
3240
|
+
return ExitCodes.OptionError;
|
|
3241
|
+
}
|
|
3242
|
+
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3243
|
+
return ExitCodes.OptionError;
|
|
3244
|
+
}
|
|
3245
|
+
if (app.options.getValue("entryPoints").length === 0) {
|
|
3246
|
+
app.logger.error("No entry points provided");
|
|
3247
|
+
return ExitCodes.NoEntryPoints;
|
|
3248
|
+
}
|
|
3249
|
+
if (app.options.getValue("watch")) {
|
|
3250
|
+
await app.convertAndWatch(async (project2) => {
|
|
3251
|
+
const out = app.options.getValue("out");
|
|
3252
|
+
if (out) {
|
|
3253
|
+
await app.generateDocs(project2, out);
|
|
3254
|
+
}
|
|
3255
|
+
const json = app.options.getValue("json");
|
|
3256
|
+
if (json) {
|
|
3257
|
+
await app.generateJson(project2, json);
|
|
3258
|
+
}
|
|
3259
|
+
if (!out && !json) {
|
|
3260
|
+
await app.generateDocs(project2, "./docs");
|
|
3261
|
+
}
|
|
3262
|
+
});
|
|
3263
|
+
return ExitCodes.Ok;
|
|
3264
|
+
}
|
|
3265
|
+
const project = await app.convert();
|
|
3266
|
+
if (!project) {
|
|
3267
|
+
return ExitCodes.CompileError;
|
|
3268
|
+
}
|
|
3269
|
+
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3270
|
+
return ExitCodes.CompileError;
|
|
3271
|
+
}
|
|
3272
|
+
app.validate(project);
|
|
3273
|
+
if (app.logger.hasErrors()) {
|
|
3274
|
+
return ExitCodes.ValidationError;
|
|
3275
|
+
}
|
|
3276
|
+
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3277
|
+
return ExitCodes.ValidationError;
|
|
3278
|
+
}
|
|
3279
|
+
if (app.options.getValue("emit") !== "none") {
|
|
3280
|
+
const out = app.options.getValue("out");
|
|
3281
|
+
if (out) {
|
|
3282
|
+
await app.generateDocs(project, out);
|
|
3283
|
+
}
|
|
3284
|
+
const json = app.options.getValue("json");
|
|
3285
|
+
if (json) {
|
|
3286
|
+
await app.generateJson(project, json);
|
|
3287
|
+
}
|
|
3288
|
+
if (!out && !json) {
|
|
3289
|
+
await app.generateDocs(project, "./docs");
|
|
3290
|
+
}
|
|
3291
|
+
if (app.logger.hasErrors()) {
|
|
3292
|
+
return ExitCodes.OutputError;
|
|
3293
|
+
}
|
|
3294
|
+
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3295
|
+
return ExitCodes.OutputError;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
console.log(chalk42.green(`${pkgName} - Ok`));
|
|
3299
|
+
return ExitCodes.Ok;
|
|
3300
|
+
};
|
|
3301
|
+
|
|
3302
|
+
// src/actions/package/lint.ts
|
|
3303
|
+
import { readdirSync as readdirSync6 } from "fs";
|
|
3304
|
+
import path14 from "path";
|
|
3305
|
+
import { cwd as cwd4 } from "process";
|
|
3306
|
+
import { pathToFileURL } from "url";
|
|
3307
|
+
import chalk43 from "chalk";
|
|
3308
|
+
import { ESLint } from "eslint";
|
|
3309
|
+
import { findUp as findUp2 } from "find-up";
|
|
3310
|
+
import picomatch from "picomatch";
|
|
3311
|
+
var dumpMessages = (lintResults) => {
|
|
3312
|
+
const colors = ["white", "yellow", "red"];
|
|
3313
|
+
const severity = ["none", "warning", "error"];
|
|
3314
|
+
for (const lintResult of lintResults) {
|
|
3315
|
+
if (lintResult.messages.length > 0) {
|
|
3316
|
+
console.log(chalk43.gray(`
|
|
3317
|
+
${lintResult.filePath}`));
|
|
3318
|
+
for (const message of lintResult.messages) {
|
|
3319
|
+
console.log(
|
|
3320
|
+
chalk43.gray(` ${message.line}:${message.column}`),
|
|
3321
|
+
chalk43[colors[message.severity]](` ${severity[message.severity]}`),
|
|
3322
|
+
chalk43.white(` ${message.message}`),
|
|
3323
|
+
chalk43.gray(` ${message.ruleId}`)
|
|
3324
|
+
);
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
};
|
|
3329
|
+
async function getRootESLintConfig() {
|
|
3330
|
+
const configPath = await findUp2("eslint.config.mjs");
|
|
3331
|
+
if (configPath === void 0) {
|
|
3332
|
+
throw new Error("eslint.config.mjs not found in the monorepo");
|
|
3333
|
+
}
|
|
3334
|
+
return pathToFileURL(configPath);
|
|
3335
|
+
}
|
|
3336
|
+
function getFiles(dir, ignoreFolders) {
|
|
3337
|
+
const currentDirectory = cwd4();
|
|
3338
|
+
const subDirectory = dir.split(currentDirectory)[1]?.split("/")[1];
|
|
3339
|
+
if (ignoreFolders.includes(subDirectory)) return [];
|
|
3340
|
+
return readdirSync6(dir, { withFileTypes: true }).flatMap((dirent) => {
|
|
3341
|
+
const res = path14.resolve(dir, dirent.name);
|
|
3342
|
+
const relativePath = subDirectory === void 0 ? dirent.name : `${subDirectory}/${dirent.name}`;
|
|
3343
|
+
const ignoreMatchers = ignoreFolders.map((pattern) => picomatch(pattern));
|
|
3344
|
+
if (ignoreMatchers.some((isMatch) => isMatch(relativePath))) return [];
|
|
3345
|
+
return dirent.isDirectory() ? getFiles(res, ignoreFolders) : [res];
|
|
3346
|
+
});
|
|
3347
|
+
}
|
|
3348
|
+
var packageLint = async (fix2 = false, verbose = false, cache = true) => {
|
|
3349
|
+
const pkg = process.env.INIT_CWD;
|
|
3350
|
+
const configPath = await getRootESLintConfig();
|
|
3351
|
+
const { default: eslintConfig } = await import(configPath.href);
|
|
3352
|
+
const start = Date.now();
|
|
3353
|
+
const ignoreFolders = ["node_modules", "dist", "packages", ".git", "build", ".yarn", ".vscode", ".github"];
|
|
3354
|
+
const engine = new ESLint({
|
|
3355
|
+
baseConfig: [...eslintConfig],
|
|
3356
|
+
fix: fix2,
|
|
3357
|
+
warnIgnored: false,
|
|
3358
|
+
cache
|
|
3359
|
+
});
|
|
3360
|
+
const files = getFiles(cwd4(), ignoreFolders);
|
|
3361
|
+
console.log(chalk43.green(`Linting ${pkg} [files = ${files.length}]`));
|
|
3362
|
+
if (verbose) {
|
|
3363
|
+
for (const file of files) {
|
|
3364
|
+
console.log(chalk43.gray(` ${file}`));
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
const lintResults = await engine.lintFiles(files);
|
|
3368
|
+
dumpMessages(lintResults);
|
|
3369
|
+
if (fix2) {
|
|
3370
|
+
await ESLint.outputFixes(lintResults);
|
|
3371
|
+
}
|
|
3372
|
+
const filesCountColor = files.length < 100 ? "green" : files.length < 1e3 ? "yellow" : "red";
|
|
3373
|
+
const lintTime = Date.now() - start;
|
|
3374
|
+
const lintTimeColor = lintTime < 1e3 ? "green" : lintTime < 3e3 ? "yellow" : "red";
|
|
3375
|
+
console.log(chalk43.white(`Linted ${chalk43[filesCountColor](files.length)} files in ${chalk43[lintTimeColor](lintTime)}ms`));
|
|
3376
|
+
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
3377
|
+
};
|
|
3378
|
+
|
|
3379
|
+
// src/actions/package/publint.ts
|
|
3380
|
+
import { promises as fs10 } from "fs";
|
|
3381
|
+
import chalk44 from "chalk";
|
|
3382
|
+
import sortPackageJson from "sort-package-json";
|
|
3383
|
+
var customPubLint = (pkg) => {
|
|
3384
|
+
let errorCount = 0;
|
|
3385
|
+
let warningCount = 0;
|
|
3386
|
+
if (pkg.files === void 0) {
|
|
3387
|
+
console.warn(chalk44.yellow('Publint [custom]: "files" field is missing'));
|
|
3388
|
+
warningCount++;
|
|
3389
|
+
}
|
|
3390
|
+
if (pkg.main !== void 0) {
|
|
3391
|
+
console.warn(chalk44.yellow('Publint [custom]: "main" field is deprecated, use "exports" instead'));
|
|
3392
|
+
warningCount++;
|
|
3393
|
+
}
|
|
3394
|
+
if (pkg.sideEffects !== false) {
|
|
3395
|
+
console.warn(chalk44.yellow('Publint [custom]: "sideEffects" field should be set to false'));
|
|
3396
|
+
warningCount++;
|
|
3397
|
+
}
|
|
3398
|
+
if (pkg.resolutions !== void 0) {
|
|
3399
|
+
console.warn(chalk44.yellow('Publint [custom]: "resolutions" in use'));
|
|
3400
|
+
console.warn(chalk44.gray(JSON.stringify(pkg.resolutions, null, 2)));
|
|
3401
|
+
warningCount++;
|
|
3402
|
+
}
|
|
3403
|
+
return [errorCount, warningCount];
|
|
3404
|
+
};
|
|
3405
|
+
var packagePublint = async ({ strict = true, verbose = false } = {}) => {
|
|
3406
|
+
const pkgDir = process.env.INIT_CWD;
|
|
3407
|
+
const sortedPkg = sortPackageJson(await fs10.readFile(`${pkgDir}/package.json`, "utf8"));
|
|
3408
|
+
await fs10.writeFile(`${pkgDir}/package.json`, sortedPkg);
|
|
3409
|
+
const pkg = JSON.parse(await fs10.readFile(`${pkgDir}/package.json`, "utf8"));
|
|
3410
|
+
console.log(chalk44.green(`Publint: ${pkg.name}`));
|
|
3411
|
+
console.log(chalk44.gray(pkgDir));
|
|
3412
|
+
const { publint: publint2 } = await import("publint");
|
|
3413
|
+
const { messages } = await publint2({
|
|
3414
|
+
level: "suggestion",
|
|
3415
|
+
pkgDir,
|
|
3416
|
+
strict
|
|
3417
|
+
});
|
|
3418
|
+
const { formatMessage } = await import("publint/utils");
|
|
3419
|
+
for (const message of messages) {
|
|
3420
|
+
switch (message.type) {
|
|
3421
|
+
case "error": {
|
|
3422
|
+
console.error(chalk44.red(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
3423
|
+
break;
|
|
3424
|
+
}
|
|
3425
|
+
case "warning": {
|
|
3426
|
+
console.warn(chalk44.yellow(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
3427
|
+
break;
|
|
3428
|
+
}
|
|
3429
|
+
default: {
|
|
3430
|
+
console.log(chalk44.white(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
3431
|
+
break;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
const [errorCount, warningCount] = customPubLint(pkg);
|
|
3436
|
+
if (verbose) {
|
|
3437
|
+
console.log(chalk44.gray(`Publint [Finish]: ${pkgDir} [${messages.length + errorCount + warningCount} messages]`));
|
|
3438
|
+
}
|
|
3439
|
+
return messages.filter((message) => message.type === "error").length + errorCount;
|
|
3440
|
+
};
|
|
3441
|
+
|
|
3442
|
+
// src/actions/package/recompile.ts
|
|
3443
|
+
var packageRecompile = async () => {
|
|
3444
|
+
return await packageClean() || await packageCompile();
|
|
3445
|
+
};
|
|
3446
|
+
|
|
3447
|
+
// src/actions/package-lint.ts
|
|
3448
|
+
import { readFileSync as readFileSync13, writeFileSync as writeFileSync7 } from "fs";
|
|
3449
|
+
import PATH11 from "path";
|
|
3450
|
+
import chalk45 from "chalk";
|
|
3451
|
+
import picomatch2 from "picomatch";
|
|
3452
|
+
function emptyResult() {
|
|
3453
|
+
return {
|
|
3454
|
+
errors: [],
|
|
3455
|
+
fixable: [],
|
|
3456
|
+
warnings: []
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3459
|
+
function readRootPackageJson(cwd5) {
|
|
3460
|
+
const raw = readFileSync13(PATH11.resolve(cwd5, "package.json"), "utf8");
|
|
3461
|
+
return JSON.parse(raw);
|
|
3462
|
+
}
|
|
3463
|
+
function writeRootPackageJson(cwd5, pkg) {
|
|
3464
|
+
const path15 = PATH11.resolve(cwd5, "package.json");
|
|
3465
|
+
writeFileSync7(path15, `${JSON.stringify(pkg, null, 2)}
|
|
3466
|
+
`, "utf8");
|
|
3467
|
+
}
|
|
3468
|
+
function isMonorepo(pkg) {
|
|
3469
|
+
const workspaces = pkg.workspaces;
|
|
3470
|
+
return Array.isArray(workspaces) && workspaces.length > 0;
|
|
3471
|
+
}
|
|
3472
|
+
function checkPackagesFolder(workspaces) {
|
|
3473
|
+
const result = emptyResult();
|
|
3474
|
+
for (const { location, name } of workspaces) {
|
|
3475
|
+
if (location === ".") continue;
|
|
3476
|
+
if (!location.startsWith("packages/") && !location.startsWith("packages\\")) {
|
|
3477
|
+
result.errors.push(`${name} (${location}) is not inside a packages/ folder`);
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
return result;
|
|
3481
|
+
}
|
|
3482
|
+
function checkRootPrivate(pkg) {
|
|
3483
|
+
const result = emptyResult();
|
|
3484
|
+
if (!pkg.private) {
|
|
3485
|
+
result.fixable.push("Root package.json must be private to prevent accidental publishing");
|
|
3486
|
+
}
|
|
3487
|
+
return result;
|
|
3488
|
+
}
|
|
3489
|
+
function fixRootPrivate(cwd5, pkg) {
|
|
3490
|
+
pkg.private = true;
|
|
3491
|
+
writeRootPackageJson(cwd5, pkg);
|
|
3492
|
+
console.log(chalk45.green(' \u2714 Fixed: set "private": true in root package.json'));
|
|
3493
|
+
}
|
|
3494
|
+
function checkNoPublishConfigOnPrivate(pkg) {
|
|
3495
|
+
const result = emptyResult();
|
|
3496
|
+
if (pkg.private && pkg.publishConfig) {
|
|
3497
|
+
result.fixable.push("Root package.json has publishConfig but is private \u2014 publishConfig is unnecessary");
|
|
3498
|
+
}
|
|
3499
|
+
return result;
|
|
3500
|
+
}
|
|
3501
|
+
function fixNoPublishConfigOnPrivate(cwd5, pkg) {
|
|
3502
|
+
delete pkg.publishConfig;
|
|
3503
|
+
writeRootPackageJson(cwd5, pkg);
|
|
3504
|
+
console.log(chalk45.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
|
|
3505
|
+
}
|
|
3506
|
+
function checkDiscoverable(pkg, workspaces) {
|
|
3507
|
+
const result = emptyResult();
|
|
3508
|
+
const globs = pkg.workspaces;
|
|
3509
|
+
const matchers = globs.map((glob3) => picomatch2(glob3));
|
|
3510
|
+
const isMatch = (location) => matchers.some((m) => m(location));
|
|
3511
|
+
for (const { location, name } of workspaces) {
|
|
3512
|
+
if (location === ".") continue;
|
|
3513
|
+
if (!isMatch(location)) {
|
|
3514
|
+
result.errors.push(`${name} (${location}) is not matched by any workspace glob in package.json`);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
return result;
|
|
3518
|
+
}
|
|
3519
|
+
function logResults(label, result, fix2) {
|
|
3520
|
+
let errors = 0;
|
|
3521
|
+
let fixed = 0;
|
|
3522
|
+
for (const error of result.errors) {
|
|
3523
|
+
console.log(chalk45.red(` \u2717 ${error}`));
|
|
3524
|
+
errors++;
|
|
3525
|
+
}
|
|
3526
|
+
for (const fixable of result.fixable) {
|
|
3527
|
+
if (fix2) {
|
|
3528
|
+
fixed++;
|
|
3529
|
+
} else {
|
|
3530
|
+
console.log(chalk45.red(` \u2717 ${fixable} (fixable)`));
|
|
3531
|
+
errors++;
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
for (const warning of result.warnings) {
|
|
3535
|
+
console.log(chalk45.yellow(` \u26A0 ${warning}`));
|
|
3536
|
+
}
|
|
3537
|
+
if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
|
|
3538
|
+
console.log(chalk45.green(` \u2713 ${label}`));
|
|
3539
|
+
}
|
|
3540
|
+
return { errors, fixed };
|
|
3541
|
+
}
|
|
3542
|
+
function runChecks(entries, cwd5, pkg, fix2) {
|
|
3543
|
+
let totalErrors = 0;
|
|
3544
|
+
let totalFixed = 0;
|
|
3545
|
+
for (const entry of entries) {
|
|
3546
|
+
const result = entry.check();
|
|
3547
|
+
const log = logResults(entry.label, result, fix2);
|
|
3548
|
+
if (fix2 && entry.fix && result.fixable.length > 0) {
|
|
3549
|
+
entry.fix(cwd5, pkg);
|
|
3550
|
+
}
|
|
3551
|
+
totalErrors += log.errors;
|
|
3552
|
+
totalFixed += log.fixed;
|
|
3553
|
+
}
|
|
3554
|
+
return { errors: totalErrors, fixed: totalFixed };
|
|
3555
|
+
}
|
|
3556
|
+
function logSummary(errors, fixed) {
|
|
3557
|
+
if (fixed > 0) {
|
|
3558
|
+
console.log(chalk45.green(`
|
|
3559
|
+
Fixed ${fixed} issue(s)`));
|
|
3560
|
+
}
|
|
3561
|
+
if (errors > 0) {
|
|
3562
|
+
console.log(chalk45.red(`
|
|
3563
|
+
${errors} error(s) found`));
|
|
3564
|
+
} else if (fixed === 0) {
|
|
3565
|
+
console.log(chalk45.green("\n All checks passed"));
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
function packageLintMonorepo(fix2 = false) {
|
|
3569
|
+
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
3570
|
+
let pkg;
|
|
3571
|
+
try {
|
|
3572
|
+
pkg = readRootPackageJson(cwd5);
|
|
3573
|
+
} catch {
|
|
3574
|
+
console.error(chalk45.red("Could not read package.json"));
|
|
3575
|
+
return 1;
|
|
3576
|
+
}
|
|
3577
|
+
if (!isMonorepo(pkg)) {
|
|
3578
|
+
console.log(chalk45.gray("Not a monorepo \u2014 skipping package-lint checks"));
|
|
3579
|
+
return 0;
|
|
3580
|
+
}
|
|
3581
|
+
console.log(chalk45.green("Package Lint"));
|
|
3582
|
+
const workspaces = getPackageManager().listWorkspaces();
|
|
3583
|
+
const checks = [
|
|
3584
|
+
{
|
|
3585
|
+
check: () => checkRootPrivate(pkg),
|
|
3586
|
+
fix: fixRootPrivate,
|
|
3587
|
+
label: "Root package is private"
|
|
3588
|
+
},
|
|
3589
|
+
{
|
|
3590
|
+
check: () => checkNoPublishConfigOnPrivate(pkg),
|
|
3591
|
+
fix: fixNoPublishConfigOnPrivate,
|
|
3592
|
+
label: "No publishConfig on private root"
|
|
3593
|
+
},
|
|
3594
|
+
{ check: () => checkPackagesFolder(workspaces), label: "All packages are in packages/ folder" },
|
|
3595
|
+
{ check: () => checkDiscoverable(pkg, workspaces), label: "All packages are discoverable from workspace globs" }
|
|
3596
|
+
];
|
|
3597
|
+
const { errors, fixed } = runChecks(checks, cwd5, pkg, fix2);
|
|
3598
|
+
logSummary(errors, fixed);
|
|
3599
|
+
return errors > 0 ? 1 : 0;
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
// src/actions/packman/convert.ts
|
|
3603
|
+
import {
|
|
3604
|
+
existsSync as existsSync14,
|
|
3605
|
+
readdirSync as readdirSync7,
|
|
3606
|
+
readFileSync as readFileSync16,
|
|
3607
|
+
statSync as statSync3
|
|
3608
|
+
} from "fs";
|
|
3609
|
+
import PATH14 from "path";
|
|
3610
|
+
import chalk48 from "chalk";
|
|
3611
|
+
|
|
3612
|
+
// src/actions/packman/convertToPnpm.ts
|
|
3613
|
+
import {
|
|
3614
|
+
existsSync as existsSync12,
|
|
3615
|
+
mkdirSync as mkdirSync5,
|
|
3616
|
+
readFileSync as readFileSync14,
|
|
3617
|
+
rmSync as rmSync3,
|
|
3618
|
+
writeFileSync as writeFileSync8
|
|
3619
|
+
} from "fs";
|
|
3620
|
+
import PATH12 from "path";
|
|
3621
|
+
import chalk46 from "chalk";
|
|
3622
|
+
|
|
3623
|
+
// src/actions/packman/rewriteScripts.ts
|
|
3624
|
+
function rewriteYarnToPnpm(script) {
|
|
3625
|
+
let result = script;
|
|
3626
|
+
result = result.replaceAll(/\byarn workspace (\S+) run /g, "pnpm --filter $1 run ");
|
|
3627
|
+
result = result.replaceAll(/\byarn workspace (\S+) (package-\S+)/g, "pnpm --filter $1 run $2");
|
|
3628
|
+
result = result.replaceAll(/\byarn workspaces foreach\s+(?:[^\s]*\s+)*run /g, "pnpm -r run ");
|
|
3629
|
+
result = result.replaceAll(/\byarn workspaces foreach --all version (\S+) --deferred/g, "pnpm -r exec npm version $1 --no-git-tag-version");
|
|
3630
|
+
result = result.replaceAll(/\byarn version apply --all/g, 'echo "versions applied"');
|
|
3631
|
+
result = result.replaceAll(/\byarn xy\b/g, "pnpm xy");
|
|
3632
|
+
result = result.replaceAll(/\byarn add\b/g, "pnpm add");
|
|
3633
|
+
result = result.replaceAll(/\byarn remove\b/g, "pnpm remove");
|
|
3634
|
+
result = result.replaceAll(/\byarn install\b/g, "pnpm install");
|
|
3635
|
+
result = result.replaceAll(/\byarn dedupe\b/g, "pnpm dedupe");
|
|
3636
|
+
result = result.replaceAll(/\byarn outdated\b/g, "pnpm outdated");
|
|
3637
|
+
result = result.replaceAll(/\byarn run\b/g, "pnpm run");
|
|
3638
|
+
result = result.replaceAll(/\byarn rimraf\b/g, "rimraf");
|
|
3639
|
+
result = result.replaceAll(/\byarn npm\b/g, "npm");
|
|
3640
|
+
result = result.replaceAll(/\byarn\b(?![@/.])/g, "pnpm");
|
|
3641
|
+
return result;
|
|
3642
|
+
}
|
|
3643
|
+
function rewritePnpmToYarn(script) {
|
|
3644
|
+
let result = script;
|
|
3645
|
+
result = result.replaceAll(/\bpnpm --filter (\S+) run /g, "yarn workspace $1 run ");
|
|
3646
|
+
result = result.replaceAll(/\bpnpm -r run /g, "yarn workspaces foreach -Apt run ");
|
|
3647
|
+
result = result.replaceAll(/\bpnpm -r exec npm version (\S+) --no-git-tag-version/g, "yarn workspaces foreach --all version $1 --deferred");
|
|
3648
|
+
result = result.replaceAll(/\bpnpm xy\b/g, "yarn xy");
|
|
3649
|
+
result = result.replaceAll(/\bpnpm add\b/g, "yarn add");
|
|
3650
|
+
result = result.replaceAll(/\bpnpm remove\b/g, "yarn remove");
|
|
3651
|
+
result = result.replaceAll(/\bpnpm install\b/g, "yarn install");
|
|
3652
|
+
result = result.replaceAll(/\bpnpm dedupe\b/g, "yarn dedupe");
|
|
3653
|
+
result = result.replaceAll(/\bpnpm outdated\b/g, "yarn outdated");
|
|
3654
|
+
result = result.replaceAll(/\bpnpm run\b/g, "yarn run");
|
|
3655
|
+
result = result.replaceAll(/\bpnpm\b(?![@/.])/g, "yarn");
|
|
3656
|
+
return result;
|
|
3657
|
+
}
|
|
3658
|
+
function rewriteScript(script, direction) {
|
|
3659
|
+
return direction === "yarn-to-pnpm" ? rewriteYarnToPnpm(script) : rewritePnpmToYarn(script);
|
|
3660
|
+
}
|
|
3661
|
+
function rewriteScriptsInPackageJson(pkg, direction) {
|
|
3662
|
+
const scripts = pkg.scripts;
|
|
3663
|
+
if (!scripts) return pkg;
|
|
3664
|
+
const rewritten = {};
|
|
3665
|
+
for (const [name, script] of Object.entries(scripts)) {
|
|
3666
|
+
rewritten[name] = rewriteScript(script, direction);
|
|
3667
|
+
}
|
|
3668
|
+
return { ...pkg, scripts: rewritten };
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
// src/actions/packman/convertToPnpm.ts
|
|
3672
|
+
var PNPM_VERSION = "10.12.1";
|
|
3673
|
+
function createPnpmWorkspaceYaml(cwd5, workspacePatterns) {
|
|
3674
|
+
const lines = ["packages:"];
|
|
3675
|
+
for (const pattern of workspacePatterns) {
|
|
3676
|
+
lines.push(` - '${pattern}'`);
|
|
3677
|
+
}
|
|
3678
|
+
writeFileSync8(PATH12.join(cwd5, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
3679
|
+
console.log(chalk46.green(" Created pnpm-workspace.yaml"));
|
|
3680
|
+
}
|
|
3681
|
+
function updateRootPackageJson(cwd5) {
|
|
3682
|
+
const pkgPath = PATH12.join(cwd5, "package.json");
|
|
3683
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
3684
|
+
const workspacePatterns = pkg.workspaces ?? [];
|
|
3685
|
+
delete pkg.workspaces;
|
|
3686
|
+
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
3687
|
+
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
3688
|
+
writeFileSync8(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3689
|
+
console.log(chalk46.green(" Updated root package.json"));
|
|
3690
|
+
return workspacePatterns;
|
|
3691
|
+
}
|
|
3692
|
+
function updateGitignore(cwd5) {
|
|
3693
|
+
const gitignorePath = PATH12.join(cwd5, ".gitignore");
|
|
3694
|
+
if (!existsSync12(gitignorePath)) return;
|
|
3695
|
+
let content = readFileSync14(gitignorePath, "utf8");
|
|
3696
|
+
const yarnLines = [
|
|
3697
|
+
".pnp.*",
|
|
3698
|
+
".pnp",
|
|
3699
|
+
".yarn/*",
|
|
3700
|
+
"!.yarn/patches",
|
|
3701
|
+
"!.yarn/plugins",
|
|
3702
|
+
"!.yarn/releases",
|
|
3703
|
+
"!.yarn/sdks",
|
|
3704
|
+
"!.yarn/versions"
|
|
3705
|
+
];
|
|
3706
|
+
for (const line of yarnLines) {
|
|
3707
|
+
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
3708
|
+
}
|
|
3709
|
+
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
3710
|
+
writeFileSync8(gitignorePath, content, "utf8");
|
|
3711
|
+
console.log(chalk46.green(" Updated .gitignore"));
|
|
3712
|
+
}
|
|
3713
|
+
function deleteYarnArtifacts(cwd5) {
|
|
3714
|
+
const yarnLock = PATH12.join(cwd5, "yarn.lock");
|
|
3715
|
+
const yarnrc = PATH12.join(cwd5, ".yarnrc.yml");
|
|
3716
|
+
const yarnDir = PATH12.join(cwd5, ".yarn");
|
|
3717
|
+
if (existsSync12(yarnLock)) {
|
|
3718
|
+
rmSync3(yarnLock);
|
|
3719
|
+
console.log(chalk46.gray(" Deleted yarn.lock"));
|
|
3720
|
+
}
|
|
3721
|
+
if (existsSync12(yarnrc)) {
|
|
3722
|
+
rmSync3(yarnrc);
|
|
3723
|
+
console.log(chalk46.gray(" Deleted .yarnrc.yml"));
|
|
3724
|
+
}
|
|
3725
|
+
if (existsSync12(yarnDir)) {
|
|
3726
|
+
rmSync3(yarnDir, { force: true, recursive: true });
|
|
3727
|
+
console.log(chalk46.gray(" Deleted .yarn/"));
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
function createNpmrc(cwd5) {
|
|
3731
|
+
const npmrcPath = PATH12.join(cwd5, ".npmrc");
|
|
3732
|
+
if (existsSync12(npmrcPath)) return;
|
|
3733
|
+
mkdirSync5(PATH12.dirname(npmrcPath), { recursive: true });
|
|
3734
|
+
writeFileSync8(npmrcPath, "", "utf8");
|
|
3735
|
+
console.log(chalk46.green(" Created .npmrc"));
|
|
3736
|
+
}
|
|
3737
|
+
function convertToPnpm(cwd5, workspacePackageJsonPaths) {
|
|
3738
|
+
console.log(chalk46.blue("\nConverting to pnpm...\n"));
|
|
3739
|
+
const workspacePatterns = updateRootPackageJson(cwd5);
|
|
3740
|
+
createPnpmWorkspaceYaml(cwd5, workspacePatterns);
|
|
3741
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3742
|
+
const fullPath = PATH12.resolve(cwd5, pkgPath, "package.json");
|
|
3743
|
+
if (!existsSync12(fullPath)) continue;
|
|
3744
|
+
const pkg = JSON.parse(readFileSync14(fullPath, "utf8"));
|
|
3745
|
+
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
3746
|
+
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
3747
|
+
writeFileSync8(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
console.log(chalk46.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
3751
|
+
updateGitignore(cwd5);
|
|
3752
|
+
createNpmrc(cwd5);
|
|
3753
|
+
deleteYarnArtifacts(cwd5);
|
|
3754
|
+
console.log(chalk46.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
3755
|
+
return 0;
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
// src/actions/packman/convertToYarn.ts
|
|
3759
|
+
import {
|
|
3760
|
+
existsSync as existsSync13,
|
|
3761
|
+
readFileSync as readFileSync15,
|
|
3762
|
+
rmSync as rmSync4,
|
|
3763
|
+
writeFileSync as writeFileSync9
|
|
3764
|
+
} from "fs";
|
|
3765
|
+
import PATH13 from "path";
|
|
3766
|
+
import chalk47 from "chalk";
|
|
3767
|
+
var YARN_VERSION = "4.13.0";
|
|
3768
|
+
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
3769
|
+
|
|
3770
|
+
enableGlobalCache: true
|
|
3771
|
+
|
|
3772
|
+
enableInlineBuilds: true
|
|
3773
|
+
|
|
3774
|
+
nmHoistingLimits: none
|
|
3775
|
+
|
|
3776
|
+
nodeLinker: node-modules
|
|
3777
|
+
`;
|
|
3778
|
+
var YARN_GITIGNORE_ENTRIES = `
|
|
3779
|
+
.pnp.*
|
|
3780
|
+
.yarn/*
|
|
3781
|
+
!.yarn/patches
|
|
3782
|
+
!.yarn/plugins
|
|
3783
|
+
!.yarn/releases
|
|
3784
|
+
!.yarn/sdks
|
|
3785
|
+
!.yarn/versions
|
|
3786
|
+
`;
|
|
3787
|
+
function readPnpmWorkspacePatterns(cwd5) {
|
|
3788
|
+
const wsPath = PATH13.join(cwd5, "pnpm-workspace.yaml");
|
|
3789
|
+
if (!existsSync13(wsPath)) return [];
|
|
3790
|
+
const content = readFileSync15(wsPath, "utf8");
|
|
3791
|
+
const patterns = [];
|
|
3792
|
+
const lines = content.split("\n");
|
|
3793
|
+
let inPackages = false;
|
|
3794
|
+
for (const line of lines) {
|
|
3795
|
+
if (line.trim() === "packages:") {
|
|
3796
|
+
inPackages = true;
|
|
3797
|
+
continue;
|
|
3798
|
+
}
|
|
3799
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
3800
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
3801
|
+
if (pattern) patterns.push(pattern);
|
|
3802
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
3803
|
+
inPackages = false;
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
return patterns;
|
|
3807
|
+
}
|
|
3808
|
+
function updateRootPackageJson2(cwd5, workspacePatterns) {
|
|
3809
|
+
const pkgPath = PATH13.join(cwd5, "package.json");
|
|
3810
|
+
const pkg = JSON.parse(readFileSync15(pkgPath, "utf8"));
|
|
3811
|
+
pkg.workspaces = workspacePatterns;
|
|
3812
|
+
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
3813
|
+
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
3814
|
+
writeFileSync9(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3815
|
+
console.log(chalk47.green(" Updated root package.json"));
|
|
3816
|
+
}
|
|
3817
|
+
function updateGitignore2(cwd5) {
|
|
3818
|
+
const gitignorePath = PATH13.join(cwd5, ".gitignore");
|
|
3819
|
+
let content = existsSync13(gitignorePath) ? readFileSync15(gitignorePath, "utf8") : "";
|
|
3820
|
+
if (!content.includes(".yarn/*")) {
|
|
3821
|
+
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
3822
|
+
}
|
|
3823
|
+
writeFileSync9(gitignorePath, content, "utf8");
|
|
3824
|
+
console.log(chalk47.green(" Updated .gitignore"));
|
|
3825
|
+
}
|
|
3826
|
+
function deletePnpmArtifacts(cwd5) {
|
|
3827
|
+
const lockfile = PATH13.join(cwd5, "pnpm-lock.yaml");
|
|
3828
|
+
const workspaceYaml = PATH13.join(cwd5, "pnpm-workspace.yaml");
|
|
3829
|
+
const npmrc = PATH13.join(cwd5, ".npmrc");
|
|
3830
|
+
if (existsSync13(lockfile)) {
|
|
3831
|
+
rmSync4(lockfile);
|
|
3832
|
+
console.log(chalk47.gray(" Deleted pnpm-lock.yaml"));
|
|
3833
|
+
}
|
|
3834
|
+
if (existsSync13(workspaceYaml)) {
|
|
3835
|
+
rmSync4(workspaceYaml);
|
|
3836
|
+
console.log(chalk47.gray(" Deleted pnpm-workspace.yaml"));
|
|
3837
|
+
}
|
|
3838
|
+
if (existsSync13(npmrc)) {
|
|
3839
|
+
const content = readFileSync15(npmrc, "utf8");
|
|
3840
|
+
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
3841
|
+
rmSync4(npmrc);
|
|
3842
|
+
console.log(chalk47.gray(" Deleted .npmrc"));
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
function createYarnrc(cwd5) {
|
|
3847
|
+
const yarnrcPath = PATH13.join(cwd5, ".yarnrc.yml");
|
|
3848
|
+
if (existsSync13(yarnrcPath)) return;
|
|
3849
|
+
writeFileSync9(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
3850
|
+
console.log(chalk47.green(" Created .yarnrc.yml"));
|
|
3851
|
+
}
|
|
3852
|
+
function convertToYarn(cwd5, workspacePackageJsonPaths) {
|
|
3853
|
+
console.log(chalk47.blue("\nConverting to yarn...\n"));
|
|
3854
|
+
const workspacePatterns = readPnpmWorkspacePatterns(cwd5);
|
|
3855
|
+
if (workspacePatterns.length === 0) {
|
|
3856
|
+
console.warn(chalk47.yellow(" No workspace patterns found in pnpm-workspace.yaml"));
|
|
3857
|
+
}
|
|
3858
|
+
updateRootPackageJson2(cwd5, workspacePatterns);
|
|
3859
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3860
|
+
const fullPath = PATH13.resolve(cwd5, pkgPath, "package.json");
|
|
3861
|
+
if (!existsSync13(fullPath)) continue;
|
|
3862
|
+
const pkg = JSON.parse(readFileSync15(fullPath, "utf8"));
|
|
3863
|
+
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
3864
|
+
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
3865
|
+
writeFileSync9(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
console.log(chalk47.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
3869
|
+
updateGitignore2(cwd5);
|
|
3870
|
+
createYarnrc(cwd5);
|
|
3871
|
+
deletePnpmArtifacts(cwd5);
|
|
3872
|
+
console.log(chalk47.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
3873
|
+
return 0;
|
|
3874
|
+
}
|
|
3875
|
+
|
|
3876
|
+
// src/actions/packman/convert.ts
|
|
3877
|
+
function detectCurrentPM(cwd5) {
|
|
3878
|
+
if (existsSync14(PATH14.join(cwd5, "pnpm-lock.yaml")) || existsSync14(PATH14.join(cwd5, "pnpm-workspace.yaml"))) {
|
|
3879
|
+
return "pnpm";
|
|
3880
|
+
}
|
|
3881
|
+
if (existsSync14(PATH14.join(cwd5, "yarn.lock")) || existsSync14(PATH14.join(cwd5, ".yarnrc.yml"))) {
|
|
3882
|
+
return "yarn";
|
|
3883
|
+
}
|
|
3884
|
+
return "unknown";
|
|
3885
|
+
}
|
|
3886
|
+
function findWorkspacePackagePaths(cwd5) {
|
|
3887
|
+
const pkgPath = PATH14.join(cwd5, "package.json");
|
|
3888
|
+
const pkg = JSON.parse(readFileSync16(pkgPath, "utf8"));
|
|
3889
|
+
let patterns = pkg.workspaces ?? [];
|
|
3890
|
+
if (patterns.length === 0) {
|
|
3891
|
+
const wsPath = PATH14.join(cwd5, "pnpm-workspace.yaml");
|
|
3892
|
+
if (existsSync14(wsPath)) {
|
|
3893
|
+
const content = readFileSync16(wsPath, "utf8");
|
|
3894
|
+
const lines = content.split("\n");
|
|
3895
|
+
let inPackages = false;
|
|
3896
|
+
for (const line of lines) {
|
|
3897
|
+
if (line.trim() === "packages:") {
|
|
3898
|
+
inPackages = true;
|
|
3899
|
+
continue;
|
|
3900
|
+
}
|
|
3901
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
3902
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
3903
|
+
if (pattern) patterns.push(pattern);
|
|
3904
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
3905
|
+
inPackages = false;
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
const dirs = [];
|
|
3911
|
+
for (const pattern of patterns) {
|
|
3912
|
+
const resolved = resolveWorkspaceGlob(cwd5, pattern);
|
|
3913
|
+
dirs.push(...resolved);
|
|
3914
|
+
}
|
|
3915
|
+
return dirs;
|
|
3916
|
+
}
|
|
3917
|
+
function resolveWorkspaceGlob(cwd5, pattern) {
|
|
3918
|
+
const parts = pattern.split("/");
|
|
3919
|
+
return walkGlob(cwd5, parts, "");
|
|
3920
|
+
}
|
|
3921
|
+
function walkGlob(basePath, parts, currentPath) {
|
|
3922
|
+
if (parts.length === 0) {
|
|
3923
|
+
const fullPath = PATH14.join(basePath, currentPath);
|
|
3924
|
+
if (existsSync14(PATH14.join(fullPath, "package.json"))) {
|
|
3925
|
+
return [currentPath];
|
|
3926
|
+
}
|
|
3927
|
+
return [];
|
|
3928
|
+
}
|
|
3929
|
+
const [part, ...rest] = parts;
|
|
3930
|
+
const dirPath = PATH14.join(basePath, currentPath);
|
|
3931
|
+
if (!existsSync14(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
3932
|
+
return [];
|
|
3933
|
+
}
|
|
3934
|
+
if (part === "*" || part === "**") {
|
|
3935
|
+
const entries = readdirSync7(dirPath, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules" && e.name !== "dist");
|
|
3936
|
+
const results = [];
|
|
3937
|
+
if (part === "**") {
|
|
3938
|
+
results.push(...walkGlob(basePath, rest, currentPath));
|
|
3939
|
+
}
|
|
3940
|
+
for (const entry of entries) {
|
|
3941
|
+
const subPath2 = currentPath ? `${currentPath}/${entry.name}` : entry.name;
|
|
3942
|
+
if (part === "**") {
|
|
3943
|
+
results.push(
|
|
3944
|
+
...walkGlob(basePath, rest, subPath2),
|
|
3945
|
+
...walkGlob(basePath, parts, subPath2)
|
|
3946
|
+
);
|
|
3947
|
+
} else {
|
|
3948
|
+
results.push(...walkGlob(basePath, rest, subPath2));
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
return results;
|
|
3952
|
+
}
|
|
3953
|
+
const subPath = currentPath ? `${currentPath}/${part}` : part;
|
|
3954
|
+
return walkGlob(basePath, rest, subPath);
|
|
3955
|
+
}
|
|
3956
|
+
function convert({ target, verbose }) {
|
|
3957
|
+
const validTargets = ["pnpm", "yarn"];
|
|
3958
|
+
if (!validTargets.includes(target)) {
|
|
3959
|
+
console.error(chalk48.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
3960
|
+
return 1;
|
|
3961
|
+
}
|
|
3962
|
+
const cwd5 = process.cwd();
|
|
3963
|
+
const currentPM = detectCurrentPM(cwd5);
|
|
3964
|
+
if (verbose) {
|
|
3965
|
+
console.log(chalk48.gray(`Current package manager: ${currentPM}`));
|
|
3966
|
+
console.log(chalk48.gray(`Target package manager: ${target}`));
|
|
3967
|
+
}
|
|
3968
|
+
if (currentPM === target) {
|
|
3969
|
+
console.error(chalk48.red(`Already using ${target}. No conversion needed.`));
|
|
3970
|
+
return 1;
|
|
3971
|
+
}
|
|
3972
|
+
if (currentPM === "unknown") {
|
|
3973
|
+
console.error(chalk48.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
3974
|
+
return 1;
|
|
3975
|
+
}
|
|
3976
|
+
const workspacePaths = findWorkspacePackagePaths(cwd5);
|
|
3977
|
+
if (verbose) {
|
|
3978
|
+
console.log(chalk48.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
3979
|
+
}
|
|
3980
|
+
if (target === "pnpm") {
|
|
3981
|
+
return convertToPnpm(cwd5, workspacePaths);
|
|
3982
|
+
}
|
|
3983
|
+
return convertToYarn(cwd5, workspacePaths);
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
// src/actions/publint.ts
|
|
3987
|
+
var publint = async ({ verbose, pkg }) => {
|
|
3988
|
+
return pkg === void 0 ? publintAll({ verbose }) : await publintPackage({ pkg, verbose });
|
|
3989
|
+
};
|
|
3990
|
+
var publintPackage = ({ pkg }) => {
|
|
3991
|
+
const pm = getPackageManager();
|
|
3992
|
+
return runStepsAsync(`Publint [${pkg}]`, [pm.runInWorkspace(pkg, "package-publint")]);
|
|
3993
|
+
};
|
|
3994
|
+
var publintAll = ({ verbose }) => {
|
|
3995
|
+
const pm = getPackageManager();
|
|
3996
|
+
return runSteps("Publint", [pm.foreachWorkspace("package-publint", [], { verbose })]);
|
|
3997
|
+
};
|
|
3998
|
+
|
|
3999
|
+
// src/actions/readme-gen.ts
|
|
4000
|
+
async function readmeGen({
|
|
4001
|
+
pkg,
|
|
4002
|
+
templatePath,
|
|
4003
|
+
typedoc,
|
|
4004
|
+
verbose
|
|
4005
|
+
}) {
|
|
4006
|
+
const config2 = await loadConfig();
|
|
4007
|
+
return await generateReadmeFiles({
|
|
4008
|
+
logoLinkUrl: config2.readme?.logoLinkUrl,
|
|
4009
|
+
logoUrl: config2.readme?.logoUrl,
|
|
4010
|
+
pkg,
|
|
4011
|
+
templatePath,
|
|
4012
|
+
typedoc,
|
|
4013
|
+
verbose
|
|
4014
|
+
});
|
|
4015
|
+
}
|
|
4016
|
+
|
|
4017
|
+
// src/actions/readme-init.ts
|
|
4018
|
+
async function readmeInit({ templatePath }) {
|
|
4019
|
+
const config2 = await loadConfig();
|
|
4020
|
+
const template = applyLogoConfig(DEFAULT_README_TEMPLATE, config2.readme?.logoUrl, config2.readme?.logoLinkUrl);
|
|
4021
|
+
const resolvedTemplatePath = resolveTemplatePath(templatePath);
|
|
4022
|
+
await scaffoldTemplate(resolvedTemplatePath, template);
|
|
4023
|
+
return 0;
|
|
4024
|
+
}
|
|
4025
|
+
|
|
4026
|
+
// src/actions/rebuild.ts
|
|
4027
|
+
var rebuild = ({ target }) => {
|
|
4028
|
+
const pm = getPackageManager();
|
|
4029
|
+
return runSteps("Rebuild", [
|
|
4030
|
+
pm.runXy(["clean"]),
|
|
4031
|
+
pm.runXy(target ? ["build", "-t", target] : ["build"])
|
|
4032
|
+
]);
|
|
4033
|
+
};
|
|
4034
|
+
|
|
4035
|
+
// src/actions/recompile.ts
|
|
4036
|
+
import chalk49 from "chalk";
|
|
4037
|
+
var recompile = async ({
|
|
4038
|
+
verbose,
|
|
4039
|
+
target,
|
|
4040
|
+
pkg,
|
|
4041
|
+
incremental
|
|
4042
|
+
}) => {
|
|
4043
|
+
return pkg ? await recompilePackage({
|
|
4044
|
+
pkg,
|
|
4045
|
+
target,
|
|
4046
|
+
verbose
|
|
4047
|
+
}) : await recompileAll({
|
|
4048
|
+
incremental,
|
|
4049
|
+
target,
|
|
4050
|
+
verbose
|
|
4051
|
+
});
|
|
4052
|
+
};
|
|
4053
|
+
var recompilePackage = ({ target, pkg }) => {
|
|
4054
|
+
const pm = getPackageManager();
|
|
4055
|
+
const targetOptions = target ? ["-t", target] : [];
|
|
4056
|
+
return runStepsAsync(
|
|
4057
|
+
`Recompile [${pkg}]`,
|
|
4058
|
+
[pm.runInWorkspace(pkg, "package-recompile", targetOptions)]
|
|
4059
|
+
);
|
|
4060
|
+
};
|
|
4061
|
+
var recompileAll = async ({
|
|
4062
|
+
jobs,
|
|
4063
|
+
verbose,
|
|
4064
|
+
target,
|
|
4065
|
+
incremental
|
|
4066
|
+
}) => {
|
|
4067
|
+
const pm = getPackageManager();
|
|
4068
|
+
const start = Date.now();
|
|
4069
|
+
const targetOptions = target ? ["-t", target] : [];
|
|
4070
|
+
if (jobs) {
|
|
4071
|
+
console.log(chalk49.blue(`Jobs set to [${jobs}]`));
|
|
4072
|
+
}
|
|
4073
|
+
const foreachOptions = {
|
|
4074
|
+
incremental,
|
|
4075
|
+
jobs,
|
|
4076
|
+
topological: true,
|
|
4077
|
+
verbose
|
|
4078
|
+
};
|
|
4079
|
+
const result = await runStepsAsync(`Recompile${incremental ? "-Incremental" : ""} [All]`, [
|
|
4080
|
+
pm.foreachWorkspace("package-clean", targetOptions, foreachOptions),
|
|
4081
|
+
pm.foreachWorkspace("package-compile", targetOptions, foreachOptions)
|
|
4082
|
+
]);
|
|
4083
|
+
console.log(
|
|
4084
|
+
`${chalk49.gray("Recompiled in")} [${chalk49.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk49.gray("seconds")}`
|
|
4085
|
+
);
|
|
4086
|
+
return result;
|
|
4087
|
+
};
|
|
4088
|
+
|
|
4089
|
+
// src/actions/relint.ts
|
|
4090
|
+
import chalk50 from "chalk";
|
|
4091
|
+
var relintPackage = ({
|
|
4092
|
+
pkg,
|
|
4093
|
+
fix: fix2,
|
|
4094
|
+
verbose
|
|
4095
|
+
}) => {
|
|
4096
|
+
console.log(chalk50.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
4097
|
+
const start = Date.now();
|
|
4098
|
+
const pm = getPackageManager();
|
|
4099
|
+
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
4100
|
+
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
4101
|
+
]);
|
|
4102
|
+
console.log(chalk50.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk50.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk50.gray("seconds")}`));
|
|
4103
|
+
return result;
|
|
4104
|
+
};
|
|
4105
|
+
var relint = ({
|
|
4106
|
+
pkg,
|
|
4107
|
+
verbose,
|
|
4108
|
+
incremental,
|
|
4109
|
+
fix: fix2
|
|
4110
|
+
} = {}) => {
|
|
4111
|
+
return pkg === void 0 ? relintAllPackages({
|
|
4112
|
+
verbose,
|
|
4113
|
+
incremental,
|
|
4114
|
+
fix: fix2
|
|
4115
|
+
}) : relintPackage({
|
|
4116
|
+
pkg,
|
|
4117
|
+
fix: fix2,
|
|
4118
|
+
verbose
|
|
4119
|
+
});
|
|
4120
|
+
};
|
|
4121
|
+
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
4122
|
+
console.log(chalk50.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
4123
|
+
const start = Date.now();
|
|
4124
|
+
const fixOptions = fix2 ? ["--fix"] : [];
|
|
4125
|
+
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
4126
|
+
["eslint", fixOptions]
|
|
4127
|
+
]);
|
|
4128
|
+
console.log(chalk50.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk50.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk50.gray("seconds")}`));
|
|
4129
|
+
return result;
|
|
4130
|
+
};
|
|
4131
|
+
|
|
4132
|
+
// src/actions/retest.ts
|
|
4133
|
+
var retest = ({ target } = {}) => {
|
|
4134
|
+
const pm = getPackageManager();
|
|
4135
|
+
if (target && pm.findWorkspace(target)) {
|
|
4136
|
+
return runSteps(`Re-Test [${target}]`, [
|
|
4137
|
+
pm.runInWorkspace(target, "vitest", ["--clearCache"]),
|
|
4138
|
+
pm.runInWorkspace(target, "vitest", ["."])
|
|
4139
|
+
]);
|
|
4140
|
+
}
|
|
4141
|
+
const path15 = target ?? ".";
|
|
4142
|
+
return runSteps("Re-Test", [
|
|
4143
|
+
["vitest", ["--clearCache"]],
|
|
4144
|
+
["vitest", [path15]]
|
|
4145
|
+
]);
|
|
4146
|
+
};
|
|
4147
|
+
|
|
4148
|
+
// src/actions/sonar.ts
|
|
4149
|
+
var sonar = () => {
|
|
4150
|
+
return runSteps("Sonar", [["eslint", ["-c", "sonar.eslintrc", "."]]]);
|
|
4151
|
+
};
|
|
4152
|
+
|
|
4153
|
+
// src/actions/statics.ts
|
|
4154
|
+
import chalk51 from "chalk";
|
|
4155
|
+
var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
|
|
4156
|
+
var statics = () => {
|
|
4157
|
+
console.log(chalk51.green("Check Required Static Dependencies"));
|
|
4158
|
+
const statics2 = parsedPackageJSON()?.xy?.deps?.statics;
|
|
4159
|
+
return detectDuplicateDependencies(statics2, DefaultDependencies);
|
|
4160
|
+
};
|
|
4161
|
+
|
|
4162
|
+
// src/actions/test.ts
|
|
4163
|
+
var test = ({ target } = {}) => {
|
|
4164
|
+
const pm = getPackageManager();
|
|
4165
|
+
if (target && pm.findWorkspace(target)) {
|
|
4166
|
+
return runSteps(`Test [${target}]`, [pm.runInWorkspace(target, "vitest", ["."])]);
|
|
4167
|
+
}
|
|
4168
|
+
const path15 = target ?? ".";
|
|
4169
|
+
return runSteps("Test", [["vitest", [path15]]]);
|
|
4170
|
+
};
|
|
4171
|
+
|
|
4172
|
+
// src/loadPackageConfig.ts
|
|
4173
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
4174
|
+
var loadPackageConfig = async () => {
|
|
4175
|
+
const pkg = process.env.INIT_CWD;
|
|
4176
|
+
const pkgConfig = await readFile2(`${pkg}/package.json`, { encoding: "utf8" });
|
|
4177
|
+
return JSON.parse(pkgConfig);
|
|
4178
|
+
};
|
|
4179
|
+
|
|
4180
|
+
// src/xy/build/buildCommand.ts
|
|
4181
|
+
var buildCommand = {
|
|
4182
|
+
command: "build [package]",
|
|
4183
|
+
describe: "Build - Compile & Lint",
|
|
4184
|
+
builder: (yargs2) => {
|
|
4185
|
+
return yargs2.positional("package", { describe: "Specific package to build" });
|
|
4186
|
+
},
|
|
4187
|
+
handler: async (argv) => {
|
|
4188
|
+
if (argv.verbose) {
|
|
4189
|
+
console.log(`Building: ${argv.package ?? "all"}`);
|
|
4190
|
+
}
|
|
4191
|
+
process.exitCode = await build({
|
|
4192
|
+
incremental: !!argv.incremental,
|
|
4193
|
+
jobs: argv.jobs,
|
|
4194
|
+
pkg: argv.package,
|
|
4195
|
+
target: argv.target,
|
|
4196
|
+
verbose: !!argv.verbose
|
|
4197
|
+
});
|
|
4198
|
+
}
|
|
4199
|
+
};
|
|
4200
|
+
|
|
4201
|
+
// src/xy/build/compileCommand.ts
|
|
4202
|
+
var compileCommand = {
|
|
4203
|
+
command: "compile [package]",
|
|
4204
|
+
describe: "Compile with Typescript & Copy Images",
|
|
4205
|
+
builder: (yargs2) => {
|
|
4206
|
+
return yargs2.positional("package", { describe: "Specific package to compile" });
|
|
4207
|
+
},
|
|
4208
|
+
handler: (argv) => {
|
|
4209
|
+
if (argv.verbose) {
|
|
4210
|
+
console.log(`Compiling: ${argv.package ?? "all"}`);
|
|
4211
|
+
}
|
|
4212
|
+
process.exitCode = compile({
|
|
4213
|
+
incremental: !!argv.incremental,
|
|
4214
|
+
jobs: argv.jobs,
|
|
4215
|
+
pkg: argv.package,
|
|
4216
|
+
target: argv.target,
|
|
4217
|
+
verbose: !!argv.verbose
|
|
4218
|
+
});
|
|
4219
|
+
}
|
|
4220
|
+
};
|
|
4221
|
+
|
|
4222
|
+
// src/xy/build/compileOnlyCommand.ts
|
|
4223
|
+
var compileOnlyCommand = {
|
|
4224
|
+
command: "compile-only [package]",
|
|
4225
|
+
describe: "Compile with Typescript & Copy Images (No Publint)",
|
|
4226
|
+
builder: (yargs2) => {
|
|
4227
|
+
return yargs2.positional("package", { describe: "Specific package to compile" });
|
|
4228
|
+
},
|
|
4229
|
+
handler: (argv) => {
|
|
4230
|
+
if (argv.verbose) {
|
|
4231
|
+
console.log(`Compiling: ${argv.package ?? "all"}`);
|
|
4232
|
+
}
|
|
4233
|
+
process.exitCode = compile({
|
|
4234
|
+
incremental: !!argv.incremental,
|
|
4235
|
+
jobs: argv.jobs,
|
|
4236
|
+
pkg: argv.package,
|
|
4237
|
+
publint: false,
|
|
4238
|
+
target: argv.target,
|
|
4239
|
+
verbose: !!argv.verbose
|
|
4240
|
+
});
|
|
4241
|
+
}
|
|
4242
|
+
};
|
|
4243
|
+
|
|
4244
|
+
// src/xy/build/copyAssetsCommand.ts
|
|
4245
|
+
var copyAssetsCommand = {
|
|
4246
|
+
command: "copy-assets [package]",
|
|
4247
|
+
describe: "Copy Assets - Copy the assets from src to dist",
|
|
4248
|
+
builder: (yargs2) => {
|
|
4249
|
+
return yargs2.positional("package", { describe: "Specific package to copy assets" });
|
|
4250
|
+
},
|
|
4251
|
+
handler: async (argv) => {
|
|
4252
|
+
if (argv.verbose) console.log(`Copying Assets: ${argv.package ?? "all"}`);
|
|
4253
|
+
process.exitCode = await copyAssets({ target: argv.target });
|
|
4254
|
+
}
|
|
4255
|
+
};
|
|
4256
|
+
|
|
4257
|
+
// src/xy/build/rebuildCommand.ts
|
|
4258
|
+
var rebuildCommand = {
|
|
4259
|
+
command: "rebuild [package]",
|
|
4260
|
+
describe: "Rebuild - Clean, Compile & Lint",
|
|
4261
|
+
builder: (yargs2) => {
|
|
4262
|
+
return yargs2.positional("package", { describe: "Specific package to rebuild" });
|
|
4263
|
+
},
|
|
4264
|
+
handler: (argv) => {
|
|
4265
|
+
if (argv.verbose) console.log(`Rebuilding: ${argv.package ?? "all"}`);
|
|
4266
|
+
process.exitCode = rebuild({ target: argv.target });
|
|
4267
|
+
}
|
|
4268
|
+
};
|
|
4269
|
+
|
|
4270
|
+
// src/xy/build/recompileCommand.ts
|
|
4271
|
+
var recompileCommand = {
|
|
4272
|
+
command: "recompile [package]",
|
|
4273
|
+
describe: "Re-compile with Typescript & Copy Images",
|
|
4274
|
+
builder: (yargs2) => {
|
|
4275
|
+
return yargs2.positional("package", { describe: "Specific package to re-compile" });
|
|
4276
|
+
},
|
|
4277
|
+
handler: async (argv) => {
|
|
4278
|
+
if (argv.verbose) {
|
|
4279
|
+
console.log(`Re-compiling: ${argv.package ?? "all"}`);
|
|
4280
|
+
}
|
|
4281
|
+
process.exitCode = await recompile({
|
|
4282
|
+
incremental: !!argv.incremental,
|
|
4283
|
+
jobs: argv.jobs,
|
|
4284
|
+
pkg: argv.package,
|
|
4285
|
+
target: argv.target,
|
|
4286
|
+
verbose: !!argv.verbose
|
|
4287
|
+
});
|
|
4288
|
+
}
|
|
4289
|
+
};
|
|
4290
|
+
|
|
4291
|
+
// src/xy/build/index.ts
|
|
4292
|
+
var xyBuildCommands = (args) => {
|
|
4293
|
+
return args.command(buildCommand).command(compileCommand).command(compileOnlyCommand).command(recompileCommand).command(rebuildCommand).command(copyAssetsCommand);
|
|
4294
|
+
};
|
|
4295
|
+
|
|
4296
|
+
// src/xy/common/claude/cleanCommand.ts
|
|
4297
|
+
var cleanCommand = {
|
|
4298
|
+
command: "clean",
|
|
4299
|
+
describe: "Remove all Claude configuration files from the repo",
|
|
4300
|
+
handler: (argv) => {
|
|
4301
|
+
if (argv.verbose) console.log("Claude Clean");
|
|
4302
|
+
process.exitCode = claudeClean();
|
|
4303
|
+
}
|
|
4304
|
+
};
|
|
4305
|
+
|
|
4306
|
+
// src/xy/common/claude/commandsCommand.ts
|
|
4307
|
+
var commandsCommand = {
|
|
4308
|
+
command: "commands",
|
|
4309
|
+
describe: "Sync XY Labs standard Claude slash commands to .claude/commands/",
|
|
4310
|
+
handler: (argv) => {
|
|
4311
|
+
if (argv.verbose) console.log("Claude Commands");
|
|
4312
|
+
process.exitCode = claudeCommands();
|
|
4313
|
+
}
|
|
4314
|
+
};
|
|
4315
|
+
|
|
4316
|
+
// src/xy/common/claude/initCommand.ts
|
|
4317
|
+
var initCommand = {
|
|
4318
|
+
builder: (yargs2) => {
|
|
4319
|
+
return yargs2.option("force", {
|
|
4320
|
+
alias: "f",
|
|
4321
|
+
default: false,
|
|
4322
|
+
description: "Overwrite existing CLAUDE.md",
|
|
4323
|
+
type: "boolean"
|
|
4324
|
+
});
|
|
4325
|
+
},
|
|
4326
|
+
command: "init",
|
|
4327
|
+
describe: "Initialize all Claude configuration (commands, rules, settings)",
|
|
4328
|
+
handler: async (argv) => {
|
|
4329
|
+
if (argv.verbose) console.log("Claude Init");
|
|
4330
|
+
const commandsResult = claudeCommands();
|
|
4331
|
+
const rulesResult = claudeRules({ force: argv.force });
|
|
4332
|
+
const settingsResult = await claudeSettings();
|
|
4333
|
+
process.exitCode = commandsResult || rulesResult || settingsResult;
|
|
4334
|
+
}
|
|
4335
|
+
};
|
|
4336
|
+
|
|
4337
|
+
// src/xy/common/claude/rulesCommand.ts
|
|
4338
|
+
var rulesCommand = {
|
|
4339
|
+
builder: (yargs2) => {
|
|
4340
|
+
return yargs2.option("force", {
|
|
4341
|
+
alias: "f",
|
|
4342
|
+
default: false,
|
|
4343
|
+
description: "Overwrite existing CLAUDE.md",
|
|
4344
|
+
type: "boolean"
|
|
4345
|
+
});
|
|
4346
|
+
},
|
|
4347
|
+
command: "rules",
|
|
4348
|
+
describe: "Sync XY Labs standard Claude rules to .claude/rules/",
|
|
4349
|
+
handler: (argv) => {
|
|
4350
|
+
if (argv.verbose) console.log("Claude Rules");
|
|
4351
|
+
process.exitCode = claudeRules({ force: argv.force });
|
|
4352
|
+
}
|
|
4353
|
+
};
|
|
4354
|
+
|
|
4355
|
+
// src/xy/common/claude/settingsCommand.ts
|
|
4356
|
+
var settingsCommand = {
|
|
4357
|
+
command: "settings",
|
|
4358
|
+
describe: "Initialize .claude/settings.local.json with XY Labs defaults",
|
|
4359
|
+
handler: async (argv) => {
|
|
4360
|
+
if (argv.verbose) console.log("Claude Settings");
|
|
4361
|
+
process.exitCode = await claudeSettings();
|
|
4362
|
+
}
|
|
4363
|
+
};
|
|
4364
|
+
|
|
4365
|
+
// src/xy/common/claude/skillsCommand.ts
|
|
4366
|
+
var skillsCommand = {
|
|
4367
|
+
builder: (yargs2) => yargs2,
|
|
4368
|
+
command: "skills",
|
|
4369
|
+
describe: "Sync XY Labs standard Claude skills to .claude/skills/",
|
|
4370
|
+
handler: (argv) => {
|
|
4371
|
+
if (argv.verbose) console.log("Claude Skills");
|
|
4372
|
+
process.exitCode = claudeSkills();
|
|
4373
|
+
}
|
|
4374
|
+
};
|
|
4375
|
+
|
|
4376
|
+
// src/xy/common/claude/index.ts
|
|
4377
|
+
var claudeCommand = {
|
|
4378
|
+
builder: (yargs2) => {
|
|
4379
|
+
return yargs2.command(cleanCommand).command(commandsCommand).command(initCommand).command(rulesCommand).command(settingsCommand).command(skillsCommand).demandCommand(1, "Please specify a claude subcommand");
|
|
4380
|
+
},
|
|
4381
|
+
command: "claude",
|
|
4382
|
+
describe: "Claude - Claude Code configuration utilities",
|
|
4383
|
+
handler: () => {
|
|
4384
|
+
}
|
|
4385
|
+
};
|
|
4386
|
+
|
|
4387
|
+
// src/xy/common/cleanDocsCommand.ts
|
|
4388
|
+
var cleanDocsCommand = {
|
|
4389
|
+
command: "clean-docs",
|
|
4390
|
+
describe: "CleanDocs - Clean TypeDocs",
|
|
4391
|
+
handler: (argv) => {
|
|
4392
|
+
if (argv.verbose) console.log("Cleaning TypeDocs: all");
|
|
4393
|
+
process.exitCode = cleanDocs();
|
|
4394
|
+
}
|
|
4395
|
+
};
|
|
4396
|
+
|
|
4397
|
+
// src/xy/param.ts
|
|
4398
|
+
var packagePositionalParam = (yargs2) => {
|
|
4399
|
+
return yargs2.positional("package", { describe: "Specific package to target", type: "string" });
|
|
4400
|
+
};
|
|
4401
|
+
|
|
4402
|
+
// src/xy/common/deadCommand.ts
|
|
4403
|
+
var deadCommand = {
|
|
4404
|
+
builder: (yargs2) => {
|
|
4405
|
+
return packagePositionalParam(yargs2);
|
|
4406
|
+
},
|
|
4407
|
+
command: "dead [package]",
|
|
4408
|
+
describe: "Dead - Check for dead code",
|
|
4409
|
+
handler: (argv) => {
|
|
4410
|
+
if (argv.verbose) console.log("Dead");
|
|
4411
|
+
process.exitCode = dead();
|
|
4412
|
+
}
|
|
4413
|
+
};
|
|
4414
|
+
|
|
4415
|
+
// src/xy/common/genDocsCommand.ts
|
|
4416
|
+
var genDocsCommand = {
|
|
4417
|
+
builder: (yargs2) => {
|
|
4418
|
+
return packagePositionalParam(yargs2);
|
|
4419
|
+
},
|
|
4420
|
+
command: "gen-docs [package]",
|
|
4421
|
+
describe: "GenDocs - Generate TypeDocs",
|
|
4422
|
+
handler: (argv) => {
|
|
4423
|
+
if (argv.verbose) console.log(`Generating TypeDocs: ${argv.package ?? "all"}`);
|
|
4424
|
+
process.exitCode = genDocs({ incremental: !!argv.incremental, pkg: argv.package });
|
|
4425
|
+
}
|
|
4426
|
+
};
|
|
4427
|
+
|
|
4428
|
+
// src/xy/common/gitignoreCommand.ts
|
|
4429
|
+
var gitignoreCommand = {
|
|
4430
|
+
command: "gitignore",
|
|
4431
|
+
describe: "GitIgnore - Generate root .gitignore and remove package .gitignore files",
|
|
4432
|
+
handler: (argv) => {
|
|
4433
|
+
if (argv.verbose) console.log("GitIgnore");
|
|
4434
|
+
process.exitCode = gitignore();
|
|
4435
|
+
}
|
|
4436
|
+
};
|
|
4437
|
+
|
|
4438
|
+
// src/xy/common/gitlintCommand.ts
|
|
4439
|
+
var gitlintCommand = {
|
|
4440
|
+
command: "gitlint [package]",
|
|
4441
|
+
describe: "Gitlint - Lint your git config",
|
|
4442
|
+
handler: (argv) => {
|
|
4443
|
+
if (argv.verbose) console.log("Gitlint");
|
|
4444
|
+
process.exitCode = argv.fix ? gitlintFix() : gitlint();
|
|
4445
|
+
}
|
|
4446
|
+
};
|
|
4447
|
+
|
|
4448
|
+
// src/xy/common/licenseCommand.ts
|
|
4449
|
+
var licenseCommand = {
|
|
4450
|
+
builder: (yargs2) => {
|
|
4451
|
+
return packagePositionalParam(yargs2);
|
|
4452
|
+
},
|
|
4453
|
+
command: "license [package]",
|
|
4454
|
+
describe: "License - Check licenses of dependencies",
|
|
4455
|
+
handler: async (argv) => {
|
|
4456
|
+
if (argv.verbose) console.log(`License: ${argv.package ?? "all"}`);
|
|
4457
|
+
process.exitCode = await license();
|
|
4458
|
+
}
|
|
4459
|
+
};
|
|
4460
|
+
|
|
4461
|
+
// src/xy/common/npmignoreGenCommand.ts
|
|
4462
|
+
var npmignoreGenCommand = {
|
|
4463
|
+
command: "npmignore-gen",
|
|
4464
|
+
describe: "NpmIgnore Gen - Generate .npmignore files",
|
|
4465
|
+
handler: (argv) => {
|
|
4466
|
+
if (argv.verbose) console.log("NpmIgnore Gen");
|
|
4467
|
+
process.exitCode = npmignoreGen();
|
|
4468
|
+
}
|
|
4469
|
+
};
|
|
4470
|
+
|
|
4471
|
+
// src/xy/common/packmanCommand.ts
|
|
4472
|
+
var convertCommand = {
|
|
4473
|
+
command: "convert <target>",
|
|
4474
|
+
describe: "Convert repo to a different package manager (pnpm or yarn)",
|
|
4475
|
+
builder: (yargs2) => {
|
|
4476
|
+
return yargs2.positional("target", {
|
|
4477
|
+
choices: ["pnpm", "yarn"],
|
|
4478
|
+
describe: "Target package manager",
|
|
4479
|
+
type: "string"
|
|
4480
|
+
});
|
|
4481
|
+
},
|
|
4482
|
+
handler: (argv) => {
|
|
4483
|
+
process.exitCode = convert({
|
|
4484
|
+
target: argv.target,
|
|
4485
|
+
verbose: !!argv.verbose
|
|
4486
|
+
});
|
|
4487
|
+
}
|
|
4488
|
+
};
|
|
4489
|
+
var packmanCommand = {
|
|
4490
|
+
builder: (yargs2) => {
|
|
4491
|
+
return yargs2.command(convertCommand).demandCommand(1, "Please specify a packman subcommand");
|
|
4492
|
+
},
|
|
4493
|
+
command: "packman",
|
|
4494
|
+
describe: "Package Manager - Conversion utilities",
|
|
4495
|
+
handler: () => {
|
|
4496
|
+
}
|
|
4497
|
+
};
|
|
4498
|
+
|
|
4499
|
+
// src/xy/common/readme/genCommand.ts
|
|
4500
|
+
var genCommand = {
|
|
4501
|
+
builder: (yargs2) => {
|
|
4502
|
+
return packagePositionalParam(yargs2).option("template", {
|
|
4503
|
+
alias: "t",
|
|
4504
|
+
description: "Path to README.template.md",
|
|
4505
|
+
type: "string"
|
|
4506
|
+
}).option("typedoc", {
|
|
4507
|
+
default: false,
|
|
4508
|
+
description: "Generate TypeDoc reference sections",
|
|
4509
|
+
type: "boolean"
|
|
4510
|
+
});
|
|
4511
|
+
},
|
|
4512
|
+
aliases: ["$0"],
|
|
4513
|
+
command: "gen [package]",
|
|
4514
|
+
describe: "Generate README.md files from template",
|
|
4515
|
+
handler: async (argv) => {
|
|
4516
|
+
if (argv.verbose) console.log("Readme Gen");
|
|
4517
|
+
process.exitCode = await readmeGen({
|
|
4518
|
+
pkg: argv.package,
|
|
4519
|
+
templatePath: argv.template,
|
|
4520
|
+
typedoc: argv.typedoc,
|
|
4521
|
+
verbose: !!argv.verbose
|
|
4522
|
+
});
|
|
4523
|
+
}
|
|
4524
|
+
};
|
|
4525
|
+
|
|
4526
|
+
// src/xy/common/readme/initCommand.ts
|
|
4527
|
+
var initCommand2 = {
|
|
4528
|
+
builder: (yargs2) => {
|
|
4529
|
+
return yargs2.option("template", {
|
|
4530
|
+
alias: "t",
|
|
4531
|
+
description: "Path to README.template.md",
|
|
4532
|
+
type: "string"
|
|
4533
|
+
});
|
|
4534
|
+
},
|
|
4535
|
+
command: "init",
|
|
4536
|
+
describe: "Initialize README template and logo files",
|
|
4537
|
+
handler: async (argv) => {
|
|
4538
|
+
if (argv.verbose) console.log("Readme Init");
|
|
4539
|
+
process.exitCode = await readmeInit({
|
|
4540
|
+
templatePath: argv.template,
|
|
4541
|
+
verbose: !!argv.verbose
|
|
4542
|
+
});
|
|
4543
|
+
}
|
|
4544
|
+
};
|
|
4545
|
+
|
|
4546
|
+
// src/xy/common/readme/index.ts
|
|
4547
|
+
var readmeCommand = {
|
|
4548
|
+
builder: (yargs2) => {
|
|
4549
|
+
return yargs2.command(genCommand).command(initCommand2);
|
|
4550
|
+
},
|
|
4551
|
+
command: "readme",
|
|
4552
|
+
describe: "Readme - README file utilities",
|
|
4553
|
+
handler: () => {
|
|
4554
|
+
}
|
|
4555
|
+
};
|
|
4556
|
+
|
|
4557
|
+
// src/xy/common/retestCommand.ts
|
|
4558
|
+
var retestCommand = {
|
|
4559
|
+
command: "retest [target]",
|
|
4560
|
+
describe: "Re-Test - Run Vitest Tests with cleaned cache",
|
|
4561
|
+
builder: (yargs2) => {
|
|
4562
|
+
return yargs2.positional("target", { describe: "Package name or file/folder path to test" });
|
|
4563
|
+
},
|
|
4564
|
+
handler: (argv) => {
|
|
4565
|
+
if (argv.verbose) console.log(`Re-Testing: ${argv.target ?? "all"}`);
|
|
4566
|
+
process.exitCode = retest({ target: argv.target });
|
|
4567
|
+
}
|
|
4568
|
+
};
|
|
4569
|
+
|
|
4570
|
+
// src/xy/common/testCommand.ts
|
|
4571
|
+
var testCommand = {
|
|
4572
|
+
command: "test [target]",
|
|
4573
|
+
describe: "Test - Run Vitest Tests",
|
|
4574
|
+
builder: (yargs2) => {
|
|
4575
|
+
return yargs2.positional("target", { describe: "Package name or file/folder path to test" });
|
|
4576
|
+
},
|
|
4577
|
+
handler: (argv) => {
|
|
4578
|
+
if (argv.verbose) console.log(`Testing: ${argv.target ?? "all"}`);
|
|
4579
|
+
process.exitCode = test({ target: argv.target });
|
|
4580
|
+
}
|
|
4581
|
+
};
|
|
4582
|
+
|
|
4583
|
+
// src/xy/common/index.ts
|
|
4584
|
+
var xyCommonCommands = (args) => {
|
|
4585
|
+
return args.command(claudeCommand).command(licenseCommand).command(deadCommand).command(genDocsCommand).command(cleanDocsCommand).command(gitlintCommand).command(gitignoreCommand).command(npmignoreGenCommand).command(packmanCommand).command(readmeCommand).command(retestCommand).command(testCommand);
|
|
4586
|
+
};
|
|
4587
|
+
|
|
4588
|
+
// src/xy/lint/cycleCommand.ts
|
|
4589
|
+
import chalk52 from "chalk";
|
|
4590
|
+
var cycleCommand = {
|
|
4591
|
+
command: "cycle [package]",
|
|
4592
|
+
describe: "Cycle - Check for dependency cycles",
|
|
4593
|
+
builder: (yargs2) => {
|
|
4594
|
+
return packagePositionalParam(yargs2);
|
|
4595
|
+
},
|
|
4596
|
+
handler: async (argv) => {
|
|
4597
|
+
const start = Date.now();
|
|
4598
|
+
if (argv.verbose) console.log("Cycle");
|
|
4599
|
+
process.exitCode = await cycle({ pkg: argv.package });
|
|
4600
|
+
console.log(chalk52.blue(`Finished in ${Date.now() - start}ms`));
|
|
4601
|
+
}
|
|
4602
|
+
};
|
|
4603
|
+
|
|
4604
|
+
// src/xy/lint/deplintCommand.ts
|
|
4605
|
+
import chalk53 from "chalk";
|
|
4606
|
+
var deplintCommand = {
|
|
4607
|
+
command: "deplint [package]",
|
|
4608
|
+
describe: "Deplint - Run Deplint",
|
|
4609
|
+
builder: (yargs2) => {
|
|
4610
|
+
return packagePositionalParam(yargs2).option("deps", {
|
|
4611
|
+
alias: "d",
|
|
4612
|
+
default: false,
|
|
4613
|
+
description: "Check dependencies",
|
|
4614
|
+
type: "boolean"
|
|
4615
|
+
}).option("devDeps", {
|
|
4616
|
+
alias: "v",
|
|
4617
|
+
default: false,
|
|
4618
|
+
description: "Check devDependencies",
|
|
4619
|
+
type: "boolean"
|
|
4620
|
+
}).option("peerDeps", {
|
|
4621
|
+
alias: "p",
|
|
4622
|
+
default: false,
|
|
4623
|
+
description: "Check peerDependencies",
|
|
4624
|
+
type: "boolean"
|
|
4625
|
+
}).option("exclude", {
|
|
4626
|
+
alias: "e",
|
|
4627
|
+
description: "Package names to exclude from unused checks (comma-separated or repeated)",
|
|
4628
|
+
type: "array"
|
|
4629
|
+
});
|
|
4630
|
+
},
|
|
4631
|
+
handler: async (argv) => {
|
|
4632
|
+
if (argv.verbose) console.log("Deplint");
|
|
4633
|
+
const start = Date.now();
|
|
4634
|
+
const cliExclude = argv.exclude?.flatMap((v) => String(v).split(",")).map((v) => v.trim()).filter(Boolean);
|
|
4635
|
+
process.exitCode = await deplint({
|
|
4636
|
+
cliExclude,
|
|
4637
|
+
pkg: argv.package,
|
|
4638
|
+
deps: !!argv.deps,
|
|
4639
|
+
devDeps: !!argv.devDeps,
|
|
4640
|
+
peerDeps: !!argv.peerDeps,
|
|
4641
|
+
verbose: !!argv.verbose
|
|
4642
|
+
});
|
|
4643
|
+
console.log(chalk53.blue(`Finished in ${Date.now() - start}ms`));
|
|
4644
|
+
}
|
|
4645
|
+
};
|
|
4646
|
+
|
|
4647
|
+
// src/xy/lint/fixCommand.ts
|
|
4648
|
+
import chalk54 from "chalk";
|
|
4649
|
+
var fixCommand = {
|
|
4650
|
+
command: "fix [package]",
|
|
4651
|
+
describe: "Fix - Run Eslint w/fix",
|
|
4652
|
+
builder: (yargs2) => {
|
|
4653
|
+
return packagePositionalParam(yargs2);
|
|
4654
|
+
},
|
|
4655
|
+
handler: (argv) => {
|
|
4656
|
+
const start = Date.now();
|
|
4657
|
+
if (argv.verbose) console.log("Fix");
|
|
4658
|
+
process.exitCode = fix();
|
|
4659
|
+
console.log(chalk54.blue(`Finished in ${Date.now() - start}ms`));
|
|
4660
|
+
}
|
|
4661
|
+
};
|
|
4662
|
+
|
|
4663
|
+
// src/xy/lint/knipCommand.ts
|
|
4664
|
+
import chalk55 from "chalk";
|
|
4665
|
+
var knipCommand = {
|
|
4666
|
+
command: "knip",
|
|
4667
|
+
describe: "Knip - Run Knip",
|
|
4668
|
+
builder: (yargs2) => {
|
|
4669
|
+
return packagePositionalParam(yargs2);
|
|
4670
|
+
},
|
|
4671
|
+
handler: (argv) => {
|
|
4672
|
+
if (argv.verbose) console.log("Knip");
|
|
4673
|
+
const start = Date.now();
|
|
4674
|
+
process.exitCode = knip();
|
|
4675
|
+
console.log(chalk55.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
4676
|
+
}
|
|
4677
|
+
};
|
|
4678
|
+
|
|
4679
|
+
// src/xy/lint/lintCommand.ts
|
|
4680
|
+
import chalk56 from "chalk";
|
|
4681
|
+
var lintCommand = {
|
|
4682
|
+
command: "lint [package]",
|
|
4683
|
+
describe: "Lint - Run Eslint",
|
|
4684
|
+
builder: (yargs2) => {
|
|
4685
|
+
return packagePositionalParam(yargs2).option("fix", {
|
|
4686
|
+
alias: "f",
|
|
4687
|
+
default: false,
|
|
4688
|
+
description: "Fix fixable issues",
|
|
4689
|
+
type: "boolean"
|
|
4690
|
+
}).option("cache", {
|
|
4691
|
+
alias: "c",
|
|
4692
|
+
default: false,
|
|
4693
|
+
description: "Use caching for performance",
|
|
4694
|
+
type: "boolean"
|
|
4695
|
+
});
|
|
4696
|
+
},
|
|
4697
|
+
handler: (argv) => {
|
|
4698
|
+
if (argv.verbose) console.log("Lint");
|
|
4699
|
+
const start = Date.now();
|
|
4700
|
+
process.exitCode = argv.fix ? fix({
|
|
4701
|
+
pkg: argv.package,
|
|
4702
|
+
cache: argv.cache,
|
|
4703
|
+
verbose: !!argv.verbose
|
|
4704
|
+
}) : lint({
|
|
4705
|
+
pkg: argv.package,
|
|
4706
|
+
cache: argv.cache,
|
|
4707
|
+
verbose: !!argv.verbose
|
|
4708
|
+
});
|
|
4709
|
+
console.log(chalk56.blue(`Finished in ${Date.now() - start}ms`));
|
|
4710
|
+
}
|
|
4711
|
+
};
|
|
4712
|
+
|
|
4713
|
+
// src/xy/lint/lintlintCommand.ts
|
|
4714
|
+
var lintlintCommand = {
|
|
4715
|
+
command: "lintlint",
|
|
4716
|
+
describe: "Lint Lint - Check for redundant or overridden ESLint rules vs shared config",
|
|
4717
|
+
builder: (yargs2) => {
|
|
4718
|
+
return yargs2.option("fix", {
|
|
4719
|
+
default: false,
|
|
4720
|
+
description: "Remove redundant rules from local config",
|
|
4721
|
+
type: "boolean"
|
|
4722
|
+
});
|
|
4723
|
+
},
|
|
4724
|
+
handler: async (argv) => {
|
|
4725
|
+
if (argv.verbose) console.log("Lint Lint");
|
|
4726
|
+
process.exitCode = await lintlint({
|
|
4727
|
+
fix: argv.fix,
|
|
4728
|
+
verbose: !!argv.verbose
|
|
4729
|
+
});
|
|
4730
|
+
}
|
|
4731
|
+
};
|
|
4732
|
+
|
|
4733
|
+
// src/xy/lint/packageLintCommand.ts
|
|
4734
|
+
var packageLintCommand = {
|
|
4735
|
+
builder: (yargs2) => {
|
|
4736
|
+
return yargs2.option("fix", {
|
|
4737
|
+
default: false,
|
|
4738
|
+
description: "Auto-fix fixable issues",
|
|
4739
|
+
type: "boolean"
|
|
4740
|
+
});
|
|
4741
|
+
},
|
|
4742
|
+
command: "package-lint",
|
|
4743
|
+
describe: "Package Lint - Check monorepo package structure",
|
|
4744
|
+
handler: (argv) => {
|
|
4745
|
+
if (argv.verbose) console.log("Package Lint");
|
|
4746
|
+
process.exitCode = packageLintMonorepo(!!argv.fix);
|
|
4747
|
+
}
|
|
4748
|
+
};
|
|
4749
|
+
|
|
4750
|
+
// src/xy/lint/publintCommand.ts
|
|
4751
|
+
import chalk57 from "chalk";
|
|
4752
|
+
var publintCommand = {
|
|
4753
|
+
command: "publint [package]",
|
|
4754
|
+
describe: "Publint - Run Publint",
|
|
4755
|
+
builder: (yargs2) => {
|
|
4756
|
+
return packagePositionalParam(yargs2);
|
|
4757
|
+
},
|
|
4758
|
+
handler: async (argv) => {
|
|
4759
|
+
if (argv.verbose) console.log("Publint");
|
|
4760
|
+
const start = Date.now();
|
|
4761
|
+
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
4762
|
+
console.log(chalk57.blue(`Finished in ${Date.now() - start}ms`));
|
|
4763
|
+
}
|
|
4764
|
+
};
|
|
4765
|
+
|
|
4766
|
+
// src/xy/lint/relintCommand.ts
|
|
4767
|
+
import chalk58 from "chalk";
|
|
4768
|
+
var relintCommand = {
|
|
4769
|
+
command: "relint [package]",
|
|
4770
|
+
describe: "Relint - Clean & Lint",
|
|
4771
|
+
builder: (yargs2) => {
|
|
4772
|
+
return packagePositionalParam(yargs2);
|
|
4773
|
+
},
|
|
4774
|
+
handler: (argv) => {
|
|
4775
|
+
if (argv.verbose) console.log("Relinting");
|
|
4776
|
+
const start = Date.now();
|
|
4777
|
+
process.exitCode = relint();
|
|
4778
|
+
console.log(chalk58.blue(`Finished in ${Date.now() - start}ms`));
|
|
4779
|
+
}
|
|
4780
|
+
};
|
|
4781
|
+
|
|
4782
|
+
// src/xy/lint/sonarCommand.ts
|
|
4783
|
+
import chalk59 from "chalk";
|
|
4784
|
+
var sonarCommand = {
|
|
4785
|
+
command: "sonar",
|
|
4786
|
+
describe: "Sonar - Run Sonar Check",
|
|
4787
|
+
builder: (yargs2) => {
|
|
4788
|
+
return packagePositionalParam(yargs2);
|
|
4789
|
+
},
|
|
4790
|
+
handler: (argv) => {
|
|
4791
|
+
const start = Date.now();
|
|
4792
|
+
if (argv.verbose) console.log("Sonar Check");
|
|
4793
|
+
process.exitCode = sonar();
|
|
4794
|
+
console.log(chalk59.blue(`Finished in ${Date.now() - start}ms`));
|
|
4795
|
+
}
|
|
4796
|
+
};
|
|
4797
|
+
|
|
4798
|
+
// src/xy/lint/index.ts
|
|
4799
|
+
var xyLintCommands = (args) => {
|
|
4800
|
+
return args.command(cycleCommand).command(lintCommand).command(lintlintCommand).command(deplintCommand).command(fixCommand).command(relintCommand).command(publintCommand).command(knipCommand).command(packageLintCommand).command(sonarCommand);
|
|
4801
|
+
};
|
|
4802
|
+
|
|
4803
|
+
// src/xy/xy.ts
|
|
4804
|
+
import chalk60 from "chalk";
|
|
4805
|
+
|
|
4806
|
+
// src/xy/xyParseOptions.ts
|
|
4807
|
+
import yargs from "yargs";
|
|
4808
|
+
import { hideBin } from "yargs/helpers";
|
|
4809
|
+
var xyParseOptions = () => {
|
|
4810
|
+
return yargs(hideBin(process.argv)).scriptName("yarn xy").middleware((argv) => {
|
|
4811
|
+
const commandName = argv._[0];
|
|
4812
|
+
if (commandName && argv._.length <= 1) {
|
|
4813
|
+
const result = tryRunLocalScript(commandName);
|
|
4814
|
+
if (result !== void 0) {
|
|
4815
|
+
process.exit(result);
|
|
4816
|
+
}
|
|
4817
|
+
}
|
|
4818
|
+
}, true).option("jobs", {
|
|
4819
|
+
alias: "j",
|
|
4820
|
+
default: void 0,
|
|
4821
|
+
description: "Max parallel jobs",
|
|
4822
|
+
type: "number"
|
|
4823
|
+
}).option("verbose", {
|
|
4824
|
+
alias: "v",
|
|
4825
|
+
default: false,
|
|
4826
|
+
description: "Run with verbose logging",
|
|
4827
|
+
type: "boolean"
|
|
4828
|
+
}).option("incremental", {
|
|
4829
|
+
alias: "i",
|
|
4830
|
+
default: false,
|
|
4831
|
+
description: "Attempt to perform the action only on changed packages",
|
|
4832
|
+
type: "boolean"
|
|
4833
|
+
}).option("profile", {
|
|
4834
|
+
alias: "p",
|
|
4835
|
+
default: false,
|
|
4836
|
+
description: "Profile action",
|
|
4837
|
+
type: "boolean"
|
|
4838
|
+
});
|
|
4839
|
+
};
|
|
4840
|
+
|
|
4841
|
+
// src/xy/xy.ts
|
|
4842
|
+
var xyBase = async (plugins) => {
|
|
4843
|
+
const options = xyParseOptions();
|
|
4844
|
+
let args = xyBuildCommands(xyCommonCommands(xyLintCommands(options)));
|
|
4845
|
+
if (plugins) args = plugins(args);
|
|
4846
|
+
return await args.demandCommand(1).command("*", "", () => {
|
|
4847
|
+
console.error(chalk60.yellow(`Command not found [${chalk60.magenta(process.argv[2])}]`));
|
|
4848
|
+
console.log(chalk60.gray("Try 'xy --help' for list of commands"));
|
|
4849
|
+
}).version().help().argv;
|
|
4850
|
+
};
|
|
4851
|
+
export {
|
|
4852
|
+
CROSS_PLATFORM_NEWLINE,
|
|
4853
|
+
DEFAULT_README_BODY,
|
|
4854
|
+
DEFAULT_README_TEMPLATE,
|
|
4855
|
+
DuplicateDetector,
|
|
4856
|
+
INIT_CWD,
|
|
4857
|
+
LEGACY_COMMANDS_PREFIX,
|
|
4858
|
+
WINDOWS_NEWLINE_REGEX,
|
|
4859
|
+
XYLABS_COMMANDS_PREFIX,
|
|
4860
|
+
XYLABS_RULES_PREFIX,
|
|
4861
|
+
XYLABS_SKILLS_PREFIX,
|
|
4862
|
+
applyLogoConfig,
|
|
4863
|
+
build,
|
|
4864
|
+
checkResult,
|
|
4865
|
+
claudeClean,
|
|
4866
|
+
claudeCommandTemplates,
|
|
4867
|
+
claudeCommands,
|
|
4868
|
+
claudeMdLocalTemplate,
|
|
4869
|
+
claudeMdProjectTemplate,
|
|
4870
|
+
claudeMdRuleTemplates,
|
|
4871
|
+
claudeRules,
|
|
4872
|
+
claudeSettings,
|
|
4873
|
+
claudeSkillTemplates,
|
|
4874
|
+
claudeSkills,
|
|
4875
|
+
clean,
|
|
4876
|
+
cleanAll,
|
|
4877
|
+
cleanDocs,
|
|
4878
|
+
cleanESLint,
|
|
4879
|
+
cleanPackage,
|
|
4880
|
+
compile,
|
|
4881
|
+
compileAll,
|
|
4882
|
+
compilePackage,
|
|
4883
|
+
convert,
|
|
4884
|
+
copyAssets,
|
|
4885
|
+
createBuildConfig,
|
|
4886
|
+
cycle,
|
|
4887
|
+
cycleAll,
|
|
4888
|
+
cyclePackage,
|
|
4889
|
+
dead,
|
|
4890
|
+
defaultBuildConfig,
|
|
4891
|
+
defaultReadFileSyncOptions,
|
|
4892
|
+
deleteGlob,
|
|
4893
|
+
deplint,
|
|
4894
|
+
detectDuplicateDependencies,
|
|
4895
|
+
detectPackageManager,
|
|
4896
|
+
dupdeps,
|
|
4897
|
+
empty,
|
|
4898
|
+
fix,
|
|
4899
|
+
genDocs,
|
|
4900
|
+
genDocsAll,
|
|
4901
|
+
genDocsPackage,
|
|
4902
|
+
generateIgnoreFiles,
|
|
4903
|
+
generateReadmeFiles,
|
|
4904
|
+
getPackageManager,
|
|
4905
|
+
gitignore,
|
|
4906
|
+
gitignoreGen,
|
|
4907
|
+
gitignoreTemplate,
|
|
4908
|
+
gitlint,
|
|
4909
|
+
gitlintFix,
|
|
4910
|
+
knip,
|
|
4911
|
+
license,
|
|
4912
|
+
lint,
|
|
4913
|
+
lintAllPackages,
|
|
4914
|
+
lintPackage,
|
|
4915
|
+
lintlint,
|
|
4916
|
+
loadConfig,
|
|
4917
|
+
loadPackageConfig,
|
|
4918
|
+
multiLineToJSONArray,
|
|
4919
|
+
notEmpty,
|
|
4920
|
+
npmignoreGen,
|
|
4921
|
+
packageClean,
|
|
4922
|
+
packageCleanOutputs,
|
|
4923
|
+
packageCleanTypescript,
|
|
4924
|
+
packageCompile,
|
|
4925
|
+
packageCompileTsc,
|
|
4926
|
+
packageCompileTsup,
|
|
4927
|
+
packageCopyAssets,
|
|
4928
|
+
packageCycle,
|
|
4929
|
+
packageGenDocs,
|
|
4930
|
+
packageLint,
|
|
4931
|
+
packageLintMonorepo,
|
|
4932
|
+
packagePublint,
|
|
4933
|
+
packageRecompile,
|
|
4934
|
+
parsedPackageJSON,
|
|
4935
|
+
processEx,
|
|
4936
|
+
publint,
|
|
4937
|
+
publintAll,
|
|
4938
|
+
publintPackage,
|
|
4939
|
+
readLines,
|
|
4940
|
+
readNonEmptyLines,
|
|
4941
|
+
readmeGen,
|
|
4942
|
+
readmeInit,
|
|
4943
|
+
rebuild,
|
|
4944
|
+
recompile,
|
|
4945
|
+
recompileAll,
|
|
4946
|
+
recompilePackage,
|
|
4947
|
+
registerPackageManager,
|
|
4948
|
+
relint,
|
|
4949
|
+
relintAllPackages,
|
|
4950
|
+
relintPackage,
|
|
4951
|
+
resolveTemplatePath,
|
|
4952
|
+
retest,
|
|
4953
|
+
rewriteScript,
|
|
4954
|
+
rewriteScriptsInPackageJson,
|
|
4955
|
+
runStepAsync,
|
|
4956
|
+
runSteps,
|
|
4957
|
+
runStepsAsync,
|
|
4958
|
+
runXy,
|
|
4959
|
+
runXyWithWarning,
|
|
4960
|
+
safeExit,
|
|
4961
|
+
safeExitAsync,
|
|
4962
|
+
scaffoldTemplate,
|
|
4963
|
+
sonar,
|
|
4964
|
+
statics,
|
|
4965
|
+
test,
|
|
4966
|
+
tryReadFileSync,
|
|
4967
|
+
tryRunLocalScript,
|
|
4968
|
+
tsupOptions,
|
|
4969
|
+
union,
|
|
4970
|
+
withErrnoException,
|
|
4971
|
+
withError,
|
|
4972
|
+
writeLines,
|
|
4973
|
+
xyBase,
|
|
4974
|
+
xyBuildCommands,
|
|
4975
|
+
xyCommonCommands,
|
|
4976
|
+
xyLintCommands,
|
|
4977
|
+
xyParseOptions
|
|
4978
|
+
};
|
|
4979
|
+
//# sourceMappingURL=index.mjs.map
|