Skip to content

Commit f69d202

Browse files
committed
fix: rename .app-update.json to app-update.yml #529
JSON is not readable and writable. YAML is much better.
1 parent 3eb2752 commit f69d202

File tree

10 files changed

+623
-311
lines changed

10 files changed

+623
-311
lines changed

nsis-auto-updater/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-auto-updater",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"description": "NSIS Auto Updater",
55
"main": "out/nsis-auto-updater/src/main.js",
66
"author": "Vladimir Krivosheev",
@@ -15,6 +15,7 @@
1515
"bluebird": "^3.4.6",
1616
"fs-extra-p": "^1.2.0",
1717
"ini": "^1.3.4",
18+
"js-yaml": "^3.6.1",
1819
"semver": "^5.3.0",
1920
"source-map-support": "^0.4.5",
2021
"tunnel-agent": "^0.4.3"

nsis-auto-updater/src/NsisUpdater.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { Provider, UpdateCheckResult } from "./api"
88
import { BintrayProvider } from "./BintrayProvider"
99
import BluebirdPromise from "bluebird"
1010
import { BintrayOptions, PublishConfiguration, GithubOptions } from "../../src/options/publishOptions"
11-
import { readJson } from "fs-extra-p"
11+
import { readFile } from "fs-extra-p"
12+
import { safeLoad } from "js-yaml"
1213

1314
BluebirdPromise.config({
1415
longStackTraces: true,
@@ -146,6 +147,6 @@ function createClient(data: string | PublishConfiguration | BintrayOptions | Git
146147
}
147148

148149
async function loadUpdateConfig() {
149-
const data = await readJson(path.join((<any>global).__test_resourcesPath || (<any>process).resourcesPath, ".app-update.json"), "utf-8")
150+
const data = safeLoad(await readFile(path.join((<any>global).__test_resourcesPath || (<any>process).resourcesPath, "app-update.yml"), "utf-8"))
150151
return createClient(data)
151152
}

nsis-auto-updater/yarn.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
22
# yarn lockfile v1
3+
argparse@^1.0.7:
4+
version "1.0.9"
5+
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86"
6+
dependencies:
7+
sprintf-js "~1.0.2"
8+
39
balanced-match@^0.4.1:
410
version "0.4.2"
511
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
@@ -19,6 +25,10 @@ concat-map@0.0.1:
1925
version "0.0.1"
2026
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
2127

28+
esprima@^2.6.0:
29+
version "2.7.3"
30+
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
31+
2232
fs-extra-p@^1.2.0:
2333
version "1.2.0"
2434
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-1.2.0.tgz#16abed58ec63219cf9244a5a54ba200d4864b347"
@@ -70,6 +80,13 @@ ini@^1.3.4:
7080
version "1.3.4"
7181
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"
7282

83+
js-yaml@^3.6.1:
84+
version "3.6.1"
85+
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.6.1.tgz#6e5fe67d8b205ce4d22fad05b7781e8dadcc4b30"
86+
dependencies:
87+
argparse "^1.0.7"
88+
esprima "^2.6.0"
89+
7390
jsonfile@^2.4.0:
7491
version "2.4.0"
7592
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
@@ -116,6 +133,10 @@ source-map@^0.5.3:
116133
version "0.5.6"
117134
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
118135

136+
sprintf-js@~1.0.2:
137+
version "1.0.3"
138+
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
139+
119140
tunnel-agent@^0.4.3:
120141
version "0.4.3"
121142
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb"

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"hosted-git-info": "^2.1.5",
7575
"ini": "^1.3.4",
7676
"isbinaryfile": "^3.0.1",
77+
"js-yaml": "^3.6.1",
7778
"lodash.template": "^4.4.0",
7879
"mime": "^1.3.4",
7980
"minimatch": "^3.0.3",
@@ -93,8 +94,10 @@
9394
"yargs": "^6.3.0"
9495
},
9596
"devDependencies": {
96-
"@develar/semantic-release": "^6.3.7",
97+
"@develar/semantic-release": "^6.3.9",
9798
"@develar/types": "^1.0.1",
99+
"@types/ini": "^1.3.29",
100+
"@types/js-yaml": "^3.5.28",
98101
"@types/source-map-support": "^0.2.28",
99102
"ava-tf": "^0.16.4",
100103
"babel-plugin-array-includes": "^2.0.3",
@@ -110,8 +113,8 @@
110113
"json8": "^0.9.2",
111114
"path-sort": "^0.1.0",
112115
"ts-babel": "^1.1.2",
113-
"tslint": "^3.15.1",
114-
"typescript": "^2.1.0-dev.20161019",
116+
"tslint": "^4.0.0-dev.0",
117+
"typescript": "^2.1.0-dev.20161025",
115118
"validate-commit-msg": "^2.8.2",
116119
"whitespace": "^2.1.0"
117120
},

src/targets/nsis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { v5 as uuid5 } from "uuid-1345"
88
import { normalizeExt, TargetEx, getPublishConfigs, getResolvedPublishConfig } from "../platformPackager"
99
import { archiveApp } from "./archive"
1010
import { subTask, task, log } from "../util/log"
11-
import { unlink, readFile } from "fs-extra-p"
11+
import { unlink, readFile, writeFile } from "fs-extra-p"
1212
import { SemVer } from "semver"
1313
import { NsisOptions } from "../options/winOptions"
14-
import { writeJson } from "fs-extra-p"
1514
import { PublishConfiguration } from "../options/publishOptions"
15+
import { safeDump } from "js-yaml"
1616

1717
const NSIS_VERSION = "3.0.1"
1818
//noinspection SpellCheckingInspection
@@ -54,7 +54,7 @@ export default class NsisTarget extends TargetEx {
5454
private async doBuild(appOutDir: string, arch: Arch) {
5555
const publishConfig = await this.publishConfig
5656
if (publishConfig != null) {
57-
await writeJson(path.join(appOutDir, "resources", ".app-update.json"), publishConfig)
57+
await writeFile(path.join(appOutDir, "resources", "app-update.yml"), safeDump(publishConfig))
5858
}
5959

6060
const packager = this.packager

src/util/httpRequest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as path from "path"
88
import { createHash } from "crypto"
99
import { Transform } from "stream"
1010
import { homedir } from "os"
11+
import { parse as parseIni } from "ini"
1112

1213
const maxRedirects = 10
1314

@@ -146,7 +147,7 @@ async function proxyFromNpm() {
146147
}
147148

148149
try {
149-
const config = require("ini").parse(data)
150+
const config = parseIni(data)
150151
return config["https-proxy"] || config.proxy
151152
}
152153
catch (e) {

test/src/helpers/checkDeps.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const printErrorAndExit = require("../../../out/util/promise").printErrorAndExit
77

88
const knownUnusedDevDependencies = new Set([
99
"@develar/types",
10-
"@types/source-map-support",
1110
"ava-tf",
1211
"decompress-zip",
1312
"diff",
@@ -23,7 +22,7 @@ async function main(): Promise<void> {
2322

2423
console.log(`Checking ${projectDir}`)
2524

26-
const result = await new BluebirdPromise<DepCheckResult>(function (resolve) {
25+
const result = await new BluebirdPromise<DepCheckResult>(function (resolve) {
2726
depCheck(projectDir, {
2827
ignoreDirs: [
2928
"out", "test", "docs", "typings", "docker", "certs", "templates", "nsis-auto-updater", ".idea", ".github",
@@ -35,7 +34,7 @@ async function main(): Promise<void> {
3534
throw new Error(`Unused dependencies: ${JSON.stringify(result.dependencies, null, 2)}`)
3635
}
3736

38-
const unusedDevDependencies = result.devDependencies.filter(it => !knownUnusedDevDependencies.has(it))
37+
const unusedDevDependencies = result.devDependencies.filter(it => !it.startsWith("@types/") && !knownUnusedDevDependencies.has(it))
3938
if (unusedDevDependencies.length > 0) {
4039
throw new Error(`Unused devDependencies: ${JSON.stringify(unusedDevDependencies, null, 2)}`)
4140
}

test/src/nsisTest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Platform, Arch } from "out"
22
import test from "./helpers/avaEx"
33
import { assertPack, getTestAsset, app } from "./helpers/packTester"
4-
import { copy, outputFile, readJson } from "fs-extra-p"
4+
import { copy, outputFile, readFile } from "fs-extra-p"
55
import * as path from "path"
66
import BluebirdPromise from "bluebird"
77
import { assertThat } from "./helpers/fileAssert"
88
import { extractFile } from "asar-electron-builder"
99
import { walk } from "out/asarUtil"
1010
import { nsisPerMachineInstall } from "./helpers/expectedContents"
1111
import { WineManager, diff } from "./helpers/wine"
12+
import { safeLoad } from "js-yaml"
1213

1314
const nsisTarget = Platform.WINDOWS.createTarget(["nsis"])
1415

@@ -31,7 +32,7 @@ test("one-click", app({
3132
packed: async (context) => {
3233
await doTest(context.outDir, true)
3334

34-
assertThat(await readJson(path.join(context.getResources(Platform.WINDOWS, Arch.ia32), ".app-update.json"))).hasProperties({
35+
assertThat(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, Arch.ia32), "app-update.yml"), "utf-8"))).hasProperties({
3536
provider: "bintray",
3637
owner: "actperepo",
3738
package: "TestApp",

test/src/nsisUpdaterTest.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { assertThat } from "./helpers/fileAssert"
33
import { NsisUpdater } from "out/nsis-auto-updater/src/NsisUpdater"
44
import * as path from "path"
55
import { TmpDir } from "out/util/tmp"
6-
import { outputJson } from "fs-extra-p"
6+
import { outputFile } from "fs-extra-p"
7+
import { safeDump } from "js-yaml"
78

89
const NsisUpdaterClass = require("../../nsis-auto-updater/out/nsis-auto-updater/src/NsisUpdater").NsisUpdater
910

@@ -37,11 +38,11 @@ test("cannot find suitable file for version", async (t) => {
3738
test("file url", async () => {
3839
const tmpDir = new TmpDir()
3940
const testResourcesPath = await tmpDir.getTempFile("update-config")
40-
await outputJson(path.join(testResourcesPath, ".app-update.json"), {
41+
await outputFile(path.join(testResourcesPath, "app-update.yml"), safeDump({
4142
provider: "bintray",
4243
owner: "actperepo",
4344
package: "TestApp",
44-
})
45+
}))
4546
g.__test_resourcesPath = testResourcesPath
4647
const updater: NsisUpdater = new NsisUpdaterClass()
4748

0 commit comments

Comments
 (0)