Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
chore: upgrade web
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed May 31, 2022
1 parent 45f9e08 commit 2bd0f69
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 127 deletions.
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ test/data/tmp/
web/
.github
codeqldb
*.js
scripts/
*.js
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "Standard Notes",
"description": "An end-to-end encrypted notes app for digitalists and professionals.",
"author": "Standard Notes <[email protected]>",
"version": "3.20.0",
"version": "3.20.1",
"main": "./dist/index.js",
"dependencies": {
"keytar": "^7.9.0"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "standard-notes",
"main": "./app/dist/index.js",
"version": "3.20.0",
"version": "3.20.1",
"repository": {
"type": "git",
"url": "git://github.com/standardnotes/desktop"
Expand All @@ -24,6 +24,7 @@
"lint": "npm-run-all --parallel lint:*",
"postinstall": "electron-builder install-app-deps",
"release": "node scripts/build.mjs mainstream",
"release:mac": "node scripts/build.mjs mac",
"setup": "yarn --ignore-engines && yarn --ignore-engines --cwd ./app && git submodule update --init && yarn --ignore-engines --cwd ./web",
"start": "electron ./app --enable-logging --icon _icon/icon.png",
"test": "rimraf test/data/tmp && ava",
Expand Down
123 changes: 56 additions & 67 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { spawn } from 'child_process';
import fs from 'fs';
import { spawn } from 'child_process'
import fs from 'fs'

async function buildTargets(targets) {
console.log('Building targets: ', targets);
await runCommand(Command('yarn run lint'));
await runCommand(Command('yarn clean:build'));
await runCommand(Command('yarn run build:web'));
console.log('Building targets: ', targets)
await runCommand(Command('yarn run lint'))
await runCommand(Command('yarn clean:build'))
await runCommand(Command('yarn run build:web'))

for (const group of CompileGroups) {
let didCompileGroup = false;
let didCompileGroup = false
for (const target of targets) {
if (group.targets.includes(target)) {
if (!didCompileGroup) {
await runCommand(group.compileCommand);
didCompileGroup = true;
await runCommand(group.compileCommand)
didCompileGroup = true
}
const buildCommands = BuildCommands[target];
const buildCommands = BuildCommands[target]
for (const buildCommand of buildCommands) {
await runCommand(buildCommand);
await runCommand(buildCommand)
}
}
}
Expand All @@ -26,22 +26,22 @@ async function buildTargets(targets) {

function runCommand(commandObj) {
return new Promise((resolve, reject) => {
const { prompt, extraEnv } = commandObj;
console.log(prompt, Object.keys(extraEnv).length > 0 ? extraEnv : '');
const [command, ...args] = prompt.split(' ');
const options = { env: Object.assign({}, process.env, extraEnv) };
const child = spawn(command, args, options);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
child.on('error', reject);
const { prompt, extraEnv } = commandObj
console.log(prompt, Object.keys(extraEnv).length > 0 ? extraEnv : '')
const [command, ...args] = prompt.split(' ')
const options = { env: Object.assign({}, process.env, extraEnv) }
const child = spawn(command, args, options)
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
child.on('error', reject)
child.on('close', (code) => {
if (code > 0) {
reject(code);
reject(code)
} else {
resolve(code);
resolve(code)
}
});
});
})
})
}

const Targets = {
Expand All @@ -59,9 +59,9 @@ const Targets = {
Snap: 'snap',
SnapArm64: 'snap-arm64',
Windows: 'windows',
};
}

const MainstreamTargetGroup = 'mainstream';
const MainstreamTargetGroup = 'mainstream'

const TargetGroups = {
all: [
Expand All @@ -83,16 +83,17 @@ const TargetGroups = {
Targets.DebArm64,
Targets.MacAll,
],
};
mac: [Targets.MacArm64],
}

const arm64Env = { npm_config_target_arch: 'arm64' };
const arm64Env = { npm_config_target_arch: 'arm64' }

const Command = function (prompt, extraEnv = {}) {
return {
prompt,
extraEnv,
};
};
}
}

const CompileGroups = [
{
Expand Down Expand Up @@ -129,28 +130,20 @@ const CompileGroups = [
compileCommand: Command('yarn run webpack --config webpack.prod.js --env snap', arm64Env),
targets: [Targets.SnapArm64],
},
];
]

const BuildCommands = {
[Targets.Appimage]: [
Command(
'yarn run electron-builder --linux --x64 --ia32 -c.linux.target=AppImage --publish=never'
),
],
[Targets.AppimageX64]: [
Command('yarn run electron-builder --linux --x64 -c.linux.target=AppImage --publish=never'),
Command('yarn run electron-builder --linux --x64 --ia32 -c.linux.target=AppImage --publish=never'),
],
[Targets.AppimageX64]: [Command('yarn run electron-builder --linux --x64 -c.linux.target=AppImage --publish=never')],
[Targets.AppimageArm64]: [
Command('yarn run electron-builder --linux --arm64 -c.linux.target=AppImage --publish=never'),
],
[Targets.AppimageAll]: [
Command(
'yarn run electron-builder --linux --arm64 --x64 --ia32 -c.linux.target=AppImage --publish=never'
),
],
[Targets.Deb]: [
Command('yarn run electron-builder --linux --x64 --ia32 -c.linux.target=deb --publish=never'),
Command('yarn run electron-builder --linux --arm64 --x64 --ia32 -c.linux.target=AppImage --publish=never'),
],
[Targets.Deb]: [Command('yarn run electron-builder --linux --x64 --ia32 -c.linux.target=deb --publish=never')],
[Targets.DebArm64]: [
Command('yarn run electron-builder --linux --arm64 -c.linux.target=deb --publish=never', {
npm_config_target_arch: 'arm64',
Expand All @@ -163,51 +156,47 @@ const BuildCommands = {
],
[Targets.MacArm64]: [Command('yarn run electron-builder --mac --arm64 --publish=never')],
[Targets.MacAll]: [Command('yarn run electron-builder --macos --arm64 --x64 --publish=never')],
[Targets.Dir]: [
Command('yarn run electron-builder --linux --x64 -c.linux.target=dir --publish=never'),
],
[Targets.Dir]: [Command('yarn run electron-builder --linux --x64 -c.linux.target=dir --publish=never')],
[Targets.DirArm64]: [
Command(
'yarn run electron-builder --linux --arm64 -c.linux.target=dir --publish=never',
arm64Env
),
],
[Targets.Snap]: [
Command('yarn run electron-builder --linux --x64 -c.linux.target=snap --publish=never'),
Command('yarn run electron-builder --linux --arm64 -c.linux.target=dir --publish=never', arm64Env),
],
[Targets.Snap]: [Command('yarn run electron-builder --linux --x64 -c.linux.target=snap --publish=never')],
[Targets.SnapArm64]: [
Command('yarn run electron-builder --linux --arm64 -c.linux.target=snap --publish=never', {
npm_config_target_arch: 'arm64',
SNAPCRAFT_BUILD_ENVIRONMENT: 'host',
}),
],
[Targets.Windows]: [Command('yarn run electron-builder --windows --x64 --ia32 --publish=never')],
};
}

async function publishSnap() {
const packageJson = await fs.promises.readFile('./package.json');
const version = JSON.parse(packageJson).version;
await runCommand(Command(`snapcraft upload dist/standard-notes-${version}-linux-amd64.snap`));
const packageJson = await fs.promises.readFile('./package.json')
const version = JSON.parse(packageJson).version
await runCommand(Command(`snapcraft upload dist/standard-notes-${version}-linux-amd64.snap`))
}

(async () => {
;(async () => {
try {
const input = process.argv[2];
let targets = input.split(',');
const input = process.argv[2]
let targets = input.split(',')

console.log('Input targets:', targets)

if (targets.length === 1) {
if (TargetGroups[targets[0]]) {
targets = TargetGroups[targets[0]];
targets = TargetGroups[targets[0]]
}
}
await buildTargets(targets);
await buildTargets(targets)

if (input === MainstreamTargetGroup) {
await runCommand(Command('node scripts/sums.mjs'));
await runCommand(Command('node scripts/create-draft-release.mjs'));
await publishSnap();
await runCommand(Command('node scripts/sums.mjs'))
await runCommand(Command('node scripts/create-draft-release.mjs'))
await publishSnap()
}
} catch (e) {
console.error(e);
process.exitCode = 1;
console.error(e)
process.exitCode = 1
}
})();
})()
27 changes: 13 additions & 14 deletions scripts/change-version.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { execSync } from 'child_process';

(async () => {
const version = process.argv[2];
import { execSync } from 'child_process'
;(async () => {
const version = process.argv[2]
if (!version) {
console.error('Must specify a version number.');
process.exitCode = 1;
return;
console.error('Must specify a version number.')
process.exitCode = 1
return
}
execSync(`yarn version --no-git-tag-version --new-version ${version}`);
process.chdir('app');
execSync(`yarn version --no-git-tag-version --new-version ${version}`);
process.chdir('..');
execSync('git add package.json app/package.json');
execSync(`git commit -m "chore(version): ${version}"`);
})();
execSync(`yarn version --no-git-tag-version --new-version ${version}`)
process.chdir('app')
execSync(`yarn version --no-git-tag-version --new-version ${version}`)
process.chdir('..')
execSync('git add package.json app/package.json')
execSync(`git commit -m "chore(version): ${version}"`)
})()
27 changes: 13 additions & 14 deletions scripts/create-draft-release.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
import { getLatestBuiltFilesList } from './utils.mjs';
import { spawn } from 'child_process'
import fs from 'fs'
import path from 'path'
import { getLatestBuiltFilesList } from './utils.mjs'
;(async () => {
const files = await getLatestBuiltFilesList()
files.push('SHA256SUMS')

(async () => {
const files = await getLatestBuiltFilesList();
files.push('SHA256SUMS');

const versionNumber = JSON.parse(fs.readFileSync('./package.json')).version;
console.log('Creating draft release...');
const versionNumber = JSON.parse(fs.readFileSync('./package.json')).version
console.log('Creating draft release...')
const child = spawn('gh', [
'release',
'create',
Expand All @@ -20,7 +19,7 @@ import { getLatestBuiltFilesList } from './utils.mjs';
'--prerelease',
'--title',
versionNumber,
]);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
})();
])
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
})()
40 changes: 20 additions & 20 deletions scripts/sums.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import crypto from 'crypto';
import fs from 'fs';
import { getLatestBuiltFilesList } from './utils.mjs';
import crypto from 'crypto'
import fs from 'fs'
import { getLatestBuiltFilesList } from './utils.mjs'

function sha256(filePath) {
return new Promise((resolve, reject) => {
fs.createReadStream(filePath)
.pipe(crypto.createHash('sha256').setEncoding('hex'))
.on('finish', function () {
resolve(this.read());
resolve(this.read())
})
.on('error', reject);
});
.on('error', reject)
})
}

(async () => {
console.log('Writing SHA256 sums to dist/SHA256SUMS');
;(async () => {
console.log('Writing SHA256 sums to dist/SHA256SUMS')

try {
const files = await getLatestBuiltFilesList();
const files = await getLatestBuiltFilesList()

process.chdir('dist');
process.chdir('dist')

let hashes = await Promise.all(
files.map(async (fileName) => {
const hash = await sha256(fileName);
return `${hash} ${fileName}`;
})
);
hashes = hashes.join('\n');
await fs.promises.writeFile('SHA256SUMS', hashes);
console.log(`Successfully wrote SHA256SUMS:\n${hashes}`);
const hash = await sha256(fileName)
return `${hash} ${fileName}`
}),
)
hashes = hashes.join('\n')
await fs.promises.writeFile('SHA256SUMS', hashes)
console.log(`Successfully wrote SHA256SUMS:\n${hashes}`)
} catch (err) {
console.error(err);
process.exitCode = 1;
console.error(err)
process.exitCode = 1
}
})();
})()
14 changes: 7 additions & 7 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import fs from 'fs'

export async function getLatestBuiltFilesList() {
const packageJson = await fs.promises.readFile('./package.json');
const version = JSON.parse(packageJson).version;
const packageJson = await fs.promises.readFile('./package.json')
const version = JSON.parse(packageJson).version
return [
`standard-notes-${version}-mac-x64.zip`,
`standard-notes-${version}-mac-x64.dmg`,
Expand Down Expand Up @@ -34,11 +34,11 @@ export async function getLatestBuiltFilesList() {
'latest-mac.yml',
'latest.yml',
'builder-effective-config.yaml',
];
]
}

export async function getBuiltx64SnapFilename() {
const packageJson = await fs.promises.readFile('./package.json');
const version = JSON.parse(packageJson).version;
return `standard-notes-${version}-linux-amd64.snap`;
const packageJson = await fs.promises.readFile('./package.json')
const version = JSON.parse(packageJson).version
return `standard-notes-${version}-linux-amd64.snap`
}
Loading

0 comments on commit 2bd0f69

Please sign in to comment.