Skip to content

Commit fcd9334

Browse files
committed
refactor: Move package.json, minify.js, and version.js to scripts/
- Move package.json and package-lock.json to scripts/ - Move minify.js to scripts/ - Move version.js to scripts/ - Update all script references to use correct paths - Update GitHub Actions workflows to use scripts/ directory - Root directory now only contains: phantom.js, phantom.test.js, LICENSE, README.md
1 parent 98d4287 commit fcd9334

10 files changed

Lines changed: 26 additions & 14 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches:
66
- main
77
paths:
8-
- 'package.json'
8+
- 'scripts/package.json'
99
- 'phantom.js'
1010

1111
jobs:
@@ -30,12 +30,13 @@ jobs:
3030
cache: 'npm'
3131

3232
- name: Install dependencies
33+
working-directory: ./scripts
3334
run: npm ci
3435

3536
- name: Get version from package.json
3637
id: version
3738
run: |
38-
VERSION=$(node -p "require('./package.json').version")
39+
VERSION=$(node -p "require('./scripts/package.json').version")
3940
echo "version=$VERSION" >> $GITHUB_OUTPUT
4041
echo "📦 Detected version: $VERSION"
4142

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ jobs:
2828
cache: 'npm'
2929

3030
- name: Install dependencies
31+
working-directory: ./scripts
3132
run: npm ci
3233

3334
- name: Check test coverage for new functions
3435
if: github.event_name == 'pull_request'
36+
working-directory: ./scripts
3537
run: |
3638
echo "🔍 Checking if new functions have test coverage..."
3739
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} || true
@@ -40,6 +42,7 @@ jobs:
4042
npm run test:check-diff || npm run test:check
4143
4244
- name: Run tests
45+
working-directory: ./scripts
4346
run: npm test
4447

4548
- name: Test Results Summary

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
cache: 'npm'
2727

2828
- name: Install dependencies
29+
working-directory: ./scripts
2930
run: npm ci
3031

3132
- name: Extract version from tag
@@ -38,9 +39,11 @@ jobs:
3839
echo "🏷️ Tag: v$VERSION"
3940
4041
- name: Generate minified file
42+
working-directory: ./scripts
4143
run: npm run minify
4244

4345
- name: Create release package
46+
working-directory: ./scripts
4447
run: npm run release
4548

4649
- name: Get release notes

.github/workflows/test-coverage-check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ jobs:
2626
cache: 'npm'
2727

2828
- name: Install dependencies
29+
working-directory: ./scripts
2930
run: npm ci
3031

3132
- name: Check test coverage for new functions
33+
working-directory: ./scripts
3234
run: |
3335
echo "🔍 Checking for new functions and their test coverage..."
3436
# Fetch the base branch
@@ -45,5 +47,6 @@ jobs:
4547
}
4648
4749
- name: Run existing tests
50+
working-directory: ./scripts
4851
run: npm test
4952

scripts/create-release.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getVersion() {
1818
}
1919

2020
// Get from package.json
21-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
21+
const packageJsonPath = path.join(__dirname, 'package.json');
2222
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
2323
return packageJson.version;
2424
}

minify.js renamed to scripts/minify.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env node
22

33
const fs = require('fs');
4+
const path = require('path');
45
const UglifyJS = require('uglify-js');
56

6-
const sourceCode = fs.readFileSync('phantom.js', 'utf8');
7+
const sourceCode = fs.readFileSync(path.join(__dirname, '..', 'phantom.js'), 'utf8');
78

89
// Remove the header comment and extract just the code
910
const codeStart = sourceCode.indexOf('(function (global)');
@@ -29,15 +30,16 @@ if (result.error) {
2930
}
3031

3132
// Read version from package.json
32-
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
33+
const packageJsonPath = path.join(__dirname, 'package.json');
34+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
3335
const version = packageJson.version;
3436

3537
// Add banner with version (uppercase BETA for consistency)
3638
const versionBanner = version.replace(/-beta$/i, '-BETA');
3739
const banner = `/*! Phantom.js v${versionBanner} - a product by David Labs */\n`;
3840
const minified = banner + result.code;
3941

40-
fs.writeFileSync('phantom.min.js', minified, 'utf8');
42+
fs.writeFileSync(path.join(__dirname, '..', 'phantom.min.js'), minified, 'utf8');
4143
console.log('Minified file created: phantom.min.js');
4244
console.log('Original size:', sourceCode.length, 'bytes');
4345
console.log('Minified size:', minified.length, 'bytes');

package.json renamed to scripts/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"test": "jest",
88
"test:watch": "jest --watch",
99
"test:coverage": "jest --coverage",
10-
"test:check": "node scripts/check-test-coverage.js --strict",
11-
"test:check-diff": "node scripts/check-test-coverage.js --strict --diff",
10+
"test:check": "node check-test-coverage.js --strict",
11+
"test:check-diff": "node check-test-coverage.js --strict --diff",
1212
"minify": "node minify.js",
13-
"release": "node scripts/create-release.js",
14-
"release:prepare": "node scripts/prepare-release.js"
13+
"release": "node create-release.js",
14+
"release:prepare": "node prepare-release.js"
1515
},
1616
"keywords": [
1717
"oie",
@@ -31,14 +31,14 @@
3131
"**/*.test.js"
3232
],
3333
"collectCoverageFrom": [
34-
"phantom.js"
34+
"../phantom.js"
3535
],
3636
"coveragePathIgnorePatterns": [
3737
"/node_modules/"
3838
],
3939
"reporters": [
4040
"default",
41-
"<rootDir>/test-summary-reporter.js"
41+
"<rootDir>/../test-summary-reporter.js"
4242
]
4343
}
4444
}

scripts/prepare-release.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function exec(command, options = {}) {
3939
}
4040

4141
// Get version from package.json
42-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
42+
const packageJsonPath = path.join(__dirname, 'package.json');
4343
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
4444
const version = packageJson.version;
4545
const tagName = `v${version}`;

version.js renamed to scripts/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ packageJson.version = newVersion;
6767
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8');
6868

6969
// Update phantom.js
70-
const phantomJsPath = path.join(__dirname, 'phantom.js');
70+
const phantomJsPath = path.join(__dirname, '..', 'phantom.js');
7171
updateVersionInFile(phantomJsPath, currentVersion, newVersion);
7272

7373
console.log(`Version updated to ${newVersion} in package.json and phantom.js`);

0 commit comments

Comments
 (0)