Skip to content

Commit 58d1008

Browse files
authored
Merge pull request #23 from MekDrop/feature/add-path-parameter
Add project_path parameter + rewritten with JS
2 parents 8bb0e02 + a4a46c2 commit 58d1008

27 files changed

+6407
-70
lines changed

.eslintrc.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"es6": true,
5+
"jest": true
6+
},
7+
"extends": ["eslint:recommended"],
8+
"plugins": ["jest"],
9+
"parserOptions": {
10+
"ecmaVersion": 2022,
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
"semi": ["error", "always"],
15+
"quotes": ["error", "single", { "avoidEscape": true }],
16+
"no-console": "off",
17+
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
18+
"jest/no-disabled-tests": "warn",
19+
"jest/no-focused-tests": "error",
20+
"jest/no-identical-title": "error",
21+
"jest/prefer-to-have-length": "warn",
22+
"jest/valid-expect": "error"
23+
}
24+
}

.github/workflows/test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests and Checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
- ready_for_review
12+
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
17+
jobs:
18+
validate:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
include:
23+
- task: test
24+
name: Run tests
25+
command: test
26+
- task: lint
27+
name: Lint code
28+
command: lint
29+
- task: pack
30+
name: Compile
31+
command: pack
32+
fail-fast: false
33+
name: ${{ matrix.name }}
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: 20.x
42+
cache: 'npm'
43+
44+
- name: Install dependencies
45+
run: npm install
46+
env:
47+
CI: true
48+
49+
- name: ${{ matrix.name }}
50+
run: npm run ${{ matrix.command }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
/.idea/
2+
/node_modules/
3+
/coverage/
4+
# Don't ignore dist folder for GitHub Actions
5+
# /dist/

README.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Generate PHP project classes list file action
44

5-
GitHub action to generate a file with [PHP](https://php.net) project classes list (works only with [composer](https://getcomposer.org) projects)
5+
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.
66

77
## Usage
88

@@ -18,39 +18,78 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkouting project code...
21-
uses: actions/checkout@v2
22-
21+
uses: actions/checkout@v4
22+
2323
- name: Install PHP
2424
uses: shivammathur/setup-php@master
2525
with:
26-
php-version: 8.1
26+
php-version: 8.4
2727
extensions: curl, gd, pdo_mysql, json, mbstring, pcre, session
2828
ini-values: post_max_size=256M
2929
coverage: none
3030
tools: composer:v2
31-
31+
3232
- name: Install Composer dependencies (with dev)
3333
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
34-
34+
3535
- name: Getting PHP classes list...
36-
uses: impresscms-dev/generate-php-project-classes-list-file-action@v1
36+
uses: impresscms-dev/generate-php-project-classes-list-file-action@v2
3737
with:
3838
output_file: ./php-classes.lst
39-
40-
- uses: actions/upload-artifact@v3
39+
# Optional: specify a different path if composer.json is not in the root
40+
# project_path: ./src
41+
42+
- uses: actions/upload-artifact@v4
4143
with:
4244
name: my-artifact
4345
path: ./php-classes.lst
4446
```
4547
46-
## Arguments
48+
## Arguments
4749
4850
This action supports such arguments (used in `with` keyword):
49-
| Argument | Required | Default value | Description |
50-
|-------------|----------|----------------------|-----------------------------------|
51-
| output_file | Yes | | File where to write classes list |
51+
| Argument | Required | Default value | Description |
52+
|-------------|----------|----------------------|------------------------------------------------------------|
53+
| output_file | Yes | | File where to write classes list |
54+
| project_path | No | . | Path to the directory containing composer.json |
55+
56+
## Development
57+
58+
### Setup
59+
60+
```bash
61+
# Install dependencies
62+
npm install
63+
64+
# Pack the action
65+
npm run pack
66+
67+
# Run tests
68+
npm test
69+
70+
# Lint code (both source and tests)
71+
npm run lint
72+
73+
# Fix lint issues (both source and tests)
74+
npm run lint:fix
75+
76+
# Run all checks (lint, pack, test)
77+
npm run all
78+
```
79+
80+
### Packaging
81+
82+
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.
83+
84+
After making changes to the code, you should run:
85+
86+
```bash
87+
npm run pack
88+
```
89+
90+
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.
5291

53-
## How to contribute?
92+
## How to contribute?
5493

5594
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).
5695

action.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ description: 'GitHub action to generate a file with PHP project classes list (wo
44
branding:
55
icon: list
66
color: blue
7-
7+
88
inputs:
99
output_file:
1010
description: File where will be written classes list
11-
required: true
11+
required: true
12+
project_path:
13+
description: Path to the directory containing composer.json (default is current directory)
14+
required: false
15+
default: '.'
1216

1317
runs:
14-
using: 'composite'
15-
steps:
16-
- name: Dumping composer autoloader with optimization...
17-
run: composer dumpautoload --optimize
18-
shell: bash
19-
20-
- name: Generating classes output list file...
21-
run: php ${{ github.action_path }}/bin/run.php "${{ inputs.output_file }}"
22-
shell: bash
18+
using: 'node20'
19+
main: 'dist/index.js'

bin/run.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

build-tools/build.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as esbuild from 'esbuild';
2+
import ejsPlugin from './esbuild-plugin-ejs.js';
3+
import fs from 'fs';
4+
import path from 'path';
5+
6+
// Ensure dist directory exists
7+
if (!fs.existsSync('dist')) {
8+
fs.mkdirSync('dist');
9+
}
10+
11+
// Copy package.json to dist
12+
fs.writeFileSync(
13+
path.join('dist', 'package.json'),
14+
JSON.stringify({ type: 'module' })
15+
);
16+
17+
// Build the project
18+
try {
19+
const result = await esbuild.build({
20+
entryPoints: ['src/index.js'],
21+
bundle: true,
22+
platform: 'node',
23+
target: 'node16',
24+
outfile: 'dist/index.js',
25+
format: 'esm',
26+
plugins: [ejsPlugin],
27+
minify: true,
28+
sourcemap: true,
29+
metafile: true,
30+
});
31+
32+
console.log('Build completed successfully!');
33+
34+
// Output build size info
35+
const outputSize = fs.statSync('dist/index.js').size;
36+
console.log(`Output size: ${(outputSize / 1024).toFixed(2)} KB`);
37+
38+
// Output metafile for analysis if needed
39+
fs.writeFileSync('dist/meta.json', JSON.stringify(result.metafile));
40+
} catch (error) {
41+
console.error('Build failed:', error);
42+
process.exit(1);
43+
}

build-tools/esbuild-plugin-ejs.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
/**
5+
* esbuild plugin to handle .ejs files
6+
* This plugin loads .ejs files as strings
7+
*/
8+
export default {
9+
name: 'ejs',
10+
setup(build) {
11+
// Handle importing .ejs files
12+
build.onResolve({ filter: /\.ejs$/ }, (args) => {
13+
const resolvedPath = path.resolve(args.resolveDir, args.path);
14+
15+
return {
16+
path: resolvedPath,
17+
namespace: 'ejs-raw',
18+
};
19+
});
20+
21+
// Load .ejs files as strings
22+
build.onLoad({ filter: /.*/, namespace: 'ejs-raw' }, async (args) => {
23+
const content = await fs.promises.readFile(args.path, 'utf8');
24+
25+
return {
26+
contents: `export default ${JSON.stringify(content)}`,
27+
loader: 'js',
28+
};
29+
});
30+
},
31+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* A custom Jest transformer for EJS files
3+
* This transformer converts EJS files to JS modules that export the template as a string
4+
*/
5+
module.exports = {
6+
process(sourceText) {
7+
return {
8+
code: `module.exports = ${JSON.stringify(sourceText)};`,
9+
};
10+
},
11+
};

dist/index.js

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

0 commit comments

Comments
 (0)