Skip to content

Commit

Permalink
style: format scripts and JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Garifullin Ruslan committed Jan 5, 2021
1 parent 52dc643 commit a03cf50
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 53 deletions.
60 changes: 31 additions & 29 deletions build-deb.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const path = require('path');
const fs = require('fs');
const process = require('child_process');
const { join } = require('path');
const { mkdirSync, readdirSync, readFileSync } = require('fs');
const { execSync } = require('child_process');

const CONFIG_FILE = path.join(__dirname, 'deploy', 'config.json');
const { appName } = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
const safeAppName = appName.replace(' ', '').toLowerCase();
const { log } = console;

const BUILD_DIR = path.join(__dirname, 'deploy', 'linux', 'build', appName);
const LIB_DIR = path.join(__dirname, 'deb-struct', 'usr', 'lib');
const BIN_DIR = path.join(__dirname, 'deb-struct', 'usr', 'bin', appName);
const CONFIG_FILE = join(__dirname, 'deploy', 'config.json');
const { appName } = JSON.parse(readFileSync(CONFIG_FILE, 'utf8'));
const safeName = appName.replace(' ', '').toLowerCase();

const BUILD_DIR = join(__dirname, 'deploy', 'linux', 'build', appName);
const LIB_DIR = join(__dirname, 'deb-struct', 'usr', 'lib');
const BIN_DIR = join(__dirname, 'deb-struct', 'usr', 'bin', appName);
const paths = [
'./deb-struct/DEBIAN/',
'./deb-struct/usr/bin/',
Expand All @@ -17,33 +19,33 @@ const paths = [
];

function getFilesFromPath(path, extension) {
const files = fs.readdirSync(path);
const files = readdirSync(path);

return files.filter(file => file.match(new RegExp(`.*\.(${extension})`, 'ig')));
return files.filter((file) => file.match(new RegExp(`.*.(${extension})`, 'ig')));
}

console.log('Packaging DiscordQt into a Debian package...');
log('Packaging DiscordQt into a Debian package...');

paths.forEach(dir => fs.mkdirSync(dir, {recursive: true}));
paths.forEach(dir => process.execSync(`rm -rf ${dir}*`));
paths.forEach((dir) => mkdirSync(dir, { recursive: true }));
paths.forEach((dir) => execSync(`rm -rf ${dir}*`));

console.log('Copying control...');
process.execSync('cp ./control ./deb-struct/DEBIAN/control');
log('Copying control...');
execSync('cp ./control ./deb-struct/DEBIAN/control');

console.log('Copying build directory...');
process.execSync(`cp -R '${BUILD_DIR}' '${LIB_DIR}'`);
process.execSync(`cp -R ./assets './deb-struct/usr/lib/${appName}'`);
process.execSync(`mv './deb-struct/usr/lib/${appName}' ./deb-struct/usr/lib/${safeAppName}`);
log('Copying build directory...');
execSync(`cp -R '${BUILD_DIR}' '${LIB_DIR}'`);
execSync(`cp -R ./assets './deb-struct/usr/lib/${appName}'`);
execSync(`mv './deb-struct/usr/lib/${appName}' ./deb-struct/usr/lib/${safeName}`);

console.log('Copying symlink...');
process.execSync(`ln -s /usr/lib/${safeAppName}/qode '${BIN_DIR}'`);
log('Copying symlink...');
execSync(`ln -s /usr/lib/${safeName}/qode '${BIN_DIR}'`);

console.log('Copying .desktop file...');
const from = path.join(BUILD_DIR, getFilesFromPath(BUILD_DIR, '.desktop')[0]);
const to = path.join(__dirname, 'deb-struct/usr/share/applications/', `${safeAppName }.desktop`)
log('Copying .desktop file...');
const from = join(BUILD_DIR, getFilesFromPath(BUILD_DIR, '.desktop')[0]);
const to = join(__dirname, 'deb-struct/usr/share/applications/', `${safeName}.desktop`)

process.execSync(`cp '${from}' '${to}'`);
execSync(`cp '${from}' '${to}'`);

console.log('Generating Debian package...');
process.execSync('dpkg-deb --build deb-struct');
process.execSync(`mv deb-struct.deb ${safeAppName}.deb`);
log('Generating Debian package...');
execSync('dpkg-deb --build deb-struct');
execSync(`mv deb-struct.deb ${safeName}.deb`);
24 changes: 12 additions & 12 deletions downloadNodeGui.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* eslint-disable import/no-extraneous-dependencies */
const fs = require('fs');
const path = require('path');
const {https} = require('follow-redirects');
const { dirname, join } = require('path');
const { https } = require('follow-redirects');

const {platform} = process;
const {arch} = process;
const { platform } = process;
const { arch } = process;
const version = 'v0.26.0';

const binPath = path.join(__dirname, 'node_modules/@nodegui/nodegui/build/Release/nodegui_core.node');
const binPath = join(__dirname, 'node_modules/@nodegui/nodegui/build/Release/nodegui_core.node');

if (fs.existsSync(binPath)) {return process.exit(0);}
if (!fs.existsSync(binPath)) {
fs.mkdirSync(dirname(binPath), { recursive: true });

fs.mkdirSync(path.dirname(binPath), { recursive: true });
const dlPath = `https://github.com/ruslang02/nodegui-bin/releases/download/${version}/nodegui_core-${platform}-${arch}.node`;
const file = fs.createWriteStream(binPath);

const dlPath = `https://github.com/ruslang02/nodegui-bin/releases/download/${version}/nodegui_core-${platform}-${arch}.node`;

const file = fs.createWriteStream(binPath);

https.get(dlPath, r => r.pipe(file));
https.get(dlPath, (r) => r.pipe(file));
}
9 changes: 6 additions & 3 deletions launch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env node
const cp = require('child_process');

const { log, error } = console;

const proc = cp.spawn('npm run start', {
shell: true,
cwd: __dirname
cwd: __dirname,
});

proc.stdout.on('data', (chunk) => console.log(chunk.toString()));
proc.stderr.on('data', (chunk) => console.error(chunk.toString()));
proc.stdout.on('data', (chunk) => log(chunk.toString()));
proc.stderr.on('data', (chunk) => error(chunk.toString()));
12 changes: 3 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"compilerOptions": {
"target": "es2019",
"lib": [
"es6"
],
"lib": ["es6"],
"module": "commonjs",
"allowJs": false,
"checkJs": false,
Expand All @@ -20,11 +18,7 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"./src/types/"
]
"typeRoots": ["./src/types/"]
},
"exclude": [
"node_modules/**/*.ts"
]
"exclude": ["node_modules/**/*.ts"]
}

0 comments on commit a03cf50

Please sign in to comment.