Removed compressor, gulp, grunt and webpack

This commit is contained in:
Mazdak Badakhshan 2016-07-02 02:00:40 +04:30
parent 02ce5b4250
commit bb75251864
16 changed files with 4 additions and 534 deletions

View File

@ -134,58 +134,6 @@ def remove_docker_files():
PROJECT_DIRECTORY, "compose" PROJECT_DIRECTORY, "compose"
)) ))
def remove_grunt_files():
"""
Removes files needed for grunt if it isn't going to be used
"""
for filename in ["Gruntfile.js"]:
os.remove(os.path.join(
PROJECT_DIRECTORY, filename
))
def remove_gulp_files():
"""
Removes files needed for grunt if it isn't going to be used
"""
for filename in ["gulpfile.js"]:
os.remove(os.path.join(
PROJECT_DIRECTORY, filename
))
def remove_packageJSON_file():
"""
Removes files needed for grunt if it isn't going to be used
"""
for filename in ["package.json"]:
os.remove(os.path.join(
PROJECT_DIRECTORY, filename
))
def add_webpack():
"""
Adds webpack configuration using cookiecutter to install hzdg/cookiecutter-webpack
"""
cookiecutter(
'https://github.com/hzdg/cookiecutter-webpack.git',
replay=False, overwrite_if_exists=True, output_dir='../',
checkout='pydanny-django', no_input=True, extra_context={
'project_name': '{{ cookiecutter.project_name }}',
'repo_name': '{{ cookiecutter.project_slug }}',
'repo_owner': '',
'project_dir': '{{ cookiecutter.project_slug }}',
'static_root': '{{ cookiecutter.project_slug }}/static/{{ cookiecutter.project_slug }}',
'production_output_path': '{{ cookiecutter.project_slug }}/static/{{ cookiecutter.project_slug }}/dist/',
'author_name': '{{ cookiecutter.author_name }}',
'description': '{{ cookiecutter.description }}',
'version': '{{ cookiecutter.version }}',
'existing_project': 'y',
'css_extension': 'sass',
'use_ejs': 'n',
'open_source_license': '{{ cookiecutter.open_source_license }}'
})
def remove_certbot_files(): def remove_certbot_files():
""" """
Removes files needed for certbot if it isn't going to be used Removes files needed for certbot if it isn't going to be used
@ -241,35 +189,11 @@ if '{{ cookiecutter.use_heroku }}'.lower() != 'y':
if '{{ cookiecutter.use_docker }}'.lower() != 'y': if '{{ cookiecutter.use_docker }}'.lower() != 'y':
remove_docker_files() remove_docker_files()
# 6. Removes all JS task manager files if it isn't going to be used
if '{{ cookiecutter.js_task_runner}}'.lower() == 'gulp':
remove_grunt_files()
elif '{{ cookiecutter.js_task_runner}}'.lower() == 'grunt':
remove_gulp_files()
elif '{{ cookiecutter.js_task_runner }}'.lower() == 'webpack':
remove_gulp_files()
remove_grunt_files()
remove_packageJSON_file()
add_webpack()
else:
remove_gulp_files()
remove_grunt_files()
remove_packageJSON_file()
# 7. Removes all certbot/letsencrypt files if it isn't going to be used # 7. Removes all certbot/letsencrypt files if it isn't going to be used
if '{{ cookiecutter.use_lets_encrypt }}'.lower() != 'y': if '{{ cookiecutter.use_lets_encrypt }}'.lower() != 'y':
remove_certbot_files() remove_certbot_files()
# 8. Display a warning if use_docker and use_grunt are selected. Grunt isn't # 8. Removes the certbot/letsencrypt files and display a warning if use_lets_encrypt is selected and use_docker isn't.
# supported by our docker config atm.
if '{{ cookiecutter.js_task_runner }}'.lower() in ['grunt', 'gulp'] and '{{ cookiecutter.use_docker }}'.lower() == 'y':
print(
"You selected to use docker and a JS task runner. This is NOT supported out of the box for now. You "
"can continue to use the project like you normally would, but you will need to add a "
"js task runner service to your docker configuration manually."
)
# 9. Removes the certbot/letsencrypt files and display a warning if use_lets_encrypt is selected and use_docker isn't.
if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y': if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() != 'y':
remove_certbot_files() remove_certbot_files()
print( print(
@ -277,14 +201,14 @@ if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use
"can continue to use the project like you normally would, but Let's Encrypt files have been included." "can continue to use the project like you normally would, but Let's Encrypt files have been included."
) )
# 10. Directs the user to the documentation if certbot and docker are selected. # 9. Directs the user to the documentation if certbot and docker are selected.
if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y': if '{{ cookiecutter.use_lets_encrypt }}'.lower() == 'y' and '{{ cookiecutter.use_docker }}'.lower() == 'y':
print( print(
"You selected to use Let's Encrypt, please see the documentation for instructions on how to use this in production. " "You selected to use Let's Encrypt, please see the documentation for instructions on how to use this in production. "
"You must generate a dhparams.pem file before running docker-compose in a production environment." "You must generate a dhparams.pem file before running docker-compose in a production environment."
) )
# 11. Removes files needed for the GPLv3 licence if it isn't going to be used. # 10. Removes files needed for the GPLv3 licence if it isn't going to be used.
if '{{ cookiecutter.open_source_license}}' != 'GPLv3': if '{{ cookiecutter.open_source_license}}' != 'GPLv3':
remove_copying_files() remove_copying_files()

View File

@ -1,138 +0,0 @@
module.exports = function (grunt) {
var appConfig = grunt.file.readJSON('package.json');
// Load grunt tasks automatically
// see: https://github.com/sindresorhus/load-grunt-tasks
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
// see: https://npmjs.org/package/time-grunt
require('time-grunt')(grunt);
var pathsConfig = function (appName) {
this.app = appName || appConfig.name;
return {
app: this.app,
templates: this.app + '/templates',
css: this.app + '/static/css',
sass: this.app + '/static/sass',
fonts: this.app + '/static/fonts',
images: this.app + '/static/images',
js: this.app + '/static/js',
manageScript: 'manage.py',
}
};
grunt.initConfig({
paths: pathsConfig(),
pkg: appConfig,
// see: https://github.com/gruntjs/grunt-contrib-watch
watch: {
gruntfile: {
files: ['Gruntfile.js']
},
sass: {
files: ['<%= paths.sass %>/**/*.{scss,sass}'],
tasks: ['sass:dev'],
options: {
atBegin: true
}
},
livereload: {
files: [
'<%= paths.js %>/**/*.js',
'<%= paths.sass %>/**/*.{scss,sass}',
'<%= paths.app %>/**/*.html'
],
options: {
spawn: false,
livereload: true,
},
},
},
// see: https://github.com/sindresorhus/grunt-sass
sass: {
dev: {
options: {
outputStyle: 'nested',
sourceMap: false,
precision: 10
},
files: {
'<%= paths.css %>/project.css': '<%= paths.sass %>/project.scss'
},
},
dist: {
options: {
outputStyle: 'compressed',
sourceMap: false,
precision: 10
},
files: {
'<%= paths.css %>/project.css': '<%= paths.sass %>/project.scss'
},
}
},
//see https://github.com/nDmitry/grunt-postcss
postcss: {
options: {
map: true, // inline sourcemaps
processors: [
require('pixrem')(), // add fallbacks for rem units
require('autoprefixer-core')({browsers: [
'Android 2.3',
'Android >= 4',
'Chrome >= 20',
'Firefox >= 24',
'Explorer >= 8',
'iOS >= 6',
'Opera >= 12',
'Safari >= 6'
]}), // add vendor prefixes
require('cssnano')() // minify the result
]
},
dist: {
src: '<%= paths.css %>/*.css'
}
},
// see: https://npmjs.org/package/grunt-bg-shell
bgShell: {
_defaults: {
bg: true
},
runDjango: {
cmd: 'python <%= paths.manageScript %> runserver'
},
{% if cookiecutter.use_mailhog == "y" and cookiecutter.use_docker == 'n' -%}runMailHog: {
cmd: './mailhog'
},{%- endif %}
}
});
grunt.registerTask('serve', [
{% if cookiecutter.use_mailhog == "y" and cookiecutter.use_docker == 'n' -%}
'bgShell:runMailHog',
{%- endif %}
'bgShell:runDjango',
'watch'
]);
grunt.registerTask('build', [
'sass:dist',
'postcss'
]);
grunt.registerTask('default', [
'build'
]);
};

View File

@ -35,7 +35,6 @@ DJANGO_APPS = (
'django.contrib.admin', 'django.contrib.admin',
) )
THIRD_PARTY_APPS = ( THIRD_PARTY_APPS = (
'crispy_forms', # Form layouts
'allauth', # registration 'allauth', # registration
'allauth.account', # registration 'allauth.account', # registration
'allauth.socialaccount', # registration 'allauth.socialaccount', # registration
@ -164,9 +163,6 @@ TEMPLATES = [
}, },
] ]
# See: http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# STATIC FILE CONFIGURATION # STATIC FILE CONFIGURATION
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
@ -234,27 +230,7 @@ BROKER_URL = env('CELERY_BROKER_URL', default='django://')
########## END CELERY ########## END CELERY
{% endif %} {% endif %}
# django-compressor
# ------------------------------------------------------------------------------
{% if cookiecutter.use_compressor == 'y'-%}
INSTALLED_APPS += ("compressor", )
STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", )
{%- endif %}
# Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %} # Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
ADMIN_URL = r'^admin/' ADMIN_URL = r'^admin/'
{% if cookiecutter.js_task_runner == 'Webpack' %}
# WEBPACK
# ------------------------------------------------------------------------------
INSTALLED_APPS += ('webpack_loader',)
# Webpack Local Stats file
STATS_FILE = ROOT_DIR('webpack-stats.json')
# Webpack config
WEBPACK_LOADER = {
'DEFAULT': {
'STATS_FILE': STATS_FILE
}
}
{% endif %}
# Your common stuff: Below this line define 3rd party library settings # Your common stuff: Below this line define 3rd party library settings

View File

@ -301,21 +301,8 @@ LOGGING = {
} }
} }
{% endif %} {% endif %}
# Custom Admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %} # Custom Admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
ADMIN_URL = env('DJANGO_ADMIN_URL') ADMIN_URL = env('DJANGO_ADMIN_URL')
{% if cookiecutter.js_task_runner == 'Webpack' %}
# WEBPACK
# ------------------------------------------------------------------------------
# Webpack Production Stats file
STATS_FILE = ROOT_DIR('webpack-stats-production.json')
# Webpack config
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': '{{ cookiecutter.project_slug }}/static/{{ cookiecutter.project_slug }}/dist/',
'STATS_FILE': STATS_FILE
}
}
{% endif %}
# Your production stuff: Below this line define 3rd party library settings # Your production stuff: Below this line define 3rd party library settings

View File

@ -9,9 +9,6 @@ from django.views.generic import TemplateView
from django.views import defaults as default_views from django.views import defaults as default_views
urlpatterns = [ urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'),
# Django Admin, use {% raw %}{% url 'admin:index' %}{% endraw %} # Django Admin, use {% raw %}{% url 'admin:index' %}{% endraw %}
url(settings.ADMIN_URL, include(admin.site.urls)), url(settings.ADMIN_URL, include(admin.site.urls)),

View File

@ -30,7 +30,4 @@ DJANGO_SENTRY_DSN=
DJANGO_OPBEAT_ORGANIZATION_ID DJANGO_OPBEAT_ORGANIZATION_ID
DJANGO_OPBEAT_APP_ID DJANGO_OPBEAT_APP_ID
DJANGO_OPBEAT_SECRET_TOKEN DJANGO_OPBEAT_SECRET_TOKEN
{% endif %}
{% if cookiecutter.use_compressor == 'y' -%}
COMPRESS_ENABLED=
{% endif %} {% endif %}

View File

@ -1,107 +0,0 @@
////////////////////////////////
//Setup//
////////////////////////////////
// Plugins
var gulp = require('gulp'),
pjson = require('./package.json'),
gutil = require('gulp-util'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
rename = require('gulp-rename'),
del = require('del'),
plumber = require('gulp-plumber'),
pixrem = require('gulp-pixrem'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
exec = require('gulp-exec'),
runSequence = require('run-sequence'),
browserSync = require('browser-sync');
// Relative paths function
var pathsConfig = function (appName) {
this.app = "./" + (appName || pjson.name);
return {
app: this.app,
templates: this.app + '/templates',
css: this.app + '/static/css',
sass: this.app + '/static/sass',
fonts: this.app + '/static/fonts',
images: this.app + '/static/images',
js: this.app + '/static/js',
}
};
var paths = pathsConfig();
////////////////////////////////
//Tasks//
////////////////////////////////
// Styles autoprefixing and minification
gulp.task('styles', function() {
return gulp.src(paths.sass + '/project.scss')
.pipe(sass().on('error', sass.logError))
.pipe(plumber()) // Checks for errors
.pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes
.pipe(pixrem()) // add fallbacks for rem units
.pipe(gulp.dest(paths.css))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano()) // Minifies the result
.pipe(gulp.dest(paths.css));
});
// Javascript minification
gulp.task('scripts', function() {
return gulp.src(paths.js + '/project.js')
.pipe(plumber()) // Checks for errors
.pipe(uglify()) // Minifies the js
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.js));
});
// Image compression
gulp.task('imgCompression', function(){
return gulp.src(paths.images + '/*')
.pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images
.pipe(gulp.dest(paths.images))
});
// Run django server
gulp.task('runServer', function() {
exec('python manage.py runserver', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
});
});
// Browser sync server for live reload
gulp.task('browserSync', function() {
browserSync.init(
[paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], {
proxy: "localhost:8000"
});
});
// Default task
gulp.task('default', function() {
runSequence(['styles', 'scripts', 'imgCompression'], 'runServer', 'browserSync');
});
////////////////////////////////
//Watch//
////////////////////////////////
// Watch
gulp.task('watch', ['default'], function() {
gulp.watch(paths.sass + '/*.scss', ['styles']);
gulp.watch(paths.js + '/*.js', ['scripts']);
gulp.watch(paths.images + '/*', ['imgCompression']);
gulp.watch('templates/*.html');
});

View File

@ -1,38 +0,0 @@
{
"name": "{{cookiecutter.project_slug}}",
"version": "{{ cookiecutter.version }}",
"dependencies": {},
"devDependencies": {
{% if cookiecutter.js_task_runner == 'Grunt' %}
"autoprefixer-core": "~5.2.1",
"connect-livereload": "~0.3.2",
"cssnano": "~2.1.0",
"grunt": "~0.4.5",
"grunt-bg-shell": "~2.3.1",
"grunt-contrib-watch": "~0.6.1",
"grunt-postcss": "~0.5.5",
"grunt-sass": "~1.0.0",
"load-grunt-tasks": "~3.2.0",
"pixrem": "~1.3.1",
"time-grunt": "~1.2.1"
{% elif cookiecutter.js_task_runner == 'Gulp' %}
"browser-sync": "^2.12.10",
"del": "^2.2.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.0",
"gulp-cssnano": "^2.1.2",
"gulp-exec": "^2.1.2",
"gulp-imagemin": "^3.0.1",
"gulp-pixrem": "^1.0.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.1",
"gulp-uglify": "^1.5.3",
"gulp-util": "^3.0.7",
"run-sequence": "^1.2.1"
{% endif %}
},
"engines": {
"node": ">=0.8.0"
}
}

View File

@ -15,12 +15,6 @@ django-environ==0.4.0
whitenoise==3.2 whitenoise==3.2
{%- endif %} {%- endif %}
# Forms
django-braces==1.9.0
django-crispy-forms==1.6.0
django-floppyforms==1.6.2
# Models # Models
django-model-utils==2.5 django-model-utils==2.5
@ -54,13 +48,4 @@ redis>=2.10.0
celery==3.1.23 celery==3.1.23
{% endif %} {% endif %}
{% if cookiecutter.use_compressor == "y" %}
django_compressor==2.0
{% endif %}
{% if cookiecutter.js_task_runner == 'Webpack' -%}
# Webpack
django-webpack-loader==0.3.0
{%- endif %}
# Your custom requirements go here # Your custom requirements go here

View File

@ -1,38 +0,0 @@
/* These styles are generated from project.scss. */
.alert-debug {
color: black;
background-color: white;
border-color: #d6e9c6;
}
.alert-error {
color: #b94a48;
background-color: #f2dede;
border-color: #eed3d7;
}
/* This is a fix for the bootstrap4 alpha release */
@media (max-width: 47.9em) {
.navbar-nav .nav-item {
float: none;
width: 100%;
display: inline-block;
}
.navbar-nav .nav-item + .nav-item {
margin-left: 0;
}
.nav.navbar-nav.pull-xs-right {
float: none !important;
}
}
/* Display django-debug-toolbar.
See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742
and https://github.com/pydanny/cookiecutter-django/issues/317
*/
[hidden][style="display: block;"] {
display: block !important;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -1 +0,0 @@
/* Project specific Javascript goes here. */

View File

@ -1,72 +0,0 @@
// project specific CSS goes here
////////////////////////////////
//Variables//
////////////////////////////////
// Alert colors
$white: #fff;
$mint-green: #d6e9c6;
$black: #000;
$pink: #f2dede;
$dark-pink: #eed3d7;
$red: #b94a48;
////////////////////////////////
//Alerts//
////////////////////////////////
// bootstrap alert CSS, translated to the django-standard levels of
// debug, info, success, warning, error
.alert-debug {
background-color: $white;
border-color: $mint-green;
color: $black;
}
.alert-error {
background-color: $pink;
border-color: $dark-pink;
color: $red;
}
////////////////////////////////
//Navbar//
////////////////////////////////
// This is a fix for the bootstrap4 alpha release
.navbar {
border-radius: 0px;
}
@media (max-width: 47.9em) {
.navbar-nav .nav-item {
display: inline-block;
float: none;
width: 100%;
}
.navbar-nav .nav-item + .nav-item {
margin-left: 0;
}
.nav.navbar-nav.pull-xs-right {
float: none !important;
}
}
////////////////////////////////
//Django Toolbar//
////////////////////////////////
// Display django-debug-toolbar.
// See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742
// and https://github.com/pydanny/cookiecutter-django/issues/317
[hidden][style="display: block;"] {
display: block !important;
}

View File

@ -1 +0,0 @@
{% raw %}{% extends "base.html" %}{% endraw %}

View File

@ -1 +0,0 @@
{% raw %}{% extends "base.html" %}{% endraw %}