Skip to content

Commit

Permalink
feat: Add projectgenerator command
Browse files Browse the repository at this point in the history
  • Loading branch information
nandenjin committed Mar 27, 2024
1 parent ba70aa6 commit 01b1af0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
11 changes: 8 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ inputs:
command:
description: 'Command to run'
required: true
version:
ofVersion:
description: 'openFrameworks version'
default: '0.12.1'
root:
default: '0.12.0'
ofRoot:
description: 'openFrameworks root directory'
default: '.'
projectGeneratorDir:
description: 'Path for ProjectGenerator directory'
projectRoot:
description: 'Project root directory'

runs:
using: 'node20'
main: 'dist/index.js'
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.4.0",
"@actions/io": "^1.1.3",
"@actions/tool-cache": "^2.0.1"
Expand Down
47 changes: 47 additions & 0 deletions src/commands/projectgenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { debug, getInput } from '@actions/core'
import { isLinux, isMacOS, isWindows } from '../util/platform'
import { join, resolve } from 'path'
import { exec } from '@actions/exec'

export default async function main() {
const OF_ROOT = resolve(process.cwd(), getInput('ofRoot', { required: true }))
const PROJECT_GENERATOR_DIR = resolve(
OF_ROOT,
getInput('projectGeneratorDir') || 'projectGenerator'
)
const PROJECT_ROOT = resolve(
process.cwd(),
getInput('projectRoot', { required: true })
)

debug(`OF_ROOT: ${OF_ROOT}`)
debug(`PROJECT_GENERATOR_DIR: ${PROJECT_GENERATOR_DIR}`)
debug(`PROJECT_ROOT: ${PROJECT_ROOT}`)

await exec(
getExecutable(PROJECT_GENERATOR_DIR),
getArgs(OF_ROOT, PROJECT_ROOT)
)
}

function getExecutable(pgDirPath: string) {
if (isWindows) {
return join(pgDirPath, 'projectGenerator.exe')
} else if (isMacOS) {
return join(
pgDirPath,
'projectGenerator.app/Contents/Resources/app/app/projectGenerator'
)
} else if (isLinux) {
return join(pgDirPath, 'projectGenerator')
}
throw new Error('Unsupported platform')
}

function getArgs(ofRoot: string, projectRoot: string) {
if (isWindows) {
return [`/ofPath=` + ofRoot, '/verbose', projectRoot]
} else {
return [`--ofPath=` + ofRoot, '--verbose', projectRoot]
}
}
4 changes: 2 additions & 2 deletions src/commands/setup-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { join, resolve } from 'path'
import { readdir } from 'fs/promises'

export default async function main() {
const OF_ROOT = getInput('root') || process.cwd()
const OF_VERSION = getInput('version') || '0.12.0'
const OF_ROOT = getInput('ofRoot')
const OF_VERSION = getInput('ofVersion')

let platform: string, ext: string

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { getInput, setFailed } from '@actions/core'
import setupOF from './commands/setup-of'
import projectGenerator from './commands/projectgenerator'

const command = getInput('command', { required: true })

switch (command) {
case 'setup-of':
setupOF()
break
case 'projectgenerator':
projectGenerator()
break
default:
setFailed(`Unknown command: ${command}`)
break
Expand Down

0 comments on commit 01b1af0

Please sign in to comment.