Skip to content

Commit 5dc2eef

Browse files
first commit
0 parents  commit 5dc2eef

File tree

12 files changed

+4534
-0
lines changed

12 files changed

+4534
-0
lines changed

.editorconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
# Use 4 spaces for the Python files
13+
[*.py]
14+
indent_size = 4
15+
max_line_length = 80
16+
17+
# The JSON files contain newlines inconsistently
18+
[*.json]
19+
insert_final_newline = ignore
20+
21+
# Minified JavaScript files shouldn't be changed
22+
[**.min.js]
23+
indent_style = ignore
24+
insert_final_newline = ignore
25+
26+
# Makefiles always use tabs for indentation
27+
[Makefile]
28+
indent_style = tab
29+
30+
# Batch files use tabs for indentation
31+
[*.bat]
32+
indent_style = tab
33+
34+
[*.md]
35+
trim_trailing_whitespace = false
36+

.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true
5+
},
6+
7+
extends: [
8+
'standard',
9+
'@lancercomet/eslint-rules',
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:import/recommended',
12+
'plugin:import/typescript'
13+
],
14+
15+
parser: '@typescript-eslint/parser',
16+
17+
rules: {
18+
'@typescript-eslint/no-unused-vars': 'off'
19+
}
20+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
.vscode/
3+
node_modules/
4+
dist/
5+
src/**/*.js

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Everia
2+
3+
This is the plugin for [`everia.club`](https://everia.club). Still under construction.

build.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
3+
const assert = require('assert')
4+
const { execSync } = require('child_process')
5+
const fs = require('fs')
6+
const path = require('path')
7+
const archiver = require('archiver')
8+
const version = require('./package.json').version
9+
10+
const ARCHIVE_FILE_NAME = `everia.v${version}.zip`
11+
12+
main().catch(error => {
13+
console.error(`Error in main function: ${error}`)
14+
})
15+
16+
function deleteFolderRecursive (directory) {
17+
if (fs.existsSync(directory)) {
18+
for (const entry of fs.readdirSync(directory)) {
19+
const curPath = path.join(directory, entry)
20+
if (fs.lstatSync(curPath).isDirectory()) {
21+
deleteFolderRecursive(curPath)
22+
} else {
23+
fs.unlinkSync(curPath)
24+
}
25+
}
26+
fs.rmdirSync(directory)
27+
}
28+
}
29+
30+
async function main () {
31+
// Step 1: Execute tsc
32+
try {
33+
execSync('rollup -c')
34+
console.log('Lib build completed.')
35+
} catch (error) {
36+
console.error(`Error during tsc: ${error}`)
37+
return
38+
}
39+
40+
// Step 2: Copy files
41+
const filesToCopy = [
42+
['src/icon.png', 'dist/icon.png'],
43+
['src/package.json', 'dist/package.json'],
44+
['README.md', 'dist/README.md']
45+
]
46+
for (const [src, dist] of filesToCopy) {
47+
fs.copyFileSync(src, dist)
48+
}
49+
console.log('Files copied.')
50+
51+
// Step 3: Replace the version in src/package.json
52+
assert(version, 'Version in package.json must be provided.')
53+
let srcPackageFileContent = fs.readFileSync('dist/package.json', { encoding: 'utf-8' })
54+
srcPackageFileContent = srcPackageFileContent.replace('<VERSION>', version)
55+
fs.writeFileSync('dist/package.json', srcPackageFileContent, { encoding: 'utf-8' })
56+
console.log('Version has been written to dist/package.json: ' + version)
57+
58+
// Step 4: Zip files
59+
const output = fs.createWriteStream(`dist/${ARCHIVE_FILE_NAME}`)
60+
const archive = archiver('zip', {
61+
zlib: { level: 9 }
62+
})
63+
64+
archive.on('error', (err) => {
65+
throw err
66+
})
67+
68+
const archiveCompletion = new Promise((resolve, reject) => {
69+
output.on('close', resolve)
70+
output.on('error', reject)
71+
})
72+
73+
archive.pipe(output)
74+
75+
const filesToZip = ['icon.png', 'package.json', 'README.md', 'index.js']
76+
filesToZip.forEach(file => {
77+
archive.append(fs.createReadStream(`dist/${file}`), { name: file })
78+
})
79+
80+
await archive.finalize()
81+
82+
await archiveCompletion
83+
console.log('Files zipped.')
84+
85+
// Step 5: Delete all files in dist except package.zip
86+
const filesInDist = fs.readdirSync('dist')
87+
filesInDist.forEach(filename => {
88+
const filePath = path.resolve('dist', filename)
89+
if (filename !== ARCHIVE_FILE_NAME) {
90+
if (fs.lstatSync(filePath).isDirectory()) {
91+
deleteFolderRecursive(filePath)
92+
} else {
93+
fs.unlinkSync(filePath)
94+
}
95+
}
96+
})
97+
console.log('Other files in dist deleted.')
98+
}

0 commit comments

Comments
 (0)