Skip to content

Commit

Permalink
Merge branch 'main' into mok/reupload-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev authored Mar 6, 2024
2 parents f892931 + 6729324 commit f3592c3
Show file tree
Hide file tree
Showing 600 changed files with 4,966 additions and 12,585 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build-and-upload-to-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: 'YOUR_CLERK_PUBLISHABLE_KEY'
NEXT_PUBLIC_API_URL: 'http://localhost:5173'
- name: Upload to S3
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1'
DEST_DIR: 'codemod-registry'
SOURCE_DIR: 'apps/registry/builder/dist'
# - name: Upload to S3
# uses: jakejarvis/s3-sync-action@master
# with:
# args: --acl public-read --follow-symlinks
# env:
# AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: 'us-west-1'
# DEST_DIR: 'codemod-registry'
# SOURCE_DIR: 'apps/registry/builder/dist'
32 changes: 0 additions & 32 deletions .github/workflows/sync.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ yarn-debug.log*
.vercel

# Backend
build-ncc
build
5 changes: 3 additions & 2 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"@biomejs/biome": "1.5.3",
"@codemod-com/filemod": "workspace:*",
"@codemod-com/utilities": "workspace:*",
"@effect/schema": "0.27.0",
"@svgr/hast-util-to-babel-ast": "^7.0.0",
"@types/babel__traverse": "^7.20.1",
"@types/columnify": "^1.5.4",
"@types/js-yaml": "4.0.9",
"@types/jscodeshift": "^0.11.5",
"@types/ms": "^0.7.34",
"@types/node": "18.11.9",
"@types/sinon": "^10.0.20",
"@types/tar": "^6.1.5",
Expand Down Expand Up @@ -98,6 +98,7 @@
"access": "public"
},
"dependencies": {
"js-yaml": "4.1.0"
"js-yaml": "4.1.0",
"ms": "^2.1.3"
}
}
4 changes: 2 additions & 2 deletions apps/cli/src/apis.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Axios from "axios";
import type FormData from "form-data";
import { type Input, nullable, object, parse, string } from "valibot";
import { type Output, nullable, object, parse, string } from "valibot";

const X_CODEMOD_ACCESS_TOKEN = "X-Codemod-Access-Token".toLocaleLowerCase();

const dataSchema = object({
username: nullable(string()),
});

type Data = Input<typeof dataSchema>;
type Data = Output<typeof dataSchema>;

export const validateAccessToken = async (
accessToken: string,
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/buildArgumentRecord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as S from "@effect/schema/Schema";
import { is, number, string } from "valibot";
import { ArgumentRecord } from "./schemata/argumentRecordSchema.js";

export const buildArgumentRecord = <T extends { [s: string]: unknown }>(
Expand All @@ -14,12 +14,12 @@ export const buildArgumentRecord = <T extends { [s: string]: unknown }>(
const key = arg.slice(4);
const value = argv[arg];

if (S.is(S.number)(value)) {
if (is(number(), value)) {
argumentRecord[key] = value;
return;
}

if (!S.is(S.string)(value)) {
if (!is(string(), value)) {
return;
}

Expand Down
18 changes: 9 additions & 9 deletions apps/cli/src/buildCodemodOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";
import * as S from "@effect/schema/Schema";
import { IFs } from "memfs";
import { object, parse, string } from "valibot";
import {
Codemod,
JavaScriptCodemodEngine,
Expand All @@ -17,11 +17,11 @@ const extractMainScriptRelativePath = async (
encoding: "utf-8",
});

const schema = S.struct({
main: S.string,
const schema = object({
main: string(),
});

const { main } = S.parseSync(schema)(JSON.parse(data.toString()));
const { main } = parse(schema, JSON.parse(data.toString()));

return main;
} catch {
Expand All @@ -38,11 +38,11 @@ const extractEngine = async (
encoding: "utf-8",
});

const schema = S.struct({
const schema = object({
engine: javaScriptCodemodEngineSchema,
});

const { engine } = S.parseSync(schema)(JSON.parse(data.toString()));
const { engine } = parse(schema, JSON.parse(data.toString()));

return engine;
} catch {
Expand Down Expand Up @@ -71,7 +71,7 @@ export const buildSourcedCodemodOptions = async (
}

if (
!["config.json", "package.json"]
![".codemodrc.json", "package.json"]
.map((lookedupFilePath) =>
path.join(codemodOptions.source, lookedupFilePath),
)
Expand Down Expand Up @@ -100,12 +100,12 @@ export const buildSourcedCodemodOptions = async (

const engine = await extractEngine(
fs,
path.join(codemodOptions.source, "config.json"),
path.join(codemodOptions.source, ".codemodrc.json"),
);

if (engine === null) {
throw new Error(
`Engine specified in config.json at ${codemodOptions.source} is not a JavaScript codemod engine or does not exist.`,
`Engine specified in .codemodrc.json at ${codemodOptions.source} is not a JavaScript codemod engine or does not exist.`,
);
}

Expand Down
6 changes: 0 additions & 6 deletions apps/cli/src/buildOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ export const buildOptions = <T extends Record<string, unknown>>(y: Argv<T>) => {
description:
'The engine to use with the local codemod: "jscodeshift", "ts-morph", "filemod"',
})
.option("limit", {
alias: "f",
type: "number",
description: "File limit for processing",
default: 1000,
})
.option("raw", {
alias: "r",
type: "boolean",
Expand Down
16 changes: 8 additions & 8 deletions apps/cli/src/codemod.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as S from "@effect/schema/Schema";
import { type Output, literal, union } from "valibot";
import { Arguments } from "./schemata/argumentsSchema.js";

export const javaScriptCodemodEngineSchema = S.union(
S.literal("jscodeshift"),
S.literal("repomod-engine"),
S.literal("filemod"),
S.literal("ts-morph"),
);
export const javaScriptCodemodEngineSchema = union([
literal("jscodeshift"),
literal("repomod-engine"),
literal("filemod"),
literal("ts-morph"),
]);

export type JavaScriptCodemodEngine = S.To<
export type JavaScriptCodemodEngine = Output<
typeof javaScriptCodemodEngineSchema
>;

Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const DEFAULT_INCLUDE_PATTERNS = ["**/*.*"] as const;
export const DEFAULT_EXCLUDE_PATTERNS = ["**/node_modules/**/*.*"] as const;
export const DEFAULT_INCLUDE_PATTERNS = ["**/*.*"];
export const DEFAULT_EXCLUDE_PATTERNS = ["**/node_modules/**/*.*"];
export const DEFAULT_INPUT_DIRECTORY_PATH = process.cwd();
export const DEFAULT_FILE_LIMIT = 7_000;
export const DEFAULT_DISABLE_PRETTIER = false;
export const DEFAULT_NO_CACHE = false;
export const DEFAULT_USE_JSON = false;
Expand Down
8 changes: 4 additions & 4 deletions apps/cli/src/downloadCodemod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createHash } from "node:crypto";
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import * as S from "@effect/schema/Schema";
import Axios from "axios";
import { parse } from "valibot";
import { Codemod } from "./codemod.js";
import { FileDownloadServiceBlueprint } from "./fileDownloadService.js";
import { handleListNamesCommand } from "./handleListCliCommand.js";
Expand Down Expand Up @@ -86,10 +86,10 @@ export class CodemodDownloader implements CodemodDownloaderBlueprint {

try {
// download the config
const configPath = join(directoryPath, "config.json");
const configPath = join(directoryPath, ".codemodrc.json");

const buffer = await this._fileDownloadService.download(
`${CODEMOD_REGISTRY_URL}/${hashDigest}/config.json`,
`${CODEMOD_REGISTRY_URL}/${hashDigest}/.codemodrc.json`,
configPath,
);

Expand All @@ -106,7 +106,7 @@ export class CodemodDownloader implements CodemodDownloaderBlueprint {

let config: CodemodConfig;
try {
config = S.parseSync(codemodConfigSchema)(parsedConfig);
config = parse(codemodConfigSchema, parsedConfig);
} catch (err) {
throw new Error(`Error parsing config for codemod ${name}: ${err}`);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/handleListCliCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const configJsonSchema = v.object({
export const getConfigFiles = async () => {
const configurationDirectoryPath = join(homedir(), ".codemod");

const configFiles = await glob("**/config.json", {
const configFiles = await glob("**/.codemodrc.json", {
absolute: true,
cwd: configurationDirectoryPath,
fs,
Expand Down Expand Up @@ -55,7 +55,7 @@ export const getConfigFiles = async () => {

export const handleListNamesCommand = async (
printer: PrinterBlueprint,
short: boolean,
short?: boolean,
) => {
const configObjects = await getConfigFiles();

Expand Down
22 changes: 10 additions & 12 deletions apps/cli/src/handlePublishCliCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { mkdir, writeFile } from "fs/promises";
import { object, optional, parse, string } from "valibot";
import { publish, validateAccessToken } from "./apis.js";
import type { PrinterBlueprint } from "./printer.js";
import { codemodConfigSchema } from "./schemata/codemodConfigSchema.js";
import { boldText, colorizeText } from "./utils.js";

const packageJsonSchema = object({
Expand All @@ -15,12 +16,6 @@ const packageJsonSchema = object({
license: optional(string()),
});

const configJsonSchema = object({
schemaVersion: string(),
name: string(),
engine: string(),
});

const getToken = (): Promise<string> => {
const configurationDirectoryPath = join(homedir(), ".codemod");
const tokenTxtPath = join(configurationDirectoryPath, "token.txt");
Expand Down Expand Up @@ -83,16 +78,16 @@ export const handlePublishCliCommand = async (
});

const configJsonData = await fs.promises.readFile(
join(source, "config.json"),
join(source, ".codemodrc.json"),
{
encoding: "utf-8",
},
);
const configJson = parse(configJsonSchema, JSON.parse(configJsonData));
const configJson = parse(codemodConfigSchema, JSON.parse(configJsonData));

if (configJson.name !== pkg.name) {
if (!("name" in configJson) || configJson.name !== pkg.name) {
throw new Error(
`The "name" field in package.json must match with that in config.json.\nIt must must start with your GitHub username with a slash ("@${username}/") and contain allowed characters (a-z, A-Z, 0-9, _, / or -).`,
`The "name" field in package.json must match with that in .codemodrc.json.\nIt must must start with your GitHub username with a slash ("@${username}/") and contain allowed characters (a-z, A-Z, 0-9, _, / or -).`,
);
}

Expand All @@ -113,7 +108,7 @@ export const handlePublishCliCommand = async (

const formData = new FormData();
formData.append("index.cjs", Buffer.from(indexCjsData));
formData.append("config.json", Buffer.from(configJsonData));
formData.append(".codemodrc.json", Buffer.from(configJsonData));

if (descriptionMdData) {
formData.append("description.md", descriptionMdData);
Expand Down Expand Up @@ -144,7 +139,10 @@ export const handlePublishCliCommand = async (
await mkdir(codemodDirectoryPath, { recursive: true });

try {
await writeFile(join(codemodDirectoryPath, "config.json"), configJsonData);
await writeFile(
join(codemodDirectoryPath, ".codemodrc.json"),
configJsonData,
);
await writeFile(join(codemodDirectoryPath, "index.cjs"), indexCjsData);
if (descriptionMdData) {
await writeFile(
Expand Down
Loading

0 comments on commit f3592c3

Please sign in to comment.