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
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"node": true,
"es6": true,
"jest": true
},
"extends": ["eslint:recommended"],
"plugins": ["jest"],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single", { "avoidEscape": true }],
"no-console": "off",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
}
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Tests and Checks

on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- ready_for_review

permissions:
contents: write
pull-requests: write

jobs:
validate:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- task: test
name: Run tests
command: test
- task: lint
name: Lint code
command: lint
- task: pack
name: Compile
command: pack
fail-fast: false
name: ${{ matrix.name }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'

- name: Install dependencies
run: npm install
env:
CI: true

- name: ${{ matrix.name }}
run: npm run ${{ matrix.command }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/.idea/
/node_modules/
/coverage/
# Don't ignore dist folder for GitHub Actions
# /dist/
67 changes: 53 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Generate PHP project classes list file action

GitHub action to generate a file with [PHP](https://php.net) project classes list (works only with [composer](https://getcomposer.org) projects)
GitHub action to generate a file with [PHP](https://php.net) project classes list (works only with [composer](https://getcomposer.org) projects). Built with Node.js 20.

## Usage

Expand All @@ -18,39 +18,78 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkouting project code...
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@master
with:
php-version: 8.1
php-version: 8.4
extensions: curl, gd, pdo_mysql, json, mbstring, pcre, session
ini-values: post_max_size=256M
coverage: none
tools: composer:v2

- name: Install Composer dependencies (with dev)
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

- name: Getting PHP classes list...
uses: impresscms-dev/generate-php-project-classes-list-file-action@v1
uses: impresscms-dev/generate-php-project-classes-list-file-action@v2
with:
output_file: ./php-classes.lst

- uses: actions/upload-artifact@v3
# Optional: specify a different path if composer.json is not in the root
# project_path: ./src

- uses: actions/upload-artifact@v4
with:
name: my-artifact
path: ./php-classes.lst
```

## Arguments
## Arguments

This action supports such arguments (used in `with` keyword):
| Argument | Required | Default value | Description |
|-------------|----------|----------------------|-----------------------------------|
| output_file | Yes | | File where to write classes list |
| Argument | Required | Default value | Description |
|-------------|----------|----------------------|------------------------------------------------------------|
| output_file | Yes | | File where to write classes list |
| project_path | No | . | Path to the directory containing composer.json |

## Development

### Setup

```bash
# Install dependencies
npm install

# Pack the action
npm run pack

# Run tests
npm test

# Lint code (both source and tests)
npm run lint

# Fix lint issues (both source and tests)
npm run lint:fix

# Run all checks (lint, pack, test)
npm run all
```

### Packaging

This action uses [ncc](https://github.com/vercel/ncc) to compile the Node.js code and dependencies into a single file in the `dist/` folder. This allows the action to run quickly and reliably.

After making changes to the code, you should run:

```bash
npm run pack
```

The `dist/` folder should be committed to the repository. This is a requirement for GitHub Actions so that users can run the action without having to build it themselves.

## How to contribute?
## How to contribute?

If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try [interactive GitHub tutorial](https://skills.github.com).

Expand Down
19 changes: 8 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ description: 'GitHub action to generate a file with PHP project classes list (wo
branding:
icon: list
color: blue

inputs:
output_file:
description: File where will be written classes list
required: true
required: true
project_path:
description: Path to the directory containing composer.json (default is current directory)
required: false
default: '.'

runs:
using: 'composite'
steps:
- name: Dumping composer autoloader with optimization...
run: composer dumpautoload --optimize
shell: bash

- name: Generating classes output list file...
run: php ${{ github.action_path }}/bin/run.php "${{ inputs.output_file }}"
shell: bash
using: 'node20'
main: 'dist/index.js'
14 changes: 0 additions & 14 deletions bin/run.php

This file was deleted.

43 changes: 43 additions & 0 deletions build-tools/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as esbuild from 'esbuild';
import ejsPlugin from './esbuild-plugin-ejs.js';
import fs from 'fs';
import path from 'path';

// Ensure dist directory exists
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist');
}

// Copy package.json to dist
fs.writeFileSync(
path.join('dist', 'package.json'),
JSON.stringify({ type: 'module' })
);

// Build the project
try {
const result = await esbuild.build({
entryPoints: ['src/index.js'],
bundle: true,
platform: 'node',
target: 'node16',
outfile: 'dist/index.js',
format: 'esm',
plugins: [ejsPlugin],
minify: true,
sourcemap: true,
metafile: true,
});

console.log('Build completed successfully!');

// Output build size info
const outputSize = fs.statSync('dist/index.js').size;
console.log(`Output size: ${(outputSize / 1024).toFixed(2)} KB`);

// Output metafile for analysis if needed
fs.writeFileSync('dist/meta.json', JSON.stringify(result.metafile));
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
31 changes: 31 additions & 0 deletions build-tools/esbuild-plugin-ejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs';
import path from 'path';

/**
* esbuild plugin to handle .ejs files
* This plugin loads .ejs files as strings
*/
export default {
name: 'ejs',
setup(build) {
// Handle importing .ejs files
build.onResolve({ filter: /\.ejs$/ }, (args) => {
const resolvedPath = path.resolve(args.resolveDir, args.path);

return {
path: resolvedPath,
namespace: 'ejs-raw',
};
});

// Load .ejs files as strings
build.onLoad({ filter: /.*/, namespace: 'ejs-raw' }, async (args) => {
const content = await fs.promises.readFile(args.path, 'utf8');

return {
contents: `export default ${JSON.stringify(content)}`,
loader: 'js',
};
});
},
};
11 changes: 11 additions & 0 deletions build-tools/jest-ejs-transformer.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* A custom Jest transformer for EJS files
* This transformer converts EJS files to JS modules that export the template as a string
*/
module.exports = {
process(sourceText) {
return {
code: `module.exports = ${JSON.stringify(sourceText)};`,
};
},
};
150 changes: 150 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"module"}
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
testEnvironment: 'node',
testMatch: ['**/tests/**/*.test.js'],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov'],
verbose: true,
testTimeout: 60000, // 60 seconds timeout for tests
transform: {
'\\.ejs$': '<rootDir>/build-tools/jest-ejs-transformer.cjs'
}
};
Loading