Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
93e8393
Adding minifaction support for AngularJS, via ng-annotate.
YellowSharkMT Jul 17, 2017
de0e2d6
- Updating node-sass package, older version wasn't compiling on Ubunt…
YellowSharkMT Mar 16, 2018
0b863c7
Merge branch 'master' of https://github.com/bazzisoft/webmake
YellowSharkMT Feb 19, 2019
e4ccd73
- Bumping `node-sass` version to 4.11
YellowSharkMT Feb 19, 2019
5a33ad6
Adding dedicated exception for runtime warning.
YellowSharkMT Mar 20, 2019
6911333
Py 2/3: when opening files, use encoding='utf-8' for Py 3.
YellowSharkMT Apr 12, 2019
0617924
- Lists: adding migration to create/populate the ProductFieldDefiniti…
YellowSharkMT Jun 12, 2019
a1b9714
Merge branch 'master' of https://github.com/bazzisoft/webmake into up…
YellowSharkMT Nov 12, 2020
b0cd198
Restoring these modules to reflect current master / removing my alter…
YellowSharkMT Nov 12, 2020
9598e8d
Fixing post-merge issues with Angular annotations functionality.
YellowSharkMT Nov 12, 2020
05cd7cb
Adding an example/test file for the Angular annotations.
YellowSharkMT Nov 12, 2020
338af82
Deleting the /build directory, was accidentally committed.
YellowSharkMT Nov 12, 2020
6147e47
Adding Jetbrains project folder to the gitignore file.
YellowSharkMT Nov 12, 2020
e976a1a
Re-implementing the encoding kwargs for opening LESS files. This reso…
YellowSharkMT Nov 12, 2020
9e433c1
Merge branch 'master' of https://github.com/bazzisoft/webmake
YellowSharkMT Oct 23, 2021
3aab8b1
Remove the mangle arg from uglifyjs call
Oct 26, 2021
feb8326
Merge pull request #1 from bergantine/bergantine-patch-1
Oct 26, 2021
8a12812
Merge pull request #1 from bergantine/master
YellowSharkMT Oct 27, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__
/webmake.egg-info
/.project
/.pydevproject
/.idea
/tests/test_project/package-lock.json
/webmake/package-lock.json
/build
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def run(self):
# https://packaging.python.org/en/latest/requirements.html
install_requires=[
'watchdog>=0.8',
'six',
],

# List additional groups of dependencies here (e.g. development
Expand Down
3 changes: 3 additions & 0 deletions tests/test_project/webmakefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def custom_compiler(input_files, output_file, release):
# Minify standalone JS. Concatenates in debug mode, minifies in release mode.
api.minify_js(['www-dev/js/standalone.js'], 'www/js/standalone.js'),

# Minify AngularJS 1.x. Concatenates in debug mode, minifies and annotates Angular dependencies in release mode.
api.minify_js(['www-dev/angular-1.x/module.js'], 'www/angular-1.x/module.js', annotate_angular=True),

# Concatenate standalone files with no further processing.
api.concatenate(['www-dev/js/standalone.js'] * 2, 'www/js/standalone-x2.js'),

Expand Down
9 changes: 9 additions & 0 deletions tests/test_project/www-dev/angular-1.x/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module("WebmakeTest", [])
.factory("TestFactory", function () {
this.foo = function () {
alert("foo")
}
})
.controller("TestController", function (TestFactory) {
TestFactory.foo()
});
5 changes: 3 additions & 2 deletions webmake/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def copy_files(src_dir, dst_dir, filespec='*', recursive=False):
}


def minify_js(input_files, output_file):
def minify_js(input_files, output_file, annotate_angular=False):
"""
Minifies the input javascript files to the output file.

Expand All @@ -66,14 +66,15 @@ def minify_js(input_files, output_file):
In debug mode this function just concatenates the files
without minifying.
"""
from functools import partial
from .modules import minify, utils

if not isinstance(input_files, (list, tuple)):
raise RuntimeError('JS minifier takes a list of input files.')

return {
'dependencies_fn': utils.no_dependencies,
'compiler_fn': minify.minify_js,
'compiler_fn': partial(minify.minify_js, annotate_angular=annotate_angular),
'input': input_files,
'output': output_file,
'kwargs': {},
Expand Down
6 changes: 5 additions & 1 deletion webmake/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def pre_process(self, deployment_settings, *args, **kwargs):
BINFILE = POSSIBLE_BINFILES[0] if POSSIBLE_BINFILES else WEBMAKE_BIN


class WebmakeRuntimeWarning(RuntimeWarning):
pass


class WebmakeCompilerMiddleware:
def __init__(self, get_response=None):
self.get_response = get_response
Expand All @@ -53,7 +57,7 @@ def __call__(self, request):

def process_request(self, request):
if not settings.DEBUG:
warnings.warn('WebmakeCompilerMiddleware should not be used in production!', RuntimeWarning)
warnings.warn('WebmakeCompilerMiddleware should not be used in production!', WebmakeRuntimeWarning)

cmd = ' '.join([BINFILE, '-m', WEBMAKEFILE])
env = os.environ.copy()
Expand Down
7 changes: 5 additions & 2 deletions webmake/modules/concat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import six
from . import utils

FILE_HANDLE_KWARGS = {} if six.PY2 else dict(encoding='utf-8')


def _trimpath(path):
comps = []
Expand All @@ -24,9 +27,9 @@ def concatenate_input_files(input_files, output_file, release=False):

try:
utils.logv('>>> concat {} > {}'.format(' '.join(input_files), output_file))
with open(output_file, 'w') as output:
with open(output_file, 'w', **FILE_HANDLE_KWARGS) as output:
for input_file in input_files:
with open(input_file, 'r') as input:
with open(input_file, 'r', **FILE_HANDLE_KWARGS) as input:
output.write(input.read())

if not release:
Expand Down
1 change: 0 additions & 1 deletion webmake/modules/copyfiles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import shutil
from fnmatch import fnmatch
from . import utils
Expand Down
2 changes: 1 addition & 1 deletion webmake/modules/less.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def _read_less_imports(file):
deps = []
with open(file) as f:
with open(file, encoding='utf-8') as f:
less = f.read()
imports = LESS_IMPORT_RE.findall(less)
less_dir = os.path.dirname(file)
Expand Down
30 changes: 28 additions & 2 deletions webmake/modules/minify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
from . import utils, concat


def minify_js(input_files, output_file, release=False):
def minify_js(input_files, output_file, release=False, annotate_angular=False):
assert isinstance(input_files, (list, tuple))

if not release:
concat.concatenate_input_files(input_files, output_file, release=release)
return

if annotate_angular:
# Rather than annotate several individual files (and having to creating temp files as well), it's
# easier to just concatenate the input_files right now, and then perform the annotation upon that
# one file. We must then update the `input_files` value accordingly, so that it gets passed into
# uglify correctly.
concat.concatenate_input_files(input_files, output_file, release=release)
input_files = [output_file]
try:
annotate_angular_injections(output_file, output_file)
except:
utils.ensure_deleted(output_file)
raise

if output_file:
utils.ensure_path_exists(os.path.dirname(output_file))

cmdline = [
utils.get_node_bin_path('uglify-es', 'bin', 'uglifyjs'),
'--compress',
'--mangle',
'-o',
output_file,
'--',
Expand All @@ -28,6 +40,20 @@ def minify_js(input_files, output_file, release=False):
utils.ensure_deleted(output_file)
raise

def annotate_angular_injections(input_file, output_file):
cmdline = [
os.path.join(utils.get_node_bin_path('ng-annotate'), 'ng-annotate.js'),
'--add',
'-o',
output_file,
]
cmdline.extend([input_file])

try:
utils.run_command(cmdline, 'Failed to annotate Angular injections to "{}"'.format(output_file), with_node=True)
except Exception as e:
utils.ensure_deleted(output_file)
raise

def minify_css(input_files, output_file, release=False):
assert isinstance(input_files, (list, tuple))
Expand Down
1 change: 1 addition & 0 deletions webmake/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"browserify": "^9.0.8",
"cssmin": "^0.4.3",
"less": "^2.7.3",
"ng-annotate": "1.x",
"node-sass": "^4.12.0",
"uglify-es": "^3.3.9"
}
Expand Down