frontend-guardian 0.1.8 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/cli.js +70 -0
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -220,6 +220,70 @@ function printResult(projectName, result) {
220
220
  console.log(chalk.bold(" Scan Complete"));
221
221
  console.log(chalk.gray(" © Justinmoto · Frontend Guardian") + "\n");
222
222
  }
223
+ const WORKFLOW_YAML = `name: Frontend Guardian
224
+
225
+ on:
226
+ push:
227
+ branches: [main, master]
228
+ pull_request:
229
+ branches: [main, master]
230
+
231
+ jobs:
232
+ frontend-guardian:
233
+ name: Frontend Guardian (min score 70)
234
+ runs-on: ubuntu-latest
235
+ steps:
236
+ - uses: actions/checkout@v4
237
+
238
+ - name: Setup Node
239
+ uses: actions/setup-node@v4
240
+ with:
241
+ node-version: "22"
242
+
243
+ - name: Run Frontend Guardian
244
+ id: scan
245
+ run: |
246
+ npx frontend-guardian@latest . --json > scan-result.json
247
+ echo "score=$(node -e "console.log(JSON.parse(require('fs').readFileSync('scan-result.json','utf8')).score)")" >> $GITHUB_OUTPUT
248
+ env:
249
+ CI: true
250
+
251
+ - name: Comment on PR
252
+ if: github.event_name == 'pull_request'
253
+ uses: actions/github-script@v7
254
+ with:
255
+ script: |
256
+ const score = parseInt(process.env.SCORE || '0', 10);
257
+ const body = \`## Frontend Guardian\\n\\n**Score:** \${score}/100 (min 70)\\n\${score < 70 ? '❌ Below threshold' : '✅ Passed'}\`;
258
+ await github.rest.issues.createComment({
259
+ issue_number: context.issue.number,
260
+ owner: context.repo.owner,
261
+ repo: context.repo.repo,
262
+ body
263
+ });
264
+ env:
265
+ SCORE: $\{\{ steps.scan.outputs.score \}\}
266
+
267
+ - name: Fail if below threshold
268
+ run: |
269
+ SCORE="$\{\{ steps.scan.outputs.score \}\}"
270
+ if [ -z "$SCORE" ] || [ "$SCORE" -lt 70 ]; then
271
+ echo "Score $SCORE is below required 70. Failing."
272
+ exit 1
273
+ fi
274
+ `;
275
+ function initWorkflow(cwd) {
276
+ const dir = path.join(cwd, ".github", "workflows");
277
+ const file = path.join(dir, "frontend-guardian.yml");
278
+ if (fs.existsSync(file)) {
279
+ console.error("Already exists:", file);
280
+ process.exit(1);
281
+ }
282
+ fs.mkdirSync(dir, { recursive: true });
283
+ fs.writeFileSync(file, WORKFLOW_YAML, "utf-8");
284
+ console.log("Created:", file);
285
+ console.log("Commit and push to enable the check on push/PR.");
286
+ }
223
287
  function parseArgs() {
224
288
  const argv = process.argv.slice(2);
225
289
  const pathArg = argv[0];
@@ -247,9 +311,15 @@ function parseArgs() {
247
311
  return { path: pathArg, json, failOnScore };
248
312
  }
249
313
  async function main() {
314
+ const argv = process.argv.slice(2);
315
+ if (argv[0] === "init") {
316
+ initWorkflow(process.cwd());
317
+ return;
318
+ }
250
319
  const { path: pathArg, json: outputJson, failOnScore } = parseArgs();
251
320
  if (!pathArg) {
252
321
  console.error("Usage: frontend-guardian <path> [options]");
322
+ console.error(" frontend-guardian init # add GitHub Actions workflow");
253
323
  console.error(" npx frontend-guardian .");
254
324
  console.error(" npx frontend-guardian . --fail-on-score 70");
255
325
  console.error(" npx frontend-guardian . --json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-guardian",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Scan frontend projects for Tailwind & component consistency (Phase 1 CLI)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "chalk": "^5.3.0",
15
15
  "ora": "^8.0.1",
16
- "@justinmoto/frontend-guardian-core": "0.1.9"
16
+ "@justinmoto/frontend-guardian-core": "0.1.10"
17
17
  },
18
18
  "devDependencies": {
19
19
  "typescript": "^5"