-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts to format code (c/cpp/h/js/css/scss)
Add .prettierrc as js/scss/css format configuration Apply style to code source
- Loading branch information
1 parent
34ef4bc
commit 28747db
Showing
303 changed files
with
16,491 additions
and
7,885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 4, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"jsxSingleQuote": false, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"bracketSameLine": false, | ||
"arrowParens": "always", | ||
"requirePragma": false, | ||
"insertPragma": false, | ||
"proseWrap": "preserve", | ||
"overrides": [ | ||
{ | ||
"files": "*.js", | ||
"options": { | ||
"parser": "babel" | ||
} | ||
}, | ||
{"files": "*.scss", | ||
"options": { | ||
"parser": "css" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,93 @@ | ||
let path = require("path"); | ||
const fs = require("fs"); | ||
const { createReadStream, createWriteStream } = require("fs"); | ||
const { createGzip } = require("zlib"); | ||
const chalk = require("chalk"); | ||
|
||
let destPath = path.normalize(__dirname + "/../../main/embedded/"); | ||
let distPath = path.normalize(__dirname + "/../dist/"); | ||
let srcPath = path.normalize(__dirname + "/../assets/"); | ||
let path = require('path'); | ||
const fs = require('fs'); | ||
const { createReadStream, createWriteStream } = require('fs'); | ||
const { createGzip } = require('zlib'); | ||
const chalk = require('chalk'); | ||
|
||
let destPath = path.normalize(__dirname + '/../../main/embedded/'); | ||
let distPath = path.normalize(__dirname + '/../dist/'); | ||
let srcPath = path.normalize(__dirname + '/../assets/'); | ||
|
||
const convertToC = (filepath) => { | ||
console.log(chalk.yellow("Converting bin to text file")); | ||
//Cleaning files | ||
if (fs.existsSync(distPath + "out.tmp")) fs.rmSync(distPath + "out.tmp"); | ||
if (fs.existsSync(distPath + "favicon.h")) fs.rmSync(distPath + "favicon.h"); | ||
|
||
const data = new Uint8Array( | ||
fs.readFileSync(filepath, { flag: "r" }) | ||
); | ||
console.log("data size is ", data.length); | ||
let out = "#define favicon_size " + data.length + "\n"; | ||
out += "const unsigned char favicon[" + data.length + "] PROGMEM = {\n "; | ||
let nb = 0; | ||
data.forEach((byte, index) => { | ||
out += " 0x" + (byte.toString(16).length == 1 ? "0" : "") + byte.toString(16); | ||
if (index < data.length - 1) out += ","; | ||
if (nb == 15) { | ||
out += "\n "; | ||
nb = 0; | ||
} else { | ||
nb++; | ||
} | ||
}); | ||
console.log(chalk.yellow('Converting bin to text file')); | ||
//Cleaning files | ||
if (fs.existsSync(distPath + 'out.tmp')) fs.rmSync(distPath + 'out.tmp'); | ||
if (fs.existsSync(distPath + 'favicon.h')) | ||
fs.rmSync(distPath + 'favicon.h'); | ||
|
||
out += "\n};\n"; | ||
fs.writeFileSync(distPath + "out.tmp", out); | ||
const data = new Uint8Array(fs.readFileSync(filepath, { flag: 'r' })); | ||
console.log('data size is ', data.length); | ||
let out = '#define favicon_size ' + data.length + '\n'; | ||
out += 'const unsigned char favicon[' + data.length + '] PROGMEM = {\n '; | ||
let nb = 0; | ||
data.forEach((byte, index) => { | ||
out += | ||
' 0x' + | ||
(byte.toString(16).length == 1 ? '0' : '') + | ||
byte.toString(16); | ||
if (index < data.length - 1) out += ','; | ||
if (nb == 15) { | ||
out += '\n '; | ||
nb = 0; | ||
} else { | ||
nb++; | ||
} | ||
}); | ||
|
||
//Check conversion | ||
if (fs.existsSync(distPath + "out.tmp")) { | ||
console.log(chalk.green("[ok]")); | ||
} else { | ||
console.log(chalk.red("[error]Conversion failed")); | ||
return; | ||
} | ||
out += '\n};\n'; | ||
fs.writeFileSync(distPath + 'out.tmp', out); | ||
|
||
//Format header file | ||
console.log(chalk.yellow("Building header")); | ||
fs.writeFileSync( | ||
distPath + "favicon.h", | ||
fs.readFileSync(srcPath + "header.txt") | ||
); | ||
let bin2cfile = fs.readFileSync(distPath + "out.tmp").toString(); | ||
fs.appendFileSync(distPath + "favicon.h", bin2cfile); | ||
fs.appendFileSync( | ||
distPath + "favicon.h", | ||
fs.readFileSync(srcPath + "footer.txt") | ||
); | ||
//Check conversion | ||
if (fs.existsSync(distPath + 'out.tmp')) { | ||
console.log(chalk.green('[ok]')); | ||
} else { | ||
console.log(chalk.red('[error]Conversion failed')); | ||
return; | ||
} | ||
|
||
//Check format result | ||
if (fs.existsSync(distPath + "favicon.h")) { | ||
console.log(chalk.green("[ok]")); | ||
} else { | ||
console.log(chalk.red("[error]Conversion failed")); | ||
return; | ||
} | ||
//Format header file | ||
console.log(chalk.yellow('Building header')); | ||
fs.writeFileSync( | ||
distPath + 'favicon.h', | ||
fs.readFileSync(srcPath + 'header.txt') | ||
); | ||
let bin2cfile = fs.readFileSync(distPath + 'out.tmp').toString(); | ||
fs.appendFileSync(distPath + 'favicon.h', bin2cfile); | ||
fs.appendFileSync( | ||
distPath + 'favicon.h', | ||
fs.readFileSync(srcPath + 'footer.txt') | ||
); | ||
|
||
//Move file to src | ||
console.log(chalk.yellow("Overwriting header in sources")); | ||
fs.writeFileSync(headerPath, fs.readFileSync(distPath + "favicon.h")); | ||
if (fs.existsSync(headerPath)) { | ||
console.log(chalk.green("[ok]")); | ||
} else { | ||
console.log(chalk.red("[error]Overwriting failed")); | ||
return; | ||
} | ||
//Check format result | ||
if (fs.existsSync(distPath + 'favicon.h')) { | ||
console.log(chalk.green('[ok]')); | ||
} else { | ||
console.log(chalk.red('[error]Conversion failed')); | ||
return; | ||
} | ||
|
||
} | ||
//Move file to src | ||
console.log(chalk.yellow('Overwriting header in sources')); | ||
fs.writeFileSync(headerPath, fs.readFileSync(distPath + 'favicon.h')); | ||
if (fs.existsSync(headerPath)) { | ||
console.log(chalk.green('[ok]')); | ||
} else { | ||
console.log(chalk.red('[error]Overwriting failed')); | ||
return; | ||
} | ||
}; | ||
|
||
|
||
// Create a gzip function for reusable purpose | ||
const compressFile = (filePath, targetPath) => { | ||
const stream = createReadStream(filePath); | ||
stream | ||
.pipe(createGzip(targetPath)) | ||
.pipe(createWriteStream(targetPath)) | ||
.on("finish", () =>{console.log(`Successfully compressed favicon.ico to ${targetPath}`);} | ||
); | ||
const stream = createReadStream(filePath); | ||
stream | ||
.pipe(createGzip(targetPath)) | ||
.pipe(createWriteStream(targetPath)) | ||
.on('finish', () => { | ||
console.log(`Successfully compressed favicon.ico to ${targetPath}`); | ||
}); | ||
}; | ||
|
||
compressFile(srcPath + "favicon.ico", destPath + "favicon.ico.gz"); | ||
compressFile(srcPath + 'favicon.ico', destPath + 'favicon.ico.gz'); | ||
fs.copyFileSync(distPath + 'index.html.gz', destPath + 'index.html.gz'); | ||
console.log(`Successfully copy index.html.gz at ${destPath}index.html.gz`); | ||
console.log(`Successfully copy index.html.gz at ${destPath}index.html.gz`); |
Oops, something went wrong.