added initial files
This commit is contained in:
@@ -0,0 +1,279 @@
|
||||
const { promisify } = require('util');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const zlib = require('zlib');
|
||||
const makeDir = require('make-dir');
|
||||
const { pipeline } = require('stream');
|
||||
const fse = require('fs-extra');
|
||||
const electronBuilder = require('electron-builder');
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const readdir = promisify(fs.readdir);
|
||||
const stat = promisify(fs.stat);
|
||||
|
||||
const type = process.argv[2];
|
||||
|
||||
const getFiles = async dir => {
|
||||
const subdirs = await readdir(dir);
|
||||
const files = await Promise.all(
|
||||
subdirs.map(async subdir => {
|
||||
const res = path.resolve(dir, subdir);
|
||||
return (await stat(res)).isDirectory() ? getFiles(res) : res;
|
||||
})
|
||||
);
|
||||
return files.reduce((a, f) => a.concat(f), []);
|
||||
};
|
||||
|
||||
const getSha1 = async filePath => {
|
||||
// Calculate sha1 on original file
|
||||
const algorithm = 'sha1';
|
||||
const shasum = crypto.createHash(algorithm);
|
||||
|
||||
const s = fs.ReadStream(filePath);
|
||||
s.on('data', data => {
|
||||
shasum.update(data);
|
||||
});
|
||||
|
||||
const hash = await new Promise(resolve => {
|
||||
s.on('end', () => {
|
||||
resolve(shasum.digest('hex'));
|
||||
});
|
||||
});
|
||||
return hash;
|
||||
};
|
||||
|
||||
const winReleaseFolder = path.resolve(
|
||||
__dirname,
|
||||
'../',
|
||||
'./release',
|
||||
`win-unpacked`
|
||||
);
|
||||
const deployFolder = path.resolve(__dirname, '../', 'deploy');
|
||||
|
||||
const createDeployFiles = async () => {
|
||||
const files = await getFiles(winReleaseFolder);
|
||||
const mappedFiles = await Promise.all(
|
||||
files.map(async v => {
|
||||
// Compress
|
||||
const hash = await getSha1(v);
|
||||
|
||||
const gzip = zlib.createGzip();
|
||||
const source = fs.createReadStream(v);
|
||||
|
||||
const isAppAsar = path.basename(v) === 'app.asar';
|
||||
|
||||
const destinationPath = path.join(
|
||||
deployFolder,
|
||||
`win_${path.relative(winReleaseFolder, v).replace(path.sep, '-')}.gz`
|
||||
);
|
||||
await makeDir(path.dirname(destinationPath));
|
||||
const destination = fs.createWriteStream(destinationPath);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
pipeline(source, gzip, destination, err => {
|
||||
if (err) {
|
||||
reject();
|
||||
}
|
||||
destination.close();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
const compressedSha1 = await getSha1(destinationPath);
|
||||
|
||||
return {
|
||||
file: path.relative(winReleaseFolder, v).split(path.sep),
|
||||
sha1: hash,
|
||||
compressedFile: path.basename(destinationPath),
|
||||
compressedSha1,
|
||||
...(isAppAsar && { isAppAsar: true })
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
await fs.promises.writeFile(
|
||||
path.join(deployFolder, `win32_latest.json`),
|
||||
JSON.stringify(mappedFiles)
|
||||
);
|
||||
};
|
||||
|
||||
const extraFiles = [];
|
||||
let sevenZipPath = null;
|
||||
if (process.platform === 'win32') {
|
||||
sevenZipPath = 'node_modules/7zip-bin/win/x64/7za.exe';
|
||||
extraFiles.push({
|
||||
from: 'vcredist/',
|
||||
to: './',
|
||||
filter: '**/*'
|
||||
});
|
||||
} else if (process.platform === 'linux') {
|
||||
if (process.arch === 'arm64') {
|
||||
sevenZipPath = 'node_modules/7zip-bin/linux/arm64/7za';
|
||||
} else if (process.arch === 'arm') {
|
||||
sevenZipPath = 'node_modules/7zip-bin/linux/arm/7za';
|
||||
} else {
|
||||
sevenZipPath = 'node_modules/7zip-bin/linux/x64/7za';
|
||||
}
|
||||
} else if (process.platform === 'darwin') {
|
||||
sevenZipPath = 'node_modules/7zip-bin/mac/x64/7za';
|
||||
}
|
||||
|
||||
extraFiles.push({
|
||||
from: sevenZipPath,
|
||||
to: './'
|
||||
});
|
||||
|
||||
const commonConfig = {
|
||||
publish: 'never',
|
||||
config: {
|
||||
generateUpdatesFilesForAllChannels: true,
|
||||
npmRebuild: false,
|
||||
productName: 'GDLauncher',
|
||||
appId: 'org.gorilladevs.GDLauncher',
|
||||
files: [
|
||||
'!node_modules/**/*',
|
||||
'build/**/*',
|
||||
'package.json',
|
||||
'public/icon.png'
|
||||
],
|
||||
extraFiles,
|
||||
asar: {
|
||||
smartUnpack: false
|
||||
},
|
||||
dmg: {
|
||||
contents: [
|
||||
{
|
||||
x: 130,
|
||||
y: 220
|
||||
},
|
||||
{
|
||||
x: 410,
|
||||
y: 220,
|
||||
type: 'link',
|
||||
path: '/Applications'
|
||||
}
|
||||
]
|
||||
},
|
||||
nsisWeb: {
|
||||
oneClick: true,
|
||||
installerIcon: './public/icon.ico',
|
||||
uninstallerIcon: './public/icon.ico',
|
||||
installerHeader: './public/installerHeader.bmp',
|
||||
installerSidebar: './public/installerSidebar.bmp',
|
||||
installerHeaderIcon: './public/icon.ico',
|
||||
deleteAppDataOnUninstall: true,
|
||||
allowToChangeInstallationDirectory: false,
|
||||
perMachine: false,
|
||||
differentialPackage: true,
|
||||
include: './public/installer.nsh'
|
||||
},
|
||||
mac: {
|
||||
entitlements: './entitlements.mac.plist',
|
||||
entitlementsInherit: './entitlements.mac.plist'
|
||||
},
|
||||
/* eslint-disable */
|
||||
artifactName: `${'${productName}'}-${'${os}'}-${
|
||||
process.argv[2]
|
||||
}.${'${ext}'}`,
|
||||
/* eslint-enable */
|
||||
linux: {
|
||||
category: 'Game',
|
||||
icon: 'public/linux-icons/'
|
||||
},
|
||||
directories: {
|
||||
buildResources: 'public',
|
||||
output: 'release'
|
||||
},
|
||||
protocols: [
|
||||
{
|
||||
name: 'gdlauncher',
|
||||
role: 'Viewer',
|
||||
schemes: ['gdlauncher']
|
||||
}
|
||||
]
|
||||
},
|
||||
...(process.platform === 'linux' && {
|
||||
linux:
|
||||
type === 'setup'
|
||||
? ['appimage', 'zip', 'deb', 'rpm'].map(x => `${x}:${process.arch}`)
|
||||
: [`snap:${process.arch}`]
|
||||
}),
|
||||
...(process.platform === 'win32' && {
|
||||
win: [type === 'setup' ? 'nsis:x64' : 'zip:x64']
|
||||
}),
|
||||
...(process.platform === 'darwin' && {
|
||||
mac: type === 'setup' ? ['dmg:x64'] : []
|
||||
})
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
const releasesFolder = path.resolve(__dirname, '../', './release');
|
||||
await fse.remove(releasesFolder);
|
||||
await makeDir(deployFolder);
|
||||
await electronBuilder.build(commonConfig);
|
||||
if (type === 'portable' && process.platform === 'win32') {
|
||||
await createDeployFiles();
|
||||
}
|
||||
|
||||
// Copy all other files to deploy folder
|
||||
|
||||
const { productName } = commonConfig.config;
|
||||
|
||||
let linuxyml = '';
|
||||
if (process.arch === 'x64') {
|
||||
linuxyml = 'latest-linux.yml';
|
||||
} else {
|
||||
linuxyml = `latest-linux-${process.arch}.yml`;
|
||||
}
|
||||
|
||||
const allFiles = {
|
||||
setup: {
|
||||
darwin: [
|
||||
`${productName}-mac-${type}.dmg`,
|
||||
`${productName}-mac-${type}.dmg.blockmap`,
|
||||
'latest-mac.yml'
|
||||
],
|
||||
win32: [
|
||||
path.join(`${productName}-win-${type}.exe`),
|
||||
path.join(`${productName}-win-${type}.exe.blockmap`),
|
||||
path.join('latest.yml')
|
||||
],
|
||||
linux: [
|
||||
`${productName}-linux-${type}.zip`,
|
||||
`${productName}-linux-${type}.AppImage`,
|
||||
`${productName}-linux-${type}.deb`,
|
||||
`${productName}-linux-${type}.rpm`,
|
||||
`${linuxyml}`
|
||||
]
|
||||
},
|
||||
portable: {
|
||||
darwin: [],
|
||||
win32: [`${productName}-win-${type}.zip`],
|
||||
linux: [`${productName}-linux-${type}.snap`]
|
||||
}
|
||||
};
|
||||
|
||||
const filesToMove = allFiles[type][process.platform];
|
||||
|
||||
await Promise.all(
|
||||
filesToMove.map(async file => {
|
||||
const stats = await fs.promises.stat(path.join(releasesFolder, file));
|
||||
if (stats.isFile()) {
|
||||
await fse.move(
|
||||
path.join(releasesFolder, file),
|
||||
path.join(deployFolder, file.replace('nsis-web', ''))
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
await fse.remove(releasesFolder);
|
||||
};
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* Webpack config for production electron main process
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
// eslint-disable-next-line
|
||||
const webpack = require('webpack');
|
||||
const { merge } = require('webpack-merge');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||
|
||||
fse.copySync(
|
||||
path.resolve(__dirname, '../', 'public', 'native'),
|
||||
path.resolve(__dirname, '../', 'build', 'native'),
|
||||
{}
|
||||
);
|
||||
|
||||
const baseConfig = {
|
||||
externals: [],
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.node$/,
|
||||
loader: 'native-ext-loader',
|
||||
options: {
|
||||
basePath: ['native'],
|
||||
emit: false
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.jsx?$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
cacheDirectory: true,
|
||||
presets: [['@babel/preset-env', { targets: { node: '14' } }]],
|
||||
plugins: [
|
||||
'@babel/plugin-proposal-nullish-coalescing-operator',
|
||||
'@babel/plugin-proposal-optional-chaining'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
output: {
|
||||
path: path.join(__dirname, '..', 'build'),
|
||||
// https://github.com/webpack/webpack/issues/1114
|
||||
libraryTarget: 'commonjs2'
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine the array of extensions that should be used to resolve modules.
|
||||
*/
|
||||
resolve: {
|
||||
extensions: ['.js', '.jsx', '.json'],
|
||||
modules: [path.join(__dirname, '..', 'build'), 'node_modules']
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.EnvironmentPlugin({
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
REACT_APP_RELEASE_TYPE: process.env.REACT_APP_RELEASE_TYPE,
|
||||
SENTRY_DSN: process.env.SENTRY_DSN
|
||||
}),
|
||||
new webpack.NamedModulesPlugin()
|
||||
]
|
||||
};
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
devtool: 'source-map',
|
||||
|
||||
mode: process.env.NODE_ENV,
|
||||
|
||||
target: 'electron-main',
|
||||
|
||||
entry: './public/electron.js',
|
||||
|
||||
output: {
|
||||
path: path.join(__dirname, '..'),
|
||||
filename: './build/electron.js'
|
||||
},
|
||||
|
||||
optimization: {
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true,
|
||||
sourceMap: true,
|
||||
cache: true
|
||||
})
|
||||
]
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new BundleAnalyzerPlugin({
|
||||
analyzerMode:
|
||||
process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled',
|
||||
openAnalyzer: process.env.OPEN_ANALYZER === 'true'
|
||||
}),
|
||||
|
||||
/**
|
||||
* Create global constants which can be configured at compile time.
|
||||
*
|
||||
* Useful for allowing different behaviour between development builds and
|
||||
* release builds
|
||||
*
|
||||
* NODE_ENV should be production so that modules do not perform certain
|
||||
* development checks
|
||||
*/
|
||||
new webpack.EnvironmentPlugin({
|
||||
NODE_ENV: 'production',
|
||||
DEBUG_PROD: false,
|
||||
START_MINIMIZED: false
|
||||
})
|
||||
],
|
||||
|
||||
/**
|
||||
* Disables webpack processing of __dirname and __filename.
|
||||
* If you run the bundle in node.js it falls back to these values of node.js.
|
||||
* https://github.com/webpack/webpack/issues/2010
|
||||
*/
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
const fs = require('fs');
|
||||
// const os = require('os');
|
||||
|
||||
if (!fs.existsSync('../public/native')) fs.mkdirSync('../public/native');
|
||||
|
||||
fs.renameSync('./napi.node', `../public/native/napi.node`);
|
||||
// fs.renameSync('./index.d.ts', `../public/native/${os.platform()}/index.d.ts`);
|
||||
@@ -0,0 +1,8 @@
|
||||
const fs = require('fs');
|
||||
|
||||
if (!fs.existsSync('./public/native')) fs.mkdirSync('./public/native');
|
||||
|
||||
fs.copyFileSync(
|
||||
'./node_modules/nsfw/build/Release/nsfw.node',
|
||||
`./public/native/nsfw.node`
|
||||
);
|
||||
@@ -0,0 +1,141 @@
|
||||
const { promisify } = require('util');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const axios = require('axios');
|
||||
const fse = require('fs-extra');
|
||||
const dotenv = require('dotenv');
|
||||
const rawChangeLog = require('../src/common/modals/ChangeLogs/changeLog');
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const readdir = promisify(fs.readdir);
|
||||
const stat = promisify(fs.stat);
|
||||
|
||||
const deployFolder = path.resolve(__dirname, '../', 'deploy');
|
||||
|
||||
const main = async () => {
|
||||
if (!process.env.GH_ACCESS_TOKEN_RELEASES) {
|
||||
console.warn('Cannot upload artifacts. No auth token provided');
|
||||
return;
|
||||
}
|
||||
const { version } = await fse.readJson(
|
||||
path.resolve(__dirname, '../', 'package.json')
|
||||
);
|
||||
|
||||
let uploadUrl = null;
|
||||
|
||||
try {
|
||||
const { data: releasesList } = await axios.default.get(
|
||||
`https://api.github.com/repos/gorilla-devs/GDLauncher/releases`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `token ${process.env.GH_ACCESS_TOKEN_RELEASES}`
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const lastRelease = releasesList.find(v => v.tag_name === `v${version}`);
|
||||
|
||||
if (lastRelease) {
|
||||
uploadUrl = lastRelease.upload_url;
|
||||
console.log('Found a release with this tag. Uploading there.');
|
||||
} else {
|
||||
throw new Error('Could not find release. Creating one.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
||||
const getChangeLog = () => {
|
||||
let changeLog = '';
|
||||
for (const element in rawChangeLog) {
|
||||
if (rawChangeLog[element].length) {
|
||||
changeLog += `### ${element
|
||||
.charAt(0)
|
||||
.toUpperCase()}${element.substring(1)}\n`;
|
||||
|
||||
for (const e of rawChangeLog[element]) {
|
||||
const prSplit = e?.advanced?.pr && e?.advanced?.pr.split('/');
|
||||
const advanced =
|
||||
e?.advanced?.cm &&
|
||||
` ([${e?.advanced?.cm}](https://github.com/gorilla-devs/GDLauncher/commit/${e?.advanced?.cm})` +
|
||||
`${
|
||||
prSplit
|
||||
? ` | [#${e?.advanced.pr}](https://github.com/gorilla-devs/GDLauncher/pull/${prSplit[0]}` +
|
||||
`${prSplit?.[1] ? `/commits/${prSplit[1]}` : ''})`
|
||||
: ''
|
||||
})`;
|
||||
const notes = `- **${e?.header || ''}** ${e?.content || ''}`;
|
||||
changeLog += `${notes + advanced} \n`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changeLog;
|
||||
};
|
||||
|
||||
const { data: newRelease } = await axios.default.post(
|
||||
'https://api.github.com/repos/gorilla-devs/GDLauncher/releases',
|
||||
{
|
||||
tag_name: `v${version}`,
|
||||
name: `v${version}`,
|
||||
draft: true,
|
||||
prerelease: version.includes('beta'),
|
||||
body: getChangeLog()
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `token ${process.env.GH_ACCESS_TOKEN_RELEASES}`
|
||||
}
|
||||
}
|
||||
);
|
||||
uploadUrl = newRelease.upload_url;
|
||||
console.log('New release tag created.');
|
||||
}
|
||||
|
||||
const deployFiles = await readdir(deployFolder);
|
||||
|
||||
console.log(`Found ${deployFiles.length} files to upload.`);
|
||||
let uploaded = 0;
|
||||
for (const file of deployFiles) {
|
||||
const fileUploadUrl = uploadUrl.replace('{?name,label}', `?name=${file}`);
|
||||
const stats = await stat(path.join(deployFolder, file));
|
||||
const buffer = await fs.promises.readFile(path.join(deployFolder, file));
|
||||
|
||||
let contentType = null;
|
||||
|
||||
switch (path.extname(file)) {
|
||||
case '.gz':
|
||||
contentType = 'application/gzip';
|
||||
break;
|
||||
case '.zip':
|
||||
contentType = 'application/zip';
|
||||
break;
|
||||
case '.json':
|
||||
contentType = 'application/json';
|
||||
break;
|
||||
default:
|
||||
contentType = 'application/octet-stream';
|
||||
}
|
||||
|
||||
try {
|
||||
await axios.default.post(fileUploadUrl, buffer, {
|
||||
headers: {
|
||||
'Content-Length': stats.size,
|
||||
'Content-Type': contentType,
|
||||
Authorization: `token ${process.env.GH_ACCESS_TOKEN_RELEASES}`
|
||||
},
|
||||
maxContentLength: Infinity,
|
||||
maxBodyLength: Infinity
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
throw err;
|
||||
}
|
||||
uploaded += 1;
|
||||
console.log(`Uploaded ${uploaded} / ${deployFiles.length} -- ${file}`);
|
||||
}
|
||||
};
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user