Skip to content

Commit bf9953e

Browse files
committed
prettier config file and settings
1 parent 6fa1293 commit bf9953e

20 files changed

Lines changed: 4033 additions & 3564 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
test.mjs
3-
.vscode
43
dist.zip

.vscode/getNet.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { networkInterfaces } = require('os');
2+
3+
module.exports = async (mode = 'dev') => {
4+
const { WiFi, Ethernet } = getIp();
5+
const [ip] = WiFi || Ethernet || [];
6+
const port = '5500';
7+
const src = `https://${ip || '10.0.0'}:${port}`;
8+
console.log('Server starting at: ', src);
9+
return { ip, port };
10+
};
11+
12+
function getIp() {
13+
const nets = networkInterfaces();
14+
const results = {}; // Or just '{}', an empty object
15+
16+
Object.keys(nets).forEach((name) => {
17+
nets[name].forEach((net) => {
18+
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
19+
// 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
20+
const familyV4Value = typeof net.family === 'string' ? 'IPv4' : 4;
21+
if (net.family === familyV4Value && !net.internal) {
22+
if (!results[name]) {
23+
results[name] = [];
24+
}
25+
results[name].push(net.address);
26+
}
27+
});
28+
});
29+
return results;
30+
}

.vscode/pack-zip.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const jszip = require('jszip');
4+
5+
const iconFile = path.join(__dirname, '../icon.png');
6+
const pluginJSON = path.join(__dirname, '../plugin.json');
7+
const distFolder = path.join(__dirname, '../dist');
8+
let readmeDotMd = path.join(__dirname, '../readme.md');
9+
10+
if (!fs.existsSync(readmeDotMd)) {
11+
readmeDotMd = path.join(__dirname, '../README.md');
12+
}
13+
14+
// create zip file of dist folder
15+
16+
const zip = new jszip();
17+
18+
zip.file('icon.png', fs.readFileSync(iconFile));
19+
zip.file('plugin.json', fs.readFileSync(pluginJSON));
20+
zip.file('readme.md', fs.readFileSync(readmeDotMd));
21+
22+
loadFile('', distFolder);
23+
24+
zip
25+
.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
26+
.pipe(fs.createWriteStream(path.join(__dirname, '../dist.zip')))
27+
.on('finish', () => {
28+
console.log('dist.zip written.');
29+
});
30+
31+
function loadFile(root, folder) {
32+
const distFiles = fs.readdirSync(folder);
33+
distFiles.forEach((file) => {
34+
35+
const stat = fs.statSync(path.join(folder, file));
36+
37+
if (stat.isDirectory()) {
38+
zip.folder(file);
39+
loadFile(path.join(root, file), path.join(folder, file));
40+
return;
41+
}
42+
43+
if (!/LICENSE.txt/.test(file)) {
44+
zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file)));
45+
}
46+
});
47+
}

.vscode/run-webpack.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable no-console */
2+
const { spawn } = require('child_process');
3+
const path = require('path');
4+
5+
const webpack = spawn('npx', ['webpack', '--mode=development', '--watch'], { cwd: path.resolve(__dirname, '../') });
6+
7+
webpack.on('error', (webpackError) => {
8+
if (webpackError) {
9+
console.error(webpackError);
10+
process.exit(1);
11+
}
12+
});
13+
14+
webpack.stdout.on('data', (chunk) => {
15+
const stdout = chunk.toString();
16+
console.log(stdout);
17+
process.send(stdout);
18+
});
19+
20+
webpack.stdout.on('error', (error) => {
21+
console.log(error);
22+
});
23+
24+
webpack.stderr.on('data', (chunk) => {
25+
const stderr = chunk.toString();
26+
console.log(stderr);
27+
});

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"Aspree",
1111
"deadlyjack",
1212
"espree",
13-
"Meriyah"
13+
"estree",
14+
"Meriyah",
15+
"whitespaces"
1416
]
1517
}

.vscode/start-dev.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable no-console */
2+
const { fork, spawn } = require('child_process');
3+
const path = require('path');
4+
5+
main();
6+
7+
async function main() {
8+
let serverStarted = false;
9+
console.log('+--------------+');
10+
console.log('| Starting dev |');
11+
console.log('+--------------+');
12+
const webpack = fork(path.resolve(__dirname, './run-webpack.js'));
13+
webpack.on('message', (chunk) => {
14+
if (!serverStarted && chunk.search(/compiled\ssuccessfully/)) {
15+
startServer();
16+
serverStarted = true;
17+
}
18+
});
19+
20+
webpack.on('error', (err) => {
21+
console.log('WEBPACK ERROR', err);
22+
webpack.kill(1);
23+
process.exit(1);
24+
});
25+
}
26+
27+
async function startServer() {
28+
const server = fork(path.resolve(__dirname, './start-server.js'));
29+
server.on('error', (err) => {
30+
console.log('SERVER ERROR', err);
31+
server.kill(1);
32+
process.exit(1);
33+
});
34+
}

.vscode/start-server.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
const fs = require('fs');
3+
const path = require('path');
4+
const liveServer = require('live-server');
5+
const getNet = require('./getNet');
6+
7+
const serverCrt = path.resolve(__dirname, 'server.crt');
8+
const serverKey = path.resolve(__dirname, 'server.key');
9+
10+
main();
11+
12+
async function main() {
13+
const { ip: host, port } = await getNet('dev');
14+
process.cwd = () => __dirname;
15+
liveServer.start({
16+
open: false,
17+
port,
18+
host,
19+
cors: true,
20+
root: '../',
21+
ignore: 'node_modules,platforms,plugins',
22+
file: 'index.html',
23+
https: {
24+
cert: fs.readFileSync(serverCrt),
25+
key: fs.readFileSync(serverKey),
26+
passphrase: '1234',
27+
},
28+
middleware: [(req, res, next) => {
29+
const url = req.originalUrl;
30+
const www = '../platforms/android/app/src/main/assets/www/';
31+
32+
if (url === '/cordova.js') {
33+
const file = path.resolve(__dirname, www, 'cordova.js');
34+
sendFile(res, file);
35+
return;
36+
}
37+
38+
if (url === '/cordova_plugins.js') {
39+
const file = path.resolve(__dirname, www, 'cordova_plugins.js');
40+
sendFile(res, file);
41+
return;
42+
}
43+
44+
next();
45+
}],
46+
});
47+
48+
process.send('OK');
49+
}
50+
51+
function sendFile(res, filePath) {
52+
if (fs.existsSync(filePath)) {
53+
const stat = fs.statSync(filePath);
54+
55+
res.writeHead(200, {
56+
'Content-Type': 'application/javascript',
57+
'Content-Length': stat.size,
58+
});
59+
60+
const readStream = fs.createReadStream(filePath);
61+
readStream.pipe(res);
62+
return;
63+
}
64+
65+
res.writeHead(404, { 'Content-Type': 'text/plain' });
66+
res.end(`ERROR cannot get ${filePath}`);
67+
}

dist/744.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1+
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */

0 commit comments

Comments
 (0)