mirror of
https://github.com/cline/cline.git
synced 2026-09-19 02:05:44 +08:00
* Migrate to Biome for linting/formatting and simplify hooks - Add biome.jsonc and @biomejs CLI; configure VS Code to use Biome for format/fix and imports - Replace verbose Husky pre-commit with lint-staged runner - Remove ESLint setup and custom rule package (no-direct-vscode-api) and its tests - Update package.json/package-lock and webview-ui package to reflect tooling change - Add VS Code host typings and grit definitions under src/hosts Rationale: unify lint/format tooling, speed up pre-commit checks, and reduce maintenance overhead from custom ESLint rules. * remove eslint dependencies * preserve eslint rules * clean up * update files list * add docs * fix build * clean up * update VSCode API usage detection in Grit rule This commit updates the Grit rule for detecting VSCode API usage: - Narrow down the list of monitored VSCode API methods - Add more specific diagnostic messages for direct API usage - Introduce a new check for `workspaceFolders` property - Exclude `src/extension.ts` from the Grit rule in Biome configuration The changes aim to improve code abstraction and provide clearer guidance for replacing direct VSCode API calls. * adds new cacheService rule * add back pre-commit * Remove ESLint custom rule and update linting references Remove custom ESLint rule for VSCode state API enforcement along with its tests, remove ESLint extension recommendation, and update documentation to use generic "linter" terminology instead of ESLint-specific references. * update vscode.d.ts for IntelliSense * remove format on save * clean up default values * update to 2.1.4 * buf lint * format
178 lines
4.7 KiB
JavaScript
Executable File
178 lines
4.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import archiver from "archiver"
|
|
import { execSync } from "child_process"
|
|
import fs from "fs"
|
|
import { cp } from "fs/promises"
|
|
import { glob } from "glob"
|
|
import minimatch from "minimatch"
|
|
import path from "path"
|
|
|
|
const BUILD_DIR = "dist-standalone"
|
|
const RUNTIME_DEPS_DIR = "standalone/runtime-files"
|
|
|
|
async function main() {
|
|
await installNodeDependencies()
|
|
await zipDistribution()
|
|
}
|
|
|
|
async function installNodeDependencies() {
|
|
await cpr(RUNTIME_DEPS_DIR, BUILD_DIR)
|
|
|
|
console.log("Running npm install in distribution directory...")
|
|
const cwd = process.cwd()
|
|
process.chdir(BUILD_DIR)
|
|
|
|
try {
|
|
execSync("npm install", { stdio: "inherit" })
|
|
// Move the vscode directory into node_modules.
|
|
// It can't be installed using npm because it will create a symlink which cannot be unzipped correctly on windows.
|
|
fs.renameSync("vscode", path.join("node_modules", "vscode"))
|
|
} catch (error) {
|
|
console.error("Error during setup:", error)
|
|
process.exit(1)
|
|
} finally {
|
|
process.chdir(cwd)
|
|
}
|
|
|
|
// Check for native .node modules.
|
|
const nativeModules = await glob("**/*.node", { cwd: BUILD_DIR, nodir: true })
|
|
if (nativeModules.length > 0) {
|
|
console.error("Native node modules cannot be included in the standalone distribution:\n", nativeModules.join("\n"))
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
async function zipDistribution() {
|
|
// Zip the build directory (excluding any pre-existing output zip).
|
|
const zipPath = path.join(BUILD_DIR, "standalone.zip")
|
|
const output = fs.createWriteStream(zipPath)
|
|
const archive = archiver("zip", { zlib: { level: 3 } })
|
|
|
|
output.on("close", () => {
|
|
console.log(`Created ${zipPath} (${(archive.pointer() / 1024 / 1024).toFixed(1)} MB)`)
|
|
})
|
|
archive.on("warning", (err) => {
|
|
console.warn(`Warning: ${err}`)
|
|
})
|
|
archive.on("error", (err) => {
|
|
throw err
|
|
})
|
|
|
|
archive.pipe(output)
|
|
// Add all the files from the standalone build dir.
|
|
archive.glob("**/*", {
|
|
cwd: BUILD_DIR,
|
|
ignore: ["standalone.zip"],
|
|
})
|
|
|
|
// Exclude the same files as the VCE vscode extension packager.
|
|
// Also ignore the dist directory, the build directory for the extension.
|
|
const isIgnored = createIsIgnored(["dist/**"])
|
|
|
|
// Add the whole cline directory under "extension", except the for the ignored files.
|
|
archive.directory(process.cwd(), "extension", (entry) => {
|
|
if (isIgnored(entry.name)) {
|
|
log_verbose("Ignoring", entry.name)
|
|
return false
|
|
}
|
|
return entry
|
|
})
|
|
|
|
console.log("Zipping package...")
|
|
await archive.finalize()
|
|
}
|
|
|
|
/**
|
|
* This is based on https://github.com/microsoft/vscode-vsce/blob/fafad8a63e9cf31179f918eb7a4eeb376834c904/src/package.ts#L1695
|
|
* because the .vscodeignore format is not compatible with the `ignore` npm module.
|
|
*/
|
|
function createIsIgnored(standaloneIgnores) {
|
|
const MinimatchOptions = { dot: true }
|
|
const defaultIgnore = [
|
|
".vscodeignore",
|
|
"package-lock.json",
|
|
"npm-debug.log",
|
|
"yarn.lock",
|
|
"yarn-error.log",
|
|
"npm-shrinkwrap.json",
|
|
".editorconfig",
|
|
".npmrc",
|
|
".yarnrc",
|
|
".gitattributes",
|
|
"*.todo",
|
|
"tslint.yaml",
|
|
".eslintrc*",
|
|
".babelrc*",
|
|
".prettierrc*",
|
|
"biome.json*",
|
|
".cz-config.js",
|
|
".commitlintrc*",
|
|
"webpack.config.js",
|
|
"ISSUE_TEMPLATE.md",
|
|
"CONTRIBUTING.md",
|
|
"PULL_REQUEST_TEMPLATE.md",
|
|
"CODE_OF_CONDUCT.md",
|
|
".github",
|
|
".travis.yml",
|
|
"appveyor.yml",
|
|
"**/.git",
|
|
"**/.git/**",
|
|
"**/*.vsix",
|
|
"**/.DS_Store",
|
|
"**/*.vsixmanifest",
|
|
"**/.vscode-test/**",
|
|
"**/.vscode-test-web/**",
|
|
]
|
|
|
|
const rawIgnore = fs.readFileSync(".vscodeignore", "utf8")
|
|
|
|
// Parse raw ignore by splitting output into lines and filtering out empty lines and comments
|
|
const parsedIgnore = rawIgnore
|
|
.split(/[\n\r]/)
|
|
.map((s) => s.trim())
|
|
.filter((s) => !!s)
|
|
.filter((i) => !/^\s*#/.test(i))
|
|
|
|
// Add '/**' to possible folder names
|
|
const expandedIgnore = [
|
|
...parsedIgnore,
|
|
...parsedIgnore.filter((i) => !/(^|\/)[^/]*\*[^/]*$/.test(i)).map((i) => (/\/$/.test(i) ? `${i}**` : `${i}/**`)),
|
|
]
|
|
|
|
// Combine with default ignore list
|
|
// Also ignore the dist directory- the build directory for the extension.
|
|
const allIgnore = [...defaultIgnore, ...expandedIgnore, ...standaloneIgnores]
|
|
|
|
// Split into ignore and negate list
|
|
const [ignore, negate] = allIgnore.reduce(
|
|
(r, e) => (!/^\s*!/.test(e) ? [[...r[0], e], r[1]] : [r[0], [...r[1], e]]),
|
|
[[], []],
|
|
)
|
|
|
|
function isIgnored(f) {
|
|
return (
|
|
ignore.some((i) => minimatch(f, i, MinimatchOptions)) &&
|
|
!negate.some((i) => minimatch(f, i.substr(1), MinimatchOptions))
|
|
)
|
|
}
|
|
return isIgnored
|
|
}
|
|
|
|
/* cp -r */
|
|
async function cpr(source, dest) {
|
|
await cp(source, dest, {
|
|
recursive: true,
|
|
preserveTimestamps: true,
|
|
dereference: false, // preserve symlinks instead of following them
|
|
})
|
|
}
|
|
|
|
function log_verbose(...args) {
|
|
if (process.argv.includes("-v") || process.argv.includes("--verbose")) {
|
|
console.log(...args)
|
|
}
|
|
}
|
|
|
|
await main()
|