Skip to content

Commit

Permalink
feat: improve create-react-component script
Browse files Browse the repository at this point in the history
- support onlyNamedExport option
- bumpup assert package
- remove mock files and it was replaced by snapshotTest
- split files
  • Loading branch information
ddalpange committed May 12, 2022
1 parent 6446971 commit 82930c7
Show file tree
Hide file tree
Showing 47 changed files with 501 additions and 303 deletions.
4 changes: 2 additions & 2 deletions gen-ssp/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ensureDir } from "https://deno.land/std@0.126.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import { ensureDir } from "https://deno.land/std@0.138.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";

const fixtureFiles = [
"app-bridge/android.ts",
Expand Down
6 changes: 3 additions & 3 deletions gen-ssp/fixture2.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import * as fs from "https://deno.land/std@0.126.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import * as fs from "https://deno.land/std@0.138.0/fs/mod.ts";

export async function copyFixtures(outPath: string): Promise<void> {
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
const src = path.join(__dirname, "fixture2");
await fs.copy(src, outPath, {overwrite: true});
await fs.copy(src, outPath, { overwrite: true });
}
2 changes: 1 addition & 1 deletion gen-ssp/gen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import genUrichk from "./urichk.ts";
import genFixture2 from "./fixture2.ts";
import genPbkit from "./pbkit.ts";

import { emptyDir } from "https://deno.land/std@0.126.0/fs/mod.ts";
import { emptyDir } from "https://deno.land/std@0.138.0/fs/mod.ts";
import { Command, EnumType } from "https://deno.land/x/[email protected]/mod.ts";

const defaultPollapoDir = ".pollapo";
Expand Down
4 changes: 2 additions & 2 deletions gen-ssp/gen/keycloak.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GenOptions } from "./index.ts";
import { ensureDir } from "https://deno.land/std@0.126.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import { ensureDir } from "https://deno.land/std@0.138.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import { globFiles } from "../misc/fs.ts";
import { generateKeycloakUtil, getClientRoles } from "../keycloak.ts";

Expand Down
2 changes: 1 addition & 1 deletion gen-ssp/gen/pb-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GenOptions } from "./index.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import { RootNode } from "../pbjs/ast/index.ts";
import {
generateAppBridgeBrowserClient,
Expand Down
2 changes: 1 addition & 1 deletion gen-ssp/gen/pbjs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GenOptions } from "./index.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";

const __dirname = path.dirname(path.fromFileUrl(import.meta.url));

Expand Down
2 changes: 1 addition & 1 deletion gen-ssp/gen/pbkit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GenOptions } from "./index.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";

const __dirname = path.dirname(path.fromFileUrl(import.meta.url));

Expand Down
4 changes: 2 additions & 2 deletions gen-ssp/gen/rrtv2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GenOptions } from "./index.ts";
import { ensureDir } from "https://deno.land/std@0.126.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import { ensureDir } from "https://deno.land/std@0.138.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import { globFiles } from "../misc/fs.ts";
import { compile as compileUbershape } from "../ubershape.ts";

Expand Down
4 changes: 2 additions & 2 deletions gen-ssp/gen/urichk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GenOptions } from "./index.ts";
import { ensureDir } from "https://deno.land/std@0.126.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import { ensureDir } from "https://deno.land/std@0.138.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import { compile as compileNextjsNavigationHook } from "https://deno.land/x/[email protected]/compile/nextjs-navigation-hook.ts";
import { compile as compileNextjsSearchParamsHook } from "https://deno.land/x/[email protected]/compile/nextjs-search-params-hook.ts";
import { kebabToPascal } from "../misc/case.ts";
Expand Down
2 changes: 1 addition & 1 deletion gen-ssp/keycloak.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse as parseYaml } from "https://deno.land/std@0.126.0/encoding/yaml.ts";
import { parse as parseYaml } from "https://deno.land/std@0.138.0/encoding/yaml.ts";

export interface ClientRoles {
[clientName: string]: string[];
Expand Down
2 changes: 1 addition & 1 deletion gen-ssp/misc/fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expandGlob } from "https://deno.land/std@0.126.0/fs/mod.ts";
import { expandGlob } from "https://deno.land/std@0.138.0/fs/mod.ts";

export async function globFiles(
root: string,
Expand Down
4 changes: 2 additions & 2 deletions gen-ssp/pbjs/misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ensureDir } from "https://deno.land/std@0.126.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import { ensureDir } from "https://deno.land/std@0.138.0/fs/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";

export interface TextFile {
dir: string[];
Expand Down
2 changes: 1 addition & 1 deletion gen-ssp/ubershape.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import { Schema } from "https://deno.land/x/[email protected]/schema.ts";
import { schema2ts } from "https://deno.land/x/[email protected]/codegen/ts.ts";
import { getReadFunction } from "https://deno.land/x/[email protected]/io/read-schema.ts";
Expand Down
4 changes: 2 additions & 2 deletions gen-ssp/urichk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { walk } from "https://deno.land/std@0.126.0/fs/walk.ts";
import * as path from "https://deno.land/std@0.126.0/path/mod.ts";
import { walk } from "https://deno.land/std@0.138.0/fs/walk.ts";
import * as path from "https://deno.land/std@0.138.0/path/mod.ts";
import { parse } from "https://deno.land/x/[email protected]/index.ts";
import type { Urichk } from "https://deno.land/x/[email protected]/ast.ts";

Expand Down
4 changes: 2 additions & 2 deletions keycloak/extract-group-mapping-from-proto-services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stringify } from "https://deno.land/std@0.126.0/encoding/yaml.ts";
import { walk } from "https://deno.land/std@0.126.0/fs/walk.ts";
import { stringify } from "https://deno.land/std@0.138.0/encoding/yaml.ts";
import { walk } from "https://deno.land/std@0.138.0/fs/walk.ts";
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import * as ast from "https://deno.land/x/[email protected]/core/ast/index.ts";
import { parse } from "https://deno.land/x/[email protected]/core/parser/proto.ts";
Expand Down
2 changes: 1 addition & 1 deletion keycloak/oidc-auth-for-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { serve } from "https://deno.land/std@0.126.0/http/server.ts";
import { serve } from "https://deno.land/std@0.138.0/http/server.ts";
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import openBrowser from "../misc/open-browser.ts";

Expand Down
2 changes: 1 addition & 1 deletion misc/open-browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from "https://deno.land/std@0.126.0/fmt/colors.ts";
import { bold } from "https://deno.land/std@0.138.0/fmt/colors.ts";
import {
print,
println,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface CreateReactComponentOption {
forwardRef?: boolean;
onlyNamedExport?: boolean;
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions www-snippet/create-react-component/__mocks__/readMockFile.test.ts

This file was deleted.

25 changes: 0 additions & 25 deletions www-snippet/create-react-component/__mocks__/readMockFile.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const snapshot = {};

snapshot[`should return correct react component. 1`] = `
'import React, { memo, PropsWithChildren } from "react";
export interface LoremIpsumProps {}
const LoremIpsum = (({}: PropsWithChildren<LoremIpsumProps>) => {
return <>LoremIpsum</>;
});
export default memo(LoremIpsum);
'
`;
snapshot[`should return correct react component. 2`] = `
'import React, { forwardRef, memo } from "react";
type RefElement = HTMLDivElement;
type RefElementProps = React.HTMLAttributes<HTMLDivElement>;
export interface LoremIpsumProps extends RefElementProps {}
const LoremIpsum = forwardRef<RefElement, LoremIpsumProps>((props, ref) => {
return <div ref={ref} {...props}>Lorem Ipsum</div>;
});
export default memo(LoremIpsum)
LoremIpsum.displayName = "LoremIpsum";
'
`;
snapshot[`should return correct react component. 3`] = `
'import React, { memo, PropsWithChildren } from "react";
export interface LoremIpsumProps {}
const LoremIpsum = (({}: PropsWithChildren<LoremIpsumProps>) => {
return <>LoremIpsum</>;
});
export { LoremIpsum: memo(LoremIpsum) };
'
`;
snapshot[`should return correct react component. 4`] = `
'import React, { forwardRef, memo } from "react";
type RefElement = HTMLDivElement;
type RefElementProps = React.HTMLAttributes<HTMLDivElement>;
export interface LoremIpsumProps extends RefElementProps {}
const LoremIpsum = forwardRef<RefElement, LoremIpsumProps>((props, ref) => {
return <div ref={ref} {...props}>Lorem Ipsum</div>;
});
export { LoremIpsum: memo(LoremIpsum) }
LoremIpsum.displayName = "LoremIpsum";
'
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const snapshot = {};

snapshot[`should return correct react component re-export. 1`] = `
'export { default } from "./LoremIpsum";
export * from "./LoremIpsum";
'
`;

snapshot[`should return correct react component re-export. 2`] = `
'export * from "./LoremIpsum";
'
`;
Loading

0 comments on commit 82930c7

Please sign in to comment.