Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ESLint and PrettierJS #2726

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/eslint_csslint_jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@ jobs:
run: npm install --force

- name: Run eslint
run: npx eslint --config=tests/eslint_rules.config.mjs
run: npm run lint
continue-on-error: true

# - name: Run JSLint
# run: npx jslint "**/*.js"
# continue-on-error: true

- name: Run Jest
run: npx jest # --config=tests/jest.config.js

- name: Run npm test
run: npm test

- name: Install csslint using npm
run: npm install -g [email protected]
# - name: Install csslint using npm
# run: npm install -g [email protected]

# - name: Lint CSS files
# run: |
# for file in $(grep -rl --include='*.css' '' ./); do npx csslint --config tests/csslint_rules.json "$file"; done


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build/__pycache__
tmp
201 changes: 89 additions & 112 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,162 +5,139 @@
# >>> TABLE OF CONTENTS:
#---------------------------------------------------------------
# 1.0 Import modules
# 2.0 Chromium
# 3.0 Firefox
# 4.0 Initialization
# 2.0 Variables and helper functions
# 3.0 Chromium
# 4.0 Firefox
# 5.0 Initialization
#---------------------------------------------------------------

#---------------------------------------------------------------
# 1.0 IMPORT MODULES
#---------------------------------------------------------------

import shutil
import sys
import argparse
import json
import os
import pathlib
import re
import zipfile


#---------------------------------------------------------------
# 2.0 CHROMIUM
# 2.0 VARIABLES AND HELPER FUNCTIONS
#---------------------------------------------------------------

def chromium(browser):
temporary_path = '../cached'

if (os.path.isdir(temporary_path)):
shutil.rmtree(temporary_path, ignore_errors=True)
excluded = {
'.git', '.github',
# 'README.md', 'LICENSE', 'CONTRIBUTING.md',
'tmp', 'node_modules', 'config', 'package-lock.json', 'package.json', 'tests', 'build'
}

os.mkdir(temporary_path)
os.chdir(temporary_path)
temp_path = '../tmp'

for item in os.listdir('../'):
if (
item != '.git' and
item != '.github' and
item != 'cached' and
item != 'previews' and
item != 'py' and
item != 'wiki' and
item != 'LICENSE' and
item != 'README.md' and
item != 'SECURITY.md' and
item.find('.zip') == -1
):
s = os.path.join('../', item)
d = os.path.join(temporary_path, item)
if os.path.isdir(s):
shutil.copytree(s, d, True, None)
else:
shutil.copy2(s, d)
def parse_args():
parser = argparse.ArgumentParser(
prog='build.py',
description='Build the extension for use in the browser')

with open('manifest.json', 'r+') as json_file:
data = json.load(json_file)
parser.add_argument('-b', '--browser', default='chromium')
parser.add_argument('-m', '--manifest', type=int, default=3)

version = data['version']
return parser.parse_args()

if (browser == 'beta'):
data['name'] = 'ImprovedTube (testing)';
def copy_src_to_tmp():
if (os.path.isdir(temp_path)):
shutil.rmtree(temp_path, ignore_errors=True)

json_file.seek(0)
json.dump(data, json_file, indent=4, sort_keys=True)
json_file.truncate()
os.mkdir(temp_path)
os.chdir(temp_path)

archive = zipfile.ZipFile('../chromium-' + version + '.zip', 'w', zipfile.ZIP_DEFLATED)
for item in os.listdir('../'):
if item not in excluded and item.find('.zip') == -1:
src = os.path.join('../', item)
dst = os.path.join(temp_path, item)
if os.path.isdir(src):
shutil.copytree(src, dst, True, None)
else:
shutil.copy2(src, dst)

for root, dirs, files in os.walk('.'):
for file in files:
archive.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join('.', '.')))

archive.close()
shutil.rmtree(temporary_path)
def archive_zip(name):
archive = zipfile.ZipFile('../' + name + '.zip', 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk('.'):
for file in files:
archive.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join('.', '.')))
archive.close()


#---------------------------------------------------------------
# 3.0 FIREFOX
# 3.0 CHROMIUM
#---------------------------------------------------------------

def firefox():
temporary_path = '../cached'
def chromium(manifest_version):
copy_src_to_tmp()
if manifest_version == 2:
shutil.copy2('../build/manifest2.json', './manifest.json')

with open('manifest.json', 'r+') as json_file:
data = json.load(json_file)

if (os.path.isdir(temporary_path)):
shutil.rmtree(temporary_path, ignore_errors=True)
version = data['version']

os.mkdir(temporary_path)
os.chdir(temporary_path)
json_file.seek(0)
json.dump(data, json_file, indent=4, sort_keys=True)
json_file.truncate()

for item in os.listdir('../'):
if (
item != '.git' and
item != '.github' and
item != 'cached' and
item != 'previews' and
item != 'py' and
item != 'wiki' and
item != 'LICENSE' and
item != 'README.md' and
item != 'SECURITY.md' and
item.find('.zip') == -1
):
s = os.path.join('../', item)
d = os.path.join(temporary_path, item)
if os.path.isdir(s):
shutil.copytree(s, d, True, None)
else:
shutil.copy2(s, d)
archive_zip('chromium-' + version)
shutil.rmtree(temp_path)

with open('background.js', 'r') as file:
lines = file.readlines()

with open('background.js', 'w') as file:
skip = False
#---------------------------------------------------------------
# 4.0 FIREFOX
#---------------------------------------------------------------

for pos, line in enumerate(lines):
if (lines[pos].find('8.0 GOOGLE ANALYTICS') != -1):
skip = True
def firefox(manifest_version):
copy_src_to_tmp()
shutil.copy2('../build/manifest3Firefox.json', './manifest.json')

if (skip == False):
file.write(line)
with open('background.js', 'r') as file:
lines = file.readlines()

if (line.find('/*--------------------------------------------------------------') != -1):
skip = False
with open('background.js', 'w') as file:
skip = False

with open('manifest.json', 'r+') as json_file:
data = json.load(json_file)
for pos, line in enumerate(lines):
if (lines[pos].find('8.0 GOOGLE ANALYTICS') != -1):
skip = True

version = data['version']
if (skip == False):
file.write(line)

del data['content_security_policy']
del data['update_url']
if (line.find('/*--------------------------------------------------------------') != -1):
skip = False

json_file.seek(0)
json.dump(data, json_file, indent=4, sort_keys=True)
json_file.truncate()
with open('manifest.json', 'r+') as json_file:
data = json.load(json_file)

archive = zipfile.ZipFile('../firefox-' + version + '.zip', 'w', zipfile.ZIP_DEFLATED)
version = data['version']

for root, dirs, files in os.walk('.'):
for file in files:
archive.write(os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join('.', '.')))
del data['content_security_policy']
del data['update_url']

archive.close()
shutil.rmtree(temporary_path)
json_file.seek(0)
json.dump(data, json_file, indent=4, sort_keys=True)
json_file.truncate()

archive_zip('firefox-' + version)
shutil.rmtree(temp_path)


#---------------------------------------------------------------
# 4.0 INITIALIZATION
# 5.0 INITIALIZATION
#---------------------------------------------------------------

for arg in sys.argv:
if arg == '-chromium-stable':
chromium('stable')
elif arg == '-chromium-beta':
chromium('beta')
elif arg == '-firefox':
firefox()
arg = parse_args()

if arg.browser == 'chromium':
chromium(arg.manifest)
elif arg.browser == 'firefox':
firefox(arg.manifest)
Loading
Loading