Skip to content

Commit

Permalink
scripts: add version argument for pnpm run clone (#204)
Browse files Browse the repository at this point in the history
also I run `pnpm run clone 0.10.1` to reflect the current main version
  • Loading branch information
Sysix authored Oct 31, 2024
1 parent 3d7a0cf commit 005fa50
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
32 changes: 23 additions & 9 deletions scripts/sparse-clone.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import shell from 'shelljs';
import fs from 'node:fs';
import { TARGET_DIRECTORY, SPARSE_CLONE_DIRECTORY } from './constants.js';
import {
TARGET_DIRECTORY,
SPARSE_CLONE_DIRECTORY,
VERSION_PREFIX,
} from './constants.js';
import { getLatestVersionFromClonedRepo } from './oxlint-version.js';

const version = process.argv[2] ?? undefined;

// Function to initialize or reconfigure sparse-checkout
function configureSparseCheckout(cloneDirectory: string) {
console.log('Configuring sparse-checkout...');
Expand All @@ -22,25 +28,32 @@ function configureSparseCheckout(cloneDirectory: string) {
}
}

function checkoutLatestTag(targetDirectory: string, cloneDirectory: string) {
const latestTag = getLatestVersionFromClonedRepo(targetDirectory);
function checkoutVersionTag(
targetDirectory: string,
cloneDirectory: string,
version?: string
) {
const tag = version
? `${VERSION_PREFIX}${version}`
: getLatestVersionFromClonedRepo(targetDirectory);

// Checkout the specified directory
if (shell.exec(`git checkout ${latestTag}`, { silent: true }).code !== 0) {
if (shell.exec(`git checkout ${tag}`, { silent: true }).code !== 0) {
shell.echo('Error: Git checkout failed');
shell.exit(1);
}

console.log(
`Successfully cloned ${cloneDirectory} into ${targetDirectory}/${cloneDirectory} at ${latestTag}`
`Successfully cloned ${cloneDirectory} into ${targetDirectory}/${cloneDirectory} at ${tag}`
);
}

// Function to clone or update a repository
function cloneOrUpdateRepo(
repositoryUrl: string,
targetDirectory: string,
cloneDirectory: string
cloneDirectory: string,
version?: string
) {
// Check if the target directory exists and is a Git repository
if (
Expand All @@ -52,7 +65,7 @@ function cloneOrUpdateRepo(
shell.cd(targetDirectory);

configureSparseCheckout(cloneDirectory);
checkoutLatestTag(targetDirectory, cloneDirectory);
checkoutVersionTag(targetDirectory, cloneDirectory, version);
} else {
console.log(`Cloning new repository into ${targetDirectory}...`);

Expand All @@ -69,12 +82,13 @@ function cloneOrUpdateRepo(
shell.cd(targetDirectory);

configureSparseCheckout(cloneDirectory);
checkoutLatestTag(targetDirectory, cloneDirectory);
checkoutVersionTag(targetDirectory, cloneDirectory, version);
}
}

cloneOrUpdateRepo(
'https://github.com/oxc-project/oxc.git',
TARGET_DIRECTORY,
SPARSE_CLONE_DIRECTORY
SPARSE_CLONE_DIRECTORY,
version
);
3 changes: 0 additions & 3 deletions src/__snapshots__/rules-by-scope.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,6 @@ exports[`contains all the oxlint rules 1`] = `
"node/no-exports-assign": [
0,
],
"node/no-new-require": [
0,
],
"nonblock-statement-body-position": [
0,
],
Expand Down
3 changes: 1 addition & 2 deletions src/rules-by-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ const restrictionRules = {
'import/no-webpack-loader-syntax': 'off',
'jsdoc/check-access': 'off',
'jsdoc/empty-tags': 'off',
'node/no-new-require': 'off',
'promise/catch-or-return': 'off',
'promise/spec-only': 'off',
'react/button-has-type': 'off',
Expand Down Expand Up @@ -380,6 +379,7 @@ const correctnessRules = {
'promise/no-callback-in-promise': 'off',
'promise/no-new-statics': 'off',
'promise/valid-params': 'off',
'react/iframe-missing-sandbox': 'off',
'react/jsx-key': 'off',
'react/jsx-no-duplicate-props': 'off',
'react/jsx-no-target-blank': 'off',
Expand Down Expand Up @@ -440,7 +440,6 @@ const suspiciousRules = {
'import/no-named-as-default-member': 'off',
'import/no-self-import': 'off',
'jest/no-commented-out-tests': 'off',
'react/iframe-missing-sandbox': 'off',
'react/jsx-no-comment-textnodes': 'off',
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/no-confusing-non-null-assertion': 'off',
Expand Down
1 change: 0 additions & 1 deletion src/rules-by-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ const nextjsRules = {

const nodeRules = {
'node/no-exports-assign': 'off',
'node/no-new-require': 'off',
} as const;

const promiseRules = {
Expand Down

0 comments on commit 005fa50

Please sign in to comment.