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
3 changes: 3 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
npm install
npm update
npm run dist:linux64
node ../scripts/test_asar_package.cjs dist/linux-unpacked/resources
cd dist
pwd
ls
Expand Down Expand Up @@ -187,6 +188,7 @@ jobs:
npm install
npm update
npm run dist:linux64
node ../scripts/test_asar_package.cjs dist/linux-unpacked/resources

- name: Copy GUI tarball to root directory
run: |
Expand Down Expand Up @@ -271,6 +273,7 @@ jobs:
npm install
npm update
npm run dist:linux:arm64
node ../scripts/test_asar_package.cjs dist/linux-arm64-unpacked/resources

- name: Copy GUI tarball to root directory
run: |
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build-vs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ jobs:
shell: pwsh
run: node --test ../openFrameworks/apps/projectGenerator/scripts/test_gui_project_settings.cjs

- name: Test packaged executable paths and writable settings
shell: pwsh
run: node --test ../openFrameworks/apps/projectGenerator/scripts/test_packaged_paths.cjs

- name: Build emptyExample and allAddonsExample
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
shell: bash
Expand All @@ -100,6 +104,7 @@ jobs:
npm install
npm update
npm run dist:win64
node ../scripts/test_asar_package.cjs dist/win-unpacked/resources
cd dist
pwd
ls
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/release-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Release version policy

on:
pull_request:

permissions:
contents: read

jobs:
release-versions:
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
- name: Check GUI and command-line versions
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: python3 scripts/check_release_versions.py "$BASE_SHA"
18 changes: 18 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Repository instructions

## Attribution

Do not add assistant attribution to commits, pull requests, issues or comments.

## Release versions

Whenever the GUI version in `frontend/package.json` increases, also increase the
command-line version in `commandLine/src/defines.h`, including GUI-only,
packaging and dependency releases. Both versions must advance relative to the
PR's base branch; their numbers do not need to match. A CLI-only release does not
require a GUI version bump.

Keep both root version fields in `frontend/npm-shrinkwrap.json` equal to the GUI
version, and state both GUI and CLI versions in the PR description. Run
`python3 scripts/check_release_versions.py <base-ref>` before pushing a version
change. See the release version policy in `README.md`.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ projectGenerator\scripts\osx\setup_environment.sh (first time)

## Contributing

### Release version policy

Every GUI version bump must also bump the command-line version, including releases
that change only GUI code, packaging or dependencies. Update `frontend/package.json`,
both root version fields in `frontend/npm-shrinkwrap.json`, and
`commandLine/src/defines.h`. GUI and CLI versions are numbered independently;
both must increase relative to the PR's base branch. A CLI-only release can keep
the GUI version unchanged. Include both versions in the PR description.
CI checks this policy with `python3 scripts/check_release_versions.py <base-ref>`.

The project generator is available in two flavors:

- A command line utility tool. This option is the most versatile and provides all features.
Expand Down
2 changes: 1 addition & 1 deletion commandLine/src/defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define OFPROJECTGENERATOR_MAJOR_VERSION "0"
#define OFPROJECTGENERATOR_MINOR_VERSION "125"
#define OFPROJECTGENERATOR_MINOR_VERSION "126"
#define OFPROJECTGENERATOR_PATCH_VERSION "0"

#define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION)
Expand Down
15 changes: 6 additions & 9 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const process = require('process');
const os = require("os");
const { execFile, spawn } = require('child_process');
const { readProjectSettings } = require('./project-settings');
const { bundledGeneratorPath, settingsStore } = require('./packaged-paths');

const {
app,
Expand Down Expand Up @@ -204,9 +205,9 @@ console.log(`Detected platform: ${platformId}`);
console.log(`Default template: ${defaultTemplate}`);


const savedSettings = settingsStore(__dirname, app.getPath('userData'), app.isPackaged);
try {
const settingsJsonString = fs.readFileSync(path.resolve(__dirname, 'settings.json'), 'utf-8');
settings = JSON.parse(settingsJsonString);
settings = savedSettings.read();
console.log(settings);

// older settings stored the template label (has spaces) instead of the platform id
Expand Down Expand Up @@ -1157,14 +1158,10 @@ ipcMain.on('getRandomSketchName', (event, projectPath) => {
function getPgPath() {
let pgApp = "";
try {
if (hostplatform == "linux" || hostplatform == "linux64") { // ???: when appear there linux64?
if (!app.isPackaged && (hostplatform == "linux" || hostplatform == "linux64")) {
pgApp = path.join(defaultOfPath, "apps/projectGenerator/commandLine/bin/projectGenerator");
} else {
pgApp = path.normalize(path.join(__dirname, "app", "projectGenerator"));
}

if (hostplatform == "windows") {
pgApp += ".exe";
pgApp = bundledGeneratorPath(__dirname);
}
} catch (error) {
console.error("Error determining project generator path:", error);
Expand Down Expand Up @@ -2465,7 +2462,7 @@ ipcMain.on('saveDefaultSettings', (event, defaultSettings) => {
// fs.writeFile is async and would resolve after that, so a quit right after e.g.
// picking a new OF path could race past the actual disk write and lose it (#602)
try {
fs.writeFileSync(path.resolve(__dirname, 'settings.json'), defaultSettings);
savedSettings.write(defaultSettings);
event.returnValue = "Updated default settings for the PG. (written to settings.json)";
} catch (err) {
event.returnValue = "Unable to save defaultSettings to settings.json... (Error=" + err.code + ")";
Expand Down
4 changes: 2 additions & 2 deletions frontend/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "projectGenerator",
"productName": "projectGenerator",
"version": "0.120.0",
"version": "0.121.0",
"description": "Build electron GUI openFrameworks projectGenerator",
"license": "MIT",
"main": "index.js",
Expand All @@ -25,7 +25,7 @@
"dist:linux": "electron-builder --linux --publish never",
"dist:linux64": "electron-builder --linux --x64 --publish never",
"dist:linux:arm64": "electron-builder --linux --arm64 --publish never",
"build:linux64": "electron-packager . $npm_package_productName --icon=static/icon/of.icns --out=dist --ignore='dist' --ignore='readme.md' --prune --overwrite --electron-version=45.2.3 --platform=linux --arch=x64"
"build:linux64": "electron-packager . $npm_package_productName --icon=static/icon/of.icns --out=dist --ignore='dist' --ignore='readme.md' --prune --overwrite --electron-version=45.2.3 --asar.unpack='app/**/*' --platform=linux --arch=x64"
},
"build": {
"appId": "cc.openframeworks.projectGenerator",
Expand All @@ -43,8 +43,8 @@
"arm64"
]
},
"mergeASARs": false,
"x64ArchFiles": "Contents/Resources/app/app/projectGenerator"
"mergeASARs": true,
"x64ArchFiles": "Contents/Resources/app.asar.unpacked/app/projectGenerator"
},
"win": {
"icon": "static/icon/of.ico",
Expand All @@ -65,6 +65,7 @@
"app/**/*",
"static/**/*",
"index.js",
"packaged-paths.js",
"app.js",
"project-settings.js",
"preload.js",
Expand All @@ -82,7 +83,8 @@
]
}
],
"asar": false
"asar": true,
"asarUnpack": ["app/**/*"]
},
"keywords": [
"electron-app"
Expand Down
32 changes: 32 additions & 0 deletions frontend/packaged-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('node:fs');
const path = require('node:path');

function bundledGeneratorPath(appDirectory, platform = process.platform) {
const directory = path.basename(appDirectory) === 'app.asar' ? appDirectory + '.unpacked' : appDirectory;
return path.join(directory, 'app', platform === 'win32' ? 'projectGenerator.exe' : 'projectGenerator');
}

function settingsStore(appDirectory, userDataDirectory, packaged) {
const filename = path.join(packaged ? userDataDirectory : appDirectory, 'settings.json');
const candidates = [filename];
if (packaged) {
candidates.push(path.join(appDirectory, 'settings.json'));
if (path.basename(appDirectory) === 'app.asar') candidates.push(path.join(path.dirname(appDirectory), 'app', 'settings.json'));
}
return {
filename,
read() {
for (const file of candidates) {
try { return JSON.parse(fs.readFileSync(file, 'utf8')); }
catch (error) { if (error.code !== 'ENOENT') throw error; }
}
throw Object.assign(new Error('No saved settings'), { code: 'ENOENT' });
},
write(contents) {
fs.mkdirSync(path.dirname(filename), { recursive: true });
fs.writeFileSync(filename, contents);
},
};
}

module.exports = { bundledGeneratorPath, settingsStore };
1 change: 1 addition & 0 deletions frontend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ npm update

### Debugging
You can open `settings.json` to enable some hidden settings, useful for debugging.
Packaged apps save it in Electron's user data directory: `~/Library/Application Support/projectGenerator` on macOS, `%APPDATA%/projectGenerator` on Windows, or `$XDG_CONFIG_HOME/projectGenerator` (usually `~/.config/projectGenerator`) on Linux. Development runs continue to use `frontend/settings.json`.
Moreover, Electron uses Webkit so all the Webkit developper tools are available to you. ( `Cmd/Ctrl` + `Shift` + `i` from the Electron window.)

- Console messages from `index.js` show up in the terminal (where you did `npm start`).
Expand Down
56 changes: 56 additions & 0 deletions scripts/check_release_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""Require a CLI version bump whenever a PR increases the GUI version."""
import argparse
import json
import pathlib
import re
import subprocess


def version(value):
if not isinstance(value, str) or not re.fullmatch(r"\d+\.\d+\.\d+", value):
raise ValueError(f"expected a major.minor.patch version, got {value!r}")
return tuple(int(part) for part in value.split("."))


def cli_version(contents):
parts = []
for part in ("MAJOR", "MINOR", "PATCH"):
match = re.search(r'^#define\s+OFPROJECTGENERATOR_' + part + r'_VERSION\s+"(\d+)"\s*$', contents, re.MULTILINE)
if not match:
raise ValueError(f"missing command-line {part} version")
parts.append(int(match[1]))
return tuple(parts)


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("base", help="PR base commit or branch, for example upstream/master")
args = parser.parse_args()
root = pathlib.Path(subprocess.check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip())

def previous(file):
return subprocess.check_output(["git", "show", f"{args.base}:{file}"], cwd=root, text=True)

package = json.loads((root / "frontend/package.json").read_text())
lock = json.loads((root / "frontend/npm-shrinkwrap.json").read_text())
gui = version(package["version"])
cli = cli_version((root / "commandLine/src/defines.h").read_text())
old_gui = version(json.loads(previous("frontend/package.json"))["version"])
old_cli = cli_version(previous("commandLine/src/defines.h"))

if lock["version"] != package["version"] or lock["packages"][""]["version"] != package["version"]:
raise ValueError("both npm-shrinkwrap.json root versions must match frontend/package.json")
if gui < old_gui or cli < old_cli:
raise ValueError("GUI and command-line versions must not decrease relative to the base")
if gui > old_gui and cli <= old_cli:
raise ValueError("a GUI version bump also requires a command-line version bump in commandLine/src/defines.h")

print(f"Release versions OK: GUI {'.'.join(map(str, gui))}, CLI {'.'.join(map(str, cli))}")


if __name__ == "__main__":
try:
main()
except (ValueError, KeyError, subprocess.CalledProcessError) as error:
raise SystemExit(f"Release version check failed: {error}")
3 changes: 3 additions & 0 deletions scripts/linux/test_cmdline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ python3 "${CURRENT_DIR}/../test_xcode_settings.py" ./projectGenerator ../../../.
echo "Test existing-project GUI settings and update arguments"
node --test "${CURRENT_DIR}/../test_gui_project_settings.cjs"

echo "Test packaged executable paths and writable settings"
node --test "${CURRENT_DIR}/../test_packaged_paths.cjs"

echo "Successful projectGenerator tests for [linux64]";
8 changes: 5 additions & 3 deletions scripts/osx/ci_build_pg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ package_app(){
echo "-------------"
echo "Copy cmdline PG from app contents (signed)"
SOURCE_FILE="commandLine/bin/commandLine.app/Contents/MacOS/commandLine"
DEST_FILE="projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/app/projectGenerator"
DEST_FILE="projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app.asar.unpacked/app/projectGenerator"

# Check if source file exists
if [ ! -f "$SOURCE_FILE" ]; then
Expand All @@ -75,7 +75,7 @@ package_app(){
# Check destination directory exists; if not, print error
if [ ! -d "$(dirname "$DEST_FILE")" ]; then
echo "Error: Destination directory does not exist: $(dirname "$DEST_FILE")"
ls -lah projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/app/
ls -lah projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app.asar.unpacked/app/
exit 12
fi

Expand All @@ -96,6 +96,8 @@ package_app(){
exit 13
fi

node "${PG_DIR}/scripts/test_asar_package.cjs" "${PG_DIR}/projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources"

cd ${PG_DIR}
echo "Current directory: (should be projectGenerator) $(pwd)"
echo "Directory contents:"
Expand Down Expand Up @@ -146,7 +148,7 @@ sign_and_upload(){
PLATFORM=$1
# Copy commandLine into electron .app
cd ${PG_DIR}
cp commandLine/bin/projectGenerator projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/app/projectGenerator 2> /dev/null
cp commandLine/bin/projectGenerator projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app.asar.unpacked/app/projectGenerator 2> /dev/null

# sed -i -e "s/osx/$PLATFORM/g" projectGenerator-$PLATFORM/projectGenerator.app/Contents/Resources/app/settings.json

Expand Down
3 changes: 3 additions & 0 deletions scripts/osx/test_cmdline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ python3 "${CURRENT_DIR}/../test_xcode_settings.py" ./projectGenerator "${PG_DIR}
echo "Test 6: existing-project GUI settings and update arguments"
node --test "${CURRENT_DIR}/../test_gui_project_settings.cjs" || exit 1

echo "Test packaged executable paths and writable settings"
node --test "${CURRENT_DIR}/../test_packaged_paths.cjs" || exit 1

# echo "test out of folder -o [vs]";
# rm -rf ../../../../../pg2
# mkdir -p ../../../../../pg2
Expand Down
30 changes: 30 additions & 0 deletions scripts/test_asar_package.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Run after packaging, on the same host platform/architecture as the bundled generator:
// node scripts/test_asar_package.cjs /path/to/app/resources
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { pathToFileURL } = require('node:url');
const { spawnSync } = require('node:child_process');
const { bundledGeneratorPath } = require('../frontend/packaged-paths');

async function main() {
assert.ok(process.argv[2], 'Pass the packaged app resources directory');
const archive = path.resolve(process.argv[2], 'app.asar');
const asar = await import(pathToFileURL(require.resolve('@electron/asar', { paths: [path.join(__dirname, '../frontend')] })).href);
for (const file of ['index.html', 'index.js', 'app.js', 'preload.js', 'packaged-paths.js', 'locales/en.json']) {
assert.ok(asar.extractFile(archive, file).length, `Missing ${file}`);
assert.ok(!asar.statFile(archive, file).unpacked, `${file} should be packed`);
}
assert.equal(asar.extractFile(archive, 'packaged-paths.js').toString(), fs.readFileSync(path.join(__dirname, '../frontend/packaged-paths.js'), 'utf8'));
const generator = bundledGeneratorPath(archive);
const relative = 'app/' + path.basename(generator);
assert.equal(asar.statFile(archive, relative).unpacked, true, 'Native generator must be unpacked');
const result = spawnSync(generator, ['--version'], { encoding: 'utf8', timeout: 30000, env: { ...process.env, TZ: 'UTC0' } });
if (result.error) throw result.error;
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.match(result.stdout, /version/);
console.log('ASAR assets, unpacked native generator and spawn --version passed');
console.log(result.stdout.trim());
}

main().catch((error) => { console.error(error); process.exitCode = 1; });
Loading
Loading