Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Playwright workflow and add linting/testing workflow #43

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Playwright Tests
name: lint and test
on:
push:
branches: [ main, master ]
Expand All @@ -17,6 +17,10 @@ jobs:
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Lint code
run: pnpm lint
- name: Run unit tests
run: pnpm vitest
- name: Start Vite dev server
run: pnpm exec vite --port 3000 &
- name: Run Playwright tests
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"lint": "eslint . --fix",
"format": "prettier --write --ignore-unknown src",
"page": "tsx src/scripts/scafold-pages/script.ts",
"vitest": "vitest --ui",
"vitest": "vitest",
"vitest:ui": "vitest --ui",
"playwright": "playwright test --ui",
"test": "npm run vitest && npm run playwright",
"build": "tsc -b && vite build",
"dryrun":"npm run lint && npm run test && npm run build",
"preview": "vite preview"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/sample.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from "vitest";

test("should pass", () => {
expect(true).toBe(true);
});
125 changes: 125 additions & 0 deletions src/scripts/scafold-pages/scafold-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { resolve } from "node:path";
import { writeFile, access, mkdir } from "node:fs/promises";
import {
rootPageComponentTemplate,
rootPageListComponentsTemplate,
rootPageTemplate,
} from "./base-templates";
import {
rootPageBaseFormComponentsTemplate,
rootPageCreateFormComponentsTemplate,
rootPageUpdateFormComponentsTemplate,
} from "./form-templates";
import {
rootOnePageComponentsTemplate,
rootOnePageDetailsComponentsTemplate,
rootOnePageTemplate,
} from "./one-page-template";
import { rootPageQeuryOptionsTemplate } from "./query-options-tempaltes";
export async function scaffoldPage(pagename: string, path: string) {
const roootDirpath = `./src/routes${path}`;
// const roootDirpath = resolve("./src/routes",path)
await mkdir(roootDirpath, { recursive: true });
const capitalpagename = pagename.charAt(0).toUpperCase() + pagename.slice(1);
let rootPath = path.trim();
if (rootPath.length == 0) {
throw new Error("Path cannot be empty");
}
if (rootPath.endsWith("/")) {
rootPath = rootPath.slice(0, rootPath.length - 1);
}
if (rootPath.startsWith("./")) {
rootPath = rootPath.slice(2);
}
if (rootPath.startsWith("/")) {
rootPath = rootPath.slice(1);
}

const indexPage = {
path: `${rootPath}/index.tsx`,
component: rootPageTemplate(pagename, rootPath),
};
const indexPageComponent = {
path: `${rootPath}/-components/${capitalpagename}Page.tsx`,
component: rootPageComponentTemplate(pagename, rootPath),
};
const indexPageListComponent = {
path: `${rootPath}/-components/list/${capitalpagename}List.tsx`,
component: rootPageListComponentsTemplate(pagename, rootPath),
};

const baseForm = {
path: `${rootPath}/-components/form/base.tsx`,
component: rootPageBaseFormComponentsTemplate(pagename),
};
const createForm = {
path: `${rootPath}/-components/form/create.tsx`,
component: rootPageCreateFormComponentsTemplate(pagename),
};
const updateForm = {
path: `${rootPath}/-components/form/update.tsx`,
component: rootPageUpdateFormComponentsTemplate(pagename),
};

// const listComponent = {
// path: `${rootPath}/-components/${capitalpagename}List.tsx`,
// component: rootPageListComponentsTemplate(pagename, rootPath),
// };
const onePageComponent = {
path: `${rootPath}/$${pagename}/index.tsx`,
component: rootOnePageTemplate(pagename, rootPath),
};
const onepageComponent = {
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Page.tsx`,
component: rootOnePageComponentsTemplate(pagename),
};
const onepageDetailsComponent = {
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Details.tsx`,
component: rootOnePageDetailsComponentsTemplate(pagename, rootPath),
};
const queryOptions = {
path: `${rootPath}/-query-options/${pagename}-query-option.ts`,
component: rootPageQeuryOptionsTemplate(pagename),
};

const allPaths = [
indexPage,
indexPageComponent,
baseForm,
createForm,
updateForm,
indexPageListComponent,
onePageComponent,
onepageComponent,
onepageDetailsComponent,
queryOptions,
];

const allComponentPaths = allPaths.map((path) => {
console.log("path======= > ", path.path);
return ensurePathExistsOrCreate(path.path, path.component);
});
await Promise.all(allComponentPaths);
}

async function ensurePathExistsOrCreate(path: string, component: string) {
const component_path = resolve("./src/routes", path);
try {
await access(component_path);
} catch (err: unknown) {
if (err instanceof Error) {
if (err.message.includes("no such file or directory")) {
await writeFile(component_path, component).catch(async (err) => {
if (err.code === "ENOENT") {
const directryPath = component_path
.split("/")
.slice(0, -1)
.join("/");
await mkdir(directryPath, { recursive: true });
await writeFile(component_path, component);
}
});
}
}
}
}
123 changes: 1 addition & 122 deletions src/scripts/scafold-pages/script.ts
Original file line number Diff line number Diff line change
@@ -1,127 +1,6 @@
import { resolve } from "node:path";
import { rootPageComponentTemplate, rootPageListComponentsTemplate, rootPageTemplate } from "./base-templates"
import { rootPageBaseFormComponentsTemplate, rootPageCreateFormComponentsTemplate, rootPageUpdateFormComponentsTemplate } from "./form-templates"
import { rootOnePageComponentsTemplate, rootOnePageDetailsComponentsTemplate, rootOnePageTemplate } from "./one-page-template";
import { rootPageQeuryOptionsTemplate } from "./query-options-tempaltes"
import { writeFile, access, mkdir } from "node:fs/promises"
import { scaffoldPage } from "./scafold-page"



async function scaffoldPage(pagename: string, path: string) {
const roootDirpath = `./src/routes${ path}`
// const roootDirpath = resolve("./src/routes",path)
await mkdir(roootDirpath, { recursive: true }).catch(() => {
// if (err instanceof Error) {
// if (err.message.includes("EEXIST")) {
// }else{
// throw err
// }
// }

})
const capitalpagename = pagename.charAt(0).toUpperCase() + pagename.slice(1);
let rootPath = path.trim()
if (rootPath.length == 0) {
throw new Error("Path cannot be empty")
}
if (rootPath.endsWith("/")) {
rootPath = rootPath.slice(0, rootPath.length - 1)
}
if (rootPath.startsWith("./")) {
rootPath = rootPath.slice(2)
}
if (rootPath.startsWith("/")) {
rootPath = rootPath.slice(1)
}

const indexPage = {
path: `${rootPath}/index.tsx`,
component: rootPageTemplate(pagename, rootPath),
};
const indexPageComponent = {
path: `${rootPath}/-components/${capitalpagename}Page.tsx`,
component: rootPageComponentTemplate(pagename, rootPath),
};
const indexPageListComponent = {
path: `${rootPath}/-components/list/${capitalpagename}List.tsx`,
component: rootPageListComponentsTemplate(pagename, rootPath),
};

const baseForm = {
path: `${rootPath}/-components/form/base.tsx`,
component: rootPageBaseFormComponentsTemplate(pagename),
};
const createForm = {
path: `${rootPath}/-components/form/create.tsx`,
component: rootPageCreateFormComponentsTemplate(pagename),
};
const updateForm = {
path: `${rootPath}/-components/form/update.tsx`,
component: rootPageUpdateFormComponentsTemplate(pagename),
};

// const listComponent = {
// path: `${rootPath}/-components/${capitalpagename}List.tsx`,
// component: rootPageListComponentsTemplate(pagename, rootPath),
// };
const onePageComponent = {
path: `${rootPath}/$${pagename}/index.tsx`,
component: rootOnePageTemplate(pagename, rootPath),
}
const onepageComponent = {
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Page.tsx`,
component: rootOnePageComponentsTemplate(pagename),
};
const onepageDetailsComponent = {
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Details.tsx`,
component: rootOnePageDetailsComponentsTemplate(pagename, rootPath),
}
const queryOptions = {
path: `${rootPath}/-query-options/${pagename}-query-option.ts`,
component: rootPageQeuryOptionsTemplate(pagename),
};

const allPaths = [
indexPage,
indexPageComponent,
baseForm,
createForm,
updateForm,
indexPageListComponent,
onePageComponent,
onepageComponent,
onepageDetailsComponent,
queryOptions
]

const allComponentPaths = allPaths.map((path) => {
console.log("path======= > ", path.path)
return ensurePathExistsOrCreate(path.path, path.component)
})
await Promise.all(allComponentPaths)

}

async function ensurePathExistsOrCreate(path: string, component: string) {
const component_path = resolve("./src/routes",path)
try {
await access(component_path)
} catch (err: unknown) {
if (err instanceof Error) {
if (err.message.includes("no such file or directory")) {
await writeFile(component_path, component)
.catch(async(err) => {
if(err.code === "ENOENT"){
const directryPath = component_path.split("/").slice(0,-1).join("/")
await mkdir(directryPath, { recursive: true })
await writeFile(component_path, component)
}
})
}
}
}
}

function main() {
const components_path = process.argv[2]

Expand Down
4 changes: 2 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineConfig({
},
test: {
globals: true,
include: ["./src"],
exclude: ["e2e-tests","node_modules"],
include: ["./src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
exclude: ["e2e-tests", "node_modules"],
},
});