create-selfchecks 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +56 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/templates.d.ts +12 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +105 -0
- package/package.json +40 -0
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createSelfchecksProject } from "./index.js";
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
6
|
+
printHelp();
|
|
7
|
+
process.exit(0);
|
|
8
|
+
}
|
|
9
|
+
const skipInstall = args.includes("--skip-install");
|
|
10
|
+
const positionalArgs = args.filter((argument) => !argument.startsWith("-"));
|
|
11
|
+
const unknownOptions = args.filter((argument) => argument.startsWith("-") && argument !== "--skip-install");
|
|
12
|
+
if (unknownOptions.length > 0) {
|
|
13
|
+
fail(`Unknown option: ${unknownOptions[0]}`);
|
|
14
|
+
}
|
|
15
|
+
else if (positionalArgs.length > 1) {
|
|
16
|
+
fail("Expected at most one target directory.");
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const targetDir = positionalArgs[0] ?? "selfchecks-project";
|
|
20
|
+
createSelfchecksProject({ install: !skipInstall, targetDir })
|
|
21
|
+
.then((result) => {
|
|
22
|
+
const relativeDir = path.relative(process.cwd(), result.targetDir) || ".";
|
|
23
|
+
const displayDir = path.isAbsolute(targetDir) ? result.targetDir : relativeDir;
|
|
24
|
+
process.stdout.write(`\nCreated Selfchecks project in ${result.targetDir}\n\n`);
|
|
25
|
+
process.stdout.write("Next steps:\n");
|
|
26
|
+
if (relativeDir !== ".") {
|
|
27
|
+
process.stdout.write(` cd ${JSON.stringify(displayDir)}\n`);
|
|
28
|
+
}
|
|
29
|
+
if (!result.installed) {
|
|
30
|
+
process.stdout.write(" npm install\n");
|
|
31
|
+
}
|
|
32
|
+
process.stdout.write(" npx playwright install chromium\n");
|
|
33
|
+
process.stdout.write(" npm test\n");
|
|
34
|
+
})
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function printHelp() {
|
|
40
|
+
process.stdout.write(`Usage: create-selfchecks [directory] [options]
|
|
41
|
+
|
|
42
|
+
Create a minimal Selfchecks project with a browser check for
|
|
43
|
+
https://selfchecks.github.io/.
|
|
44
|
+
|
|
45
|
+
Arguments:
|
|
46
|
+
directory Target directory (default: selfchecks-project)
|
|
47
|
+
|
|
48
|
+
Options:
|
|
49
|
+
--skip-install Create files without running npm install
|
|
50
|
+
-h, --help Display this help
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
function fail(message) {
|
|
54
|
+
process.stderr.write(`${message}\n`);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type CreateSelfchecksOptions = {
|
|
2
|
+
install?: boolean;
|
|
3
|
+
targetDir: string;
|
|
4
|
+
};
|
|
5
|
+
export type CreateSelfchecksResult = {
|
|
6
|
+
installed: boolean;
|
|
7
|
+
projectName: string;
|
|
8
|
+
targetDir: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function createSelfchecksProject(options: CreateSelfchecksOptions): Promise<CreateSelfchecksResult>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CAyBjC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdir, readdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createPackageJson, starterFiles } from "./templates.js";
|
|
5
|
+
export async function createSelfchecksProject(options) {
|
|
6
|
+
const targetDir = path.resolve(options.targetDir);
|
|
7
|
+
const projectName = normalizePackageName(path.basename(targetDir));
|
|
8
|
+
await ensureEmptyDirectory(targetDir);
|
|
9
|
+
const files = {
|
|
10
|
+
...starterFiles,
|
|
11
|
+
"package.json": createPackageJson(projectName),
|
|
12
|
+
};
|
|
13
|
+
for (const [relativePath, content] of Object.entries(files)) {
|
|
14
|
+
const filePath = path.join(targetDir, relativePath);
|
|
15
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
16
|
+
await writeFile(filePath, content, "utf8");
|
|
17
|
+
}
|
|
18
|
+
const install = options.install ?? true;
|
|
19
|
+
if (install) {
|
|
20
|
+
await installDependencies(targetDir);
|
|
21
|
+
}
|
|
22
|
+
return { installed: install, projectName, targetDir };
|
|
23
|
+
}
|
|
24
|
+
async function ensureEmptyDirectory(targetDir) {
|
|
25
|
+
await mkdir(targetDir, { recursive: true });
|
|
26
|
+
const entries = await readdir(targetDir);
|
|
27
|
+
if (entries.length > 0) {
|
|
28
|
+
throw new Error(`Target directory is not empty: ${targetDir}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function installDependencies(targetDir) {
|
|
32
|
+
const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
33
|
+
await new Promise((resolve, reject) => {
|
|
34
|
+
const child = spawn(npmCommand, ["install", "--no-audit", "--no-fund"], {
|
|
35
|
+
cwd: targetDir,
|
|
36
|
+
stdio: "inherit",
|
|
37
|
+
});
|
|
38
|
+
child.once("error", reject);
|
|
39
|
+
child.once("close", (status) => {
|
|
40
|
+
if (status === 0) {
|
|
41
|
+
resolve();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
reject(new Error(`npm install exited with status ${status ?? "unknown"}.`));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function normalizePackageName(value) {
|
|
49
|
+
const normalized = value
|
|
50
|
+
.trim()
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
53
|
+
.replace(/^[._-]+|[._-]+$/g, "");
|
|
54
|
+
return normalized || "selfchecks-project";
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SELFCHECKS_PACKAGE_VERSION = "0.1.1";
|
|
2
|
+
export declare const starterFiles: {
|
|
3
|
+
readonly ".gitignore": "node_modules/\nplaywright-report/\ntest-results/\n.selfchecks/\n";
|
|
4
|
+
readonly "README.md": "# Selfchecks starter\n\nThis project was created with `create-selfchecks` and checks that the Selfchecks\nwebsite is available.\n\n```bash\nnpx playwright install chromium\nnpm test\n\nexport SELFCHECKS_URL=https://checks.example.com\nexport SELFCHECKS_API_TOKEN=replace-with-a-secret\nnpm run selfchecks -- deploy --project starter --root .\n```\n";
|
|
5
|
+
readonly "checkly.config.ts": "import { defineConfig } from \"@selfchecks/selfchecks\";\nimport { Frequency } from \"@selfchecks/selfchecks/constructs\";\n\nexport default defineConfig({\n projectName: \"Selfchecks starter\",\n logicalId: \"selfchecks-starter\",\n checks: {\n activated: true,\n frequency: Frequency.EVERY_10M,\n checkMatch: \"**/*.check.ts\",\n browserChecks: {\n testMatch: \"**/*.spec.ts\",\n },\n },\n});\n";
|
|
6
|
+
readonly "checks/homepage.check.ts": "import { BrowserCheck, Frequency } from \"@selfchecks/selfchecks/constructs\";\n\nnew BrowserCheck(\"selfchecks-homepage\", {\n name: \"Selfchecks homepage\",\n activated: true,\n frequency: Frequency.EVERY_10M,\n tags: [\"starter\", \"browser\"],\n code: {\n entrypoint: \"homepage.spec.ts\",\n },\n});\n";
|
|
7
|
+
readonly "checks/homepage.spec.ts": "import { expect, test } from \"@playwright/test\";\n\ntest(\"selfchecks.github.io is available\", async ({ page }) => {\n const response = await page.goto(\"https://selfchecks.github.io/\");\n\n expect(response?.ok()).toBe(true);\n await expect(page).toHaveTitle(/Selfchecks/i);\n});\n";
|
|
8
|
+
readonly "playwright.config.ts": "import { defineConfig } from \"@playwright/test\";\n\nexport default defineConfig({\n testDir: \"./checks\",\n timeout: 60_000,\n use: {\n screenshot: \"only-on-failure\",\n trace: \"retain-on-failure\",\n },\n});\n";
|
|
9
|
+
readonly "tsconfig.json": "{\n \"compilerOptions\": {\n \"lib\": [\"ESNext\", \"DOM\", \"DOM.Iterable\"],\n \"module\": \"NodeNext\",\n \"moduleResolution\": \"NodeNext\",\n \"noEmit\": true,\n \"strict\": true,\n \"target\": \"ES2022\",\n \"types\": [\"node\"]\n },\n \"include\": [\"**/*.ts\"]\n}\n";
|
|
10
|
+
};
|
|
11
|
+
export declare function createPackageJson(projectName: string): string;
|
|
12
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,UAAU,CAAC;AAElD,eAAO,MAAM,YAAY;;;;;;;;CAiFf,CAAC;AAEX,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAyB7D"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export const SELFCHECKS_PACKAGE_VERSION = "0.1.1";
|
|
2
|
+
export const starterFiles = {
|
|
3
|
+
".gitignore": `node_modules/
|
|
4
|
+
playwright-report/
|
|
5
|
+
test-results/
|
|
6
|
+
.selfchecks/
|
|
7
|
+
`,
|
|
8
|
+
"README.md": `# Selfchecks starter
|
|
9
|
+
|
|
10
|
+
This project was created with \`create-selfchecks\` and checks that the Selfchecks
|
|
11
|
+
website is available.
|
|
12
|
+
|
|
13
|
+
\`\`\`bash
|
|
14
|
+
npx playwright install chromium
|
|
15
|
+
npm test
|
|
16
|
+
|
|
17
|
+
export SELFCHECKS_URL=https://checks.example.com
|
|
18
|
+
export SELFCHECKS_API_TOKEN=replace-with-a-secret
|
|
19
|
+
npm run selfchecks -- deploy --project starter --root .
|
|
20
|
+
\`\`\`
|
|
21
|
+
`,
|
|
22
|
+
"checkly.config.ts": `import { defineConfig } from "@selfchecks/selfchecks";
|
|
23
|
+
import { Frequency } from "@selfchecks/selfchecks/constructs";
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
projectName: "Selfchecks starter",
|
|
27
|
+
logicalId: "selfchecks-starter",
|
|
28
|
+
checks: {
|
|
29
|
+
activated: true,
|
|
30
|
+
frequency: Frequency.EVERY_10M,
|
|
31
|
+
checkMatch: "**/*.check.ts",
|
|
32
|
+
browserChecks: {
|
|
33
|
+
testMatch: "**/*.spec.ts",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
`,
|
|
38
|
+
"checks/homepage.check.ts": `import { BrowserCheck, Frequency } from "@selfchecks/selfchecks/constructs";
|
|
39
|
+
|
|
40
|
+
new BrowserCheck("selfchecks-homepage", {
|
|
41
|
+
name: "Selfchecks homepage",
|
|
42
|
+
activated: true,
|
|
43
|
+
frequency: Frequency.EVERY_10M,
|
|
44
|
+
tags: ["starter", "browser"],
|
|
45
|
+
code: {
|
|
46
|
+
entrypoint: "homepage.spec.ts",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
`,
|
|
50
|
+
"checks/homepage.spec.ts": `import { expect, test } from "@playwright/test";
|
|
51
|
+
|
|
52
|
+
test("selfchecks.github.io is available", async ({ page }) => {
|
|
53
|
+
const response = await page.goto("https://selfchecks.github.io/");
|
|
54
|
+
|
|
55
|
+
expect(response?.ok()).toBe(true);
|
|
56
|
+
await expect(page).toHaveTitle(/Selfchecks/i);
|
|
57
|
+
});
|
|
58
|
+
`,
|
|
59
|
+
"playwright.config.ts": `import { defineConfig } from "@playwright/test";
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
testDir: "./checks",
|
|
63
|
+
timeout: 60_000,
|
|
64
|
+
use: {
|
|
65
|
+
screenshot: "only-on-failure",
|
|
66
|
+
trace: "retain-on-failure",
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
`,
|
|
70
|
+
"tsconfig.json": `{
|
|
71
|
+
"compilerOptions": {
|
|
72
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
73
|
+
"module": "NodeNext",
|
|
74
|
+
"moduleResolution": "NodeNext",
|
|
75
|
+
"noEmit": true,
|
|
76
|
+
"strict": true,
|
|
77
|
+
"target": "ES2022",
|
|
78
|
+
"types": ["node"]
|
|
79
|
+
},
|
|
80
|
+
"include": ["**/*.ts"]
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
};
|
|
84
|
+
export function createPackageJson(projectName) {
|
|
85
|
+
return `${JSON.stringify({
|
|
86
|
+
name: projectName,
|
|
87
|
+
version: "0.0.0",
|
|
88
|
+
private: true,
|
|
89
|
+
type: "module",
|
|
90
|
+
scripts: {
|
|
91
|
+
selfchecks: "selfchecks",
|
|
92
|
+
test: "playwright test",
|
|
93
|
+
typecheck: "tsc --noEmit",
|
|
94
|
+
},
|
|
95
|
+
dependencies: {
|
|
96
|
+
"@playwright/test": "1.58.2",
|
|
97
|
+
},
|
|
98
|
+
devDependencies: {
|
|
99
|
+
"@selfchecks/selfchecks": SELFCHECKS_PACKAGE_VERSION,
|
|
100
|
+
"@selfchecks/selfchecks-cli": SELFCHECKS_PACKAGE_VERSION,
|
|
101
|
+
"@types/node": "^20.19.1",
|
|
102
|
+
typescript: "^5.8.3",
|
|
103
|
+
},
|
|
104
|
+
}, null, 2)}\n`;
|
|
105
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-selfchecks",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Create a minimal Selfchecks project",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/**/*.d.ts",
|
|
8
|
+
"dist/**/*.d.ts.map",
|
|
9
|
+
"dist/**/*.js"
|
|
10
|
+
],
|
|
11
|
+
"bin": "./dist/bin.js",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/selfchecks/selfchecks.git",
|
|
26
|
+
"directory": "packages/create-selfchecks"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.0.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json && node -e \"require('node:fs').chmodSync('dist/bin.js', 0o755)\"",
|
|
33
|
+
"test": "vitest run --root ../.. packages/create-selfchecks/src/index.test.ts",
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
|
+
"vitest": "^3.2.4"
|
|
39
|
+
}
|
|
40
|
+
}
|