Skip to content

Commit 1c6fabf

Browse files
authored
Merge pull request #43 from SpaceyaTech/setup-ci-actions
Remove Playwright workflow and add linting/testing workflow
2 parents c332150 + cdfa244 commit 1c6fabf

File tree

7 files changed

+142
-126
lines changed

7 files changed

+142
-126
lines changed

.github/workflows/playwright.yml renamed to .github/workflows/housekeeping.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Playwright Tests
1+
name: lint and test
22
on:
33
push:
44
branches: [ main, master ]
@@ -17,6 +17,10 @@ jobs:
1717
run: npm install -g pnpm && pnpm install
1818
- name: Install Playwright Browsers
1919
run: pnpm exec playwright install --with-deps
20+
- name: Lint code
21+
run: pnpm lint
22+
- name: Run unit tests
23+
run: pnpm vitest
2024
- name: Start Vite dev server
2125
run: pnpm exec vite --port 3000 &
2226
- name: Run Playwright tests

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
"lint": "eslint . --fix",
99
"format": "prettier --write --ignore-unknown src",
1010
"page": "tsx src/scripts/scafold-pages/script.ts",
11-
"vitest": "vitest --ui",
11+
"vitest": "vitest",
12+
"vitest:ui": "vitest --ui",
1213
"playwright": "playwright test --ui",
1314
"test": "npm run vitest && npm run playwright",
1415
"build": "tsc -b && vite build",
16+
"dryrun":"npm run lint && npm run test && npm run build",
1517
"preview": "vite preview"
1618
},
1719
"dependencies": {

pnpm-lock.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sample.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from "vitest";
2+
3+
test("should pass", () => {
4+
expect(true).toBe(true);
5+
});
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { resolve } from "node:path";
2+
import { writeFile, access, mkdir } from "node:fs/promises";
3+
import {
4+
rootPageComponentTemplate,
5+
rootPageListComponentsTemplate,
6+
rootPageTemplate,
7+
} from "./base-templates";
8+
import {
9+
rootPageBaseFormComponentsTemplate,
10+
rootPageCreateFormComponentsTemplate,
11+
rootPageUpdateFormComponentsTemplate,
12+
} from "./form-templates";
13+
import {
14+
rootOnePageComponentsTemplate,
15+
rootOnePageDetailsComponentsTemplate,
16+
rootOnePageTemplate,
17+
} from "./one-page-template";
18+
import { rootPageQeuryOptionsTemplate } from "./query-options-tempaltes";
19+
export async function scaffoldPage(pagename: string, path: string) {
20+
const roootDirpath = `./src/routes${path}`;
21+
// const roootDirpath = resolve("./src/routes",path)
22+
await mkdir(roootDirpath, { recursive: true });
23+
const capitalpagename = pagename.charAt(0).toUpperCase() + pagename.slice(1);
24+
let rootPath = path.trim();
25+
if (rootPath.length == 0) {
26+
throw new Error("Path cannot be empty");
27+
}
28+
if (rootPath.endsWith("/")) {
29+
rootPath = rootPath.slice(0, rootPath.length - 1);
30+
}
31+
if (rootPath.startsWith("./")) {
32+
rootPath = rootPath.slice(2);
33+
}
34+
if (rootPath.startsWith("/")) {
35+
rootPath = rootPath.slice(1);
36+
}
37+
38+
const indexPage = {
39+
path: `${rootPath}/index.tsx`,
40+
component: rootPageTemplate(pagename, rootPath),
41+
};
42+
const indexPageComponent = {
43+
path: `${rootPath}/-components/${capitalpagename}Page.tsx`,
44+
component: rootPageComponentTemplate(pagename, rootPath),
45+
};
46+
const indexPageListComponent = {
47+
path: `${rootPath}/-components/list/${capitalpagename}List.tsx`,
48+
component: rootPageListComponentsTemplate(pagename, rootPath),
49+
};
50+
51+
const baseForm = {
52+
path: `${rootPath}/-components/form/base.tsx`,
53+
component: rootPageBaseFormComponentsTemplate(pagename),
54+
};
55+
const createForm = {
56+
path: `${rootPath}/-components/form/create.tsx`,
57+
component: rootPageCreateFormComponentsTemplate(pagename),
58+
};
59+
const updateForm = {
60+
path: `${rootPath}/-components/form/update.tsx`,
61+
component: rootPageUpdateFormComponentsTemplate(pagename),
62+
};
63+
64+
// const listComponent = {
65+
// path: `${rootPath}/-components/${capitalpagename}List.tsx`,
66+
// component: rootPageListComponentsTemplate(pagename, rootPath),
67+
// };
68+
const onePageComponent = {
69+
path: `${rootPath}/$${pagename}/index.tsx`,
70+
component: rootOnePageTemplate(pagename, rootPath),
71+
};
72+
const onepageComponent = {
73+
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Page.tsx`,
74+
component: rootOnePageComponentsTemplate(pagename),
75+
};
76+
const onepageDetailsComponent = {
77+
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Details.tsx`,
78+
component: rootOnePageDetailsComponentsTemplate(pagename, rootPath),
79+
};
80+
const queryOptions = {
81+
path: `${rootPath}/-query-options/${pagename}-query-option.ts`,
82+
component: rootPageQeuryOptionsTemplate(pagename),
83+
};
84+
85+
const allPaths = [
86+
indexPage,
87+
indexPageComponent,
88+
baseForm,
89+
createForm,
90+
updateForm,
91+
indexPageListComponent,
92+
onePageComponent,
93+
onepageComponent,
94+
onepageDetailsComponent,
95+
queryOptions,
96+
];
97+
98+
const allComponentPaths = allPaths.map((path) => {
99+
console.log("path======= > ", path.path);
100+
return ensurePathExistsOrCreate(path.path, path.component);
101+
});
102+
await Promise.all(allComponentPaths);
103+
}
104+
105+
async function ensurePathExistsOrCreate(path: string, component: string) {
106+
const component_path = resolve("./src/routes", path);
107+
try {
108+
await access(component_path);
109+
} catch (err: unknown) {
110+
if (err instanceof Error) {
111+
if (err.message.includes("no such file or directory")) {
112+
await writeFile(component_path, component).catch(async (err) => {
113+
if (err.code === "ENOENT") {
114+
const directryPath = component_path
115+
.split("/")
116+
.slice(0, -1)
117+
.join("/");
118+
await mkdir(directryPath, { recursive: true });
119+
await writeFile(component_path, component);
120+
}
121+
});
122+
}
123+
}
124+
}
125+
}

src/scripts/scafold-pages/script.ts

Lines changed: 1 addition & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,6 @@
1-
import { resolve } from "node:path";
2-
import { rootPageComponentTemplate, rootPageListComponentsTemplate, rootPageTemplate } from "./base-templates"
3-
import { rootPageBaseFormComponentsTemplate, rootPageCreateFormComponentsTemplate, rootPageUpdateFormComponentsTemplate } from "./form-templates"
4-
import { rootOnePageComponentsTemplate, rootOnePageDetailsComponentsTemplate, rootOnePageTemplate } from "./one-page-template";
5-
import { rootPageQeuryOptionsTemplate } from "./query-options-tempaltes"
6-
import { writeFile, access, mkdir } from "node:fs/promises"
1+
import { scaffoldPage } from "./scafold-page"
72

83

9-
10-
async function scaffoldPage(pagename: string, path: string) {
11-
const roootDirpath = `./src/routes${ path}`
12-
// const roootDirpath = resolve("./src/routes",path)
13-
await mkdir(roootDirpath, { recursive: true }).catch(() => {
14-
// if (err instanceof Error) {
15-
// if (err.message.includes("EEXIST")) {
16-
// }else{
17-
// throw err
18-
// }
19-
// }
20-
21-
})
22-
const capitalpagename = pagename.charAt(0).toUpperCase() + pagename.slice(1);
23-
let rootPath = path.trim()
24-
if (rootPath.length == 0) {
25-
throw new Error("Path cannot be empty")
26-
}
27-
if (rootPath.endsWith("/")) {
28-
rootPath = rootPath.slice(0, rootPath.length - 1)
29-
}
30-
if (rootPath.startsWith("./")) {
31-
rootPath = rootPath.slice(2)
32-
}
33-
if (rootPath.startsWith("/")) {
34-
rootPath = rootPath.slice(1)
35-
}
36-
37-
const indexPage = {
38-
path: `${rootPath}/index.tsx`,
39-
component: rootPageTemplate(pagename, rootPath),
40-
};
41-
const indexPageComponent = {
42-
path: `${rootPath}/-components/${capitalpagename}Page.tsx`,
43-
component: rootPageComponentTemplate(pagename, rootPath),
44-
};
45-
const indexPageListComponent = {
46-
path: `${rootPath}/-components/list/${capitalpagename}List.tsx`,
47-
component: rootPageListComponentsTemplate(pagename, rootPath),
48-
};
49-
50-
const baseForm = {
51-
path: `${rootPath}/-components/form/base.tsx`,
52-
component: rootPageBaseFormComponentsTemplate(pagename),
53-
};
54-
const createForm = {
55-
path: `${rootPath}/-components/form/create.tsx`,
56-
component: rootPageCreateFormComponentsTemplate(pagename),
57-
};
58-
const updateForm = {
59-
path: `${rootPath}/-components/form/update.tsx`,
60-
component: rootPageUpdateFormComponentsTemplate(pagename),
61-
};
62-
63-
// const listComponent = {
64-
// path: `${rootPath}/-components/${capitalpagename}List.tsx`,
65-
// component: rootPageListComponentsTemplate(pagename, rootPath),
66-
// };
67-
const onePageComponent = {
68-
path: `${rootPath}/$${pagename}/index.tsx`,
69-
component: rootOnePageTemplate(pagename, rootPath),
70-
}
71-
const onepageComponent = {
72-
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Page.tsx`,
73-
component: rootOnePageComponentsTemplate(pagename),
74-
};
75-
const onepageDetailsComponent = {
76-
path: `${rootPath}/-components/one${pagename}/One${capitalpagename}Details.tsx`,
77-
component: rootOnePageDetailsComponentsTemplate(pagename, rootPath),
78-
}
79-
const queryOptions = {
80-
path: `${rootPath}/-query-options/${pagename}-query-option.ts`,
81-
component: rootPageQeuryOptionsTemplate(pagename),
82-
};
83-
84-
const allPaths = [
85-
indexPage,
86-
indexPageComponent,
87-
baseForm,
88-
createForm,
89-
updateForm,
90-
indexPageListComponent,
91-
onePageComponent,
92-
onepageComponent,
93-
onepageDetailsComponent,
94-
queryOptions
95-
]
96-
97-
const allComponentPaths = allPaths.map((path) => {
98-
console.log("path======= > ", path.path)
99-
return ensurePathExistsOrCreate(path.path, path.component)
100-
})
101-
await Promise.all(allComponentPaths)
102-
103-
}
104-
105-
async function ensurePathExistsOrCreate(path: string, component: string) {
106-
const component_path = resolve("./src/routes",path)
107-
try {
108-
await access(component_path)
109-
} catch (err: unknown) {
110-
if (err instanceof Error) {
111-
if (err.message.includes("no such file or directory")) {
112-
await writeFile(component_path, component)
113-
.catch(async(err) => {
114-
if(err.code === "ENOENT"){
115-
const directryPath = component_path.split("/").slice(0,-1).join("/")
116-
await mkdir(directryPath, { recursive: true })
117-
await writeFile(component_path, component)
118-
}
119-
})
120-
}
121-
}
122-
}
123-
}
124-
1254
function main() {
1265
const components_path = process.argv[2]
1276

vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default defineConfig({
2626
},
2727
test: {
2828
globals: true,
29-
include: ["./src"],
30-
exclude: ["e2e-tests","node_modules"],
29+
include: ["./src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
30+
exclude: ["e2e-tests", "node_modules"],
3131
},
3232
});

0 commit comments

Comments
 (0)