Skip to content

Commit

Permalink
feat: add JSON5 support (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 20, 2022
1 parent 1205112 commit b9ce5d7
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .changes/json5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/action-core": minor
"action": minor
---

Added support to JSON5 on `tauri.conf.json[5]`.
18 changes: 11 additions & 7 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ jobs:
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Updater signature is exposed here to make sure it works in PR's
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
with:
projectPath: ./packages/action/__fixtures__/example
iconPath: ./icon.png
tagName: example-v__VERSION__
releaseName: "Release example app v__VERSION__"
projectPath: ./packages/action/__fixtures__/example-with-tauri
tagName: example-with-tauri-v__VERSION__
releaseName: "Release example with preconfigured Tauri app v__VERSION__"
releaseBody: "See the assets to download this version and install."
releaseDraft: true
prerelease: false
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Updater signature is exposed here to make sure it works in PR's
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
with:
projectPath: ./packages/action/__fixtures__/example-with-tauri
tagName: example-with-tauri-v__VERSION__
releaseName: "Release example with preconfigured Tauri app v__VERSION__"
projectPath: ./packages/action/__fixtures__/example
# iconPath: ./icon.png
tagName: example-v__VERSION__
releaseName: "Release example app v__VERSION__"
releaseBody: "See the assets to download this version and install."
releaseDraft: true
prerelease: false
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
}
},
"updater": {
"active": true
"active": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDE5QzMxNjYwNTM5OEUwNTgKUldSWTRKaFRZQmJER1h4d1ZMYVA3dnluSjdpN2RmMldJR09hUFFlZDY0SlFqckkvRUJhZDJVZXAK"
},
"allowlist": {
"all": true
Expand Down
1 change: 0 additions & 1 deletion packages/action/__fixtures__/example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
src-tauri
dist/index.tauri.html
6 changes: 3 additions & 3 deletions packages/action/dist/index.js

Large diffs are not rendered by default.

38 changes: 32 additions & 6 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { execa } from 'execa'
import { parse as parseToml } from '@iarna/toml'
import { join, resolve, normalize, sep } from 'path'
import glob from 'glob'
import JSON5 from 'json5'

export function getPackageJson(root: string): any {
const packageJsonPath = join(root, 'package.json')
Expand Down Expand Up @@ -138,15 +139,42 @@ interface Info {
version: string
wixLanguage: string | string[] | { [language: string]: unknown }
}

function _getJson5Config(contents: string): TauriConfig | null {
try {
const config = JSON5.parse(contents) as TauriConfig
return config
} catch (e) {
return null
}
}

function getConfig(path: string): TauriConfig {
const contents = readFileSync(path).toString()
try {
const config = JSON.parse(contents) as TauriConfig;
return config
} catch (e) {
let json5Conf = _getJson5Config(contents)
if (json5Conf === null) {
json5Conf = _getJson5Config(
readFileSync(join(path, "..", "tauri.conf.json5")).toString()
)
}
if (json5Conf) {
return json5Conf
}
throw e
}
}

export function getInfo(root: string): Info {
const configPath = join(root, 'src-tauri/tauri.conf.json')
if (existsSync(configPath)) {
let name
let version
let wixLanguage: string | string[] | { [language: string]: unknown } = 'en-US'
const config = JSON.parse(
readFileSync(configPath).toString()
) as TauriConfig
const config = getConfig(configPath)
if (config.package) {
name = config.package.productName
version = config.package.version
Expand Down Expand Up @@ -224,9 +252,7 @@ export async function buildProject(
return execCommand(runner.runnerCommand, [...runner.runnerArgs, 'init', '--ci', '--app-name', info.name], {
cwd: root
}).then(() => {
const config = JSON.parse(
readFileSync(configPath).toString()
) as TauriConfig
const config = getConfig(configPath)

console.log(
`Replacing tauri.conf.json config - package.version=${info.version}`
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@iarna/toml": "2.2.5",
"execa": "6.1.0",
"glob": "^7.2.0",
"json5": "^2.2.0",
"tslib": "2.3.1"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,13 @@ js-yaml@^4.0.0:
dependencies:
argparse "^2.0.1"

json5@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
dependencies:
minimist "^1.2.5"

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
Expand Down

0 comments on commit b9ce5d7

Please sign in to comment.