Skip to content
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
54 changes: 54 additions & 0 deletions .github/scripts/verify-snippet-script-paths.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Ensures every npm script in examples/snippets/package.json that runs
* `node <path>.js` points at an existing file. For CI only.
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.join(__dirname, '..', '..');
const snippetsRoot = path.join(repoRoot, 'examples', 'snippets');
const pkgPath = path.join(snippetsRoot, 'package.json');

const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const scripts = pkg.scripts ?? {};

const errors = [];
let verified = 0;

for (const [name, cmd] of Object.entries(scripts)) {
const trimmed = String(cmd).trimStart();
if (!trimmed.startsWith('node ')) {
continue;
}

const afterNode = trimmed.slice(5).trim();
const match = afterNode.match(/^([^\s]+\.js)\b/);
if (!match) {
errors.push(`Script "${name}": could not parse a .js entry file from: ${cmd}`);
continue;
}

const relPath = match[1].replace(/^\.\//, '');
const absPath = path.resolve(snippetsRoot, relPath);

if (!fs.existsSync(absPath)) {
errors.push(
`Script "${name}": file not found: ${path.relative(snippetsRoot, absPath)}`,
);
continue;
}

verified += 1;
}

if (errors.length > 0) {
console.error('Snippet script path verification failed:\n');
for (const line of errors) {
console.error(` - ${line}`);
}
process.exit(1);
}

console.log(`OK: ${verified} node snippet script path(s) exist under examples/snippets.`);
3 changes: 3 additions & 0 deletions .github/workflows/run-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- name: Run ESLint
run: npx eslint "packages/**/{src,tests}/**/*.ts" "examples/**/{src,}/**/*.{js,ts}" --ignore-pattern "**/node_modules/**" --ignore-pattern "**/dist/**"

- name: Verify snippet npm script paths
run: node .github/scripts/verify-snippet-script-paths.mjs

- name: Build project
run: yarn run build

Expand Down
44 changes: 22 additions & 22 deletions examples/snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
},
"scripts": {
"build": "tsc --noEmit",
"conversation:app:create": "node conversation/application/create.js",
"conversation:app:get": "node conversation/application/get.js",
"conversation:app:list": "node conversation/application/list.js",
"conversation:app:update": "node conversation/application/update.js",
"conversation:app:delete": "node conversation/application/delete.js",
"conversation:app:create": "node conversation/applications/create.js",
"conversation:app:get": "node conversation/applications/get.js",
"conversation:app:list": "node conversation/applications/list.js",
"conversation:app:update": "node conversation/applications/update.js",
"conversation:app:delete": "node conversation/applications/delete.js",
"conversation:capability:lookup": "node conversation/capability/lookup.js",
"conversation:consents:listIdentities": "node conversation/consents/list-identities.js",
"conversation:consents:listAuditRecords": "node conversation/consents/list-audit-records.js",
"conversation:contact:create": "node conversation/contact/create.js",
"conversation:contact:get": "node conversation/contact/get.js",
"conversation:contact:get-channel-profile": "node conversation/contact/get-channel-profile.js",
"conversation:contact:list": "node conversation/contact/list.js",
"conversation:contact:update": "node conversation/contact/update.js",
"conversation:contact:merge": "node conversation/contact/merge.js",
"conversation:contact:delete": "node conversation/contact/delete.js",
"conversation:contact:list-identity-conflicts": "node conversation/contact/list-identity-conflicts.js",
"conversation:conversation:create": "node conversation/conversation/create.js",
"conversation:conversation:get": "node conversation/conversation/get.js",
"conversation:conversation:list": "node conversation/conversation/list.js",
"conversation:conversation:list-recent": "node conversation/conversation/list-recent.js",
"conversation:conversation:update": "node conversation/conversation/update.js",
"conversation:conversation:stop-active": "node conversation/conversation/stop-active.js",
"conversation:conversation:delete": "node conversation/conversation/delete.js",
"conversation:conversation:inject-event": "node conversation/conversation/inject-event.js",
"conversation:conversation:inject-message": "node conversation/conversation/inject-message.js",
"conversation:contact:create": "node conversation/contacts/create.js",
"conversation:contact:get": "node conversation/contacts/get.js",
"conversation:contact:get-channel-profile": "node conversation/contacts/get-channel-profile.js",
"conversation:contact:list": "node conversation/contacts/list.js",
"conversation:contact:update": "node conversation/contacts/update.js",
"conversation:contact:merge": "node conversation/contacts/merge.js",
"conversation:contact:delete": "node conversation/contacts/delete.js",
"conversation:contact:list-identity-conflicts": "node conversation/contacts/list-identity-conflicts.js",
"conversation:conversation:create": "node conversation/conversations/create.js",
"conversation:conversation:get": "node conversation/conversations/get.js",
"conversation:conversation:list": "node conversation/conversations/list.js",
"conversation:conversation:list-recent": "node conversation/conversations/list-recent.js",
"conversation:conversation:update": "node conversation/conversations/update.js",
"conversation:conversation:stop-active": "node conversation/conversations/stop-active.js",
"conversation:conversation:delete": "node conversation/conversations/delete.js",
"conversation:conversation:inject-event": "node conversation/conversations/inject-event.js",
"conversation:conversation:inject-message": "node conversation/conversations/inject-message.js",
"conversation:events:send": "node conversation/events/send.js",
"conversation:events:get": "node conversation/events/get.js",
"conversation:events:list": "node conversation/events/list.js",
Expand Down
Loading