Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #482 from cmc333333/package-files
Browse files Browse the repository at this point in the history
Include templates, static files in python distro
  • Loading branch information
anthonygarvan committed Feb 9, 2017
2 parents 0ba4a44 + eb101e7 commit 55695b1
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module.exports = function toExport(grunt) {
plugin: [
[function minifyify(b) {
b.plugin('minifyify', {
map: '/static/regulations/js/built/regulations.min.map',
map: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
output: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
});
}],
Expand Down
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include CONTRIBUTING.md
include TERMS.md
include COPYING.txt
include README.md
graft regulations/templates
graft regulations/static
graft regulations/frontend-config
27 changes: 7 additions & 20 deletions regulations/management/commands/compile_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from django.contrib.staticfiles.finders import get_finders
from django.contrib.staticfiles.storage import StaticFilesStorage

import regulations


"""
This command compiles the frontend for regulations-site after using the Django
Expand Down Expand Up @@ -38,11 +36,6 @@ def add_arguments(self, parser):
action='store_false')
parser.set_defaults(install=True)

def find_regulations_directory(self):
child = regulations.__file__
child_dir = os.path.split(child)[0]
return os.path.split(child_dir)[0] or "." # if regulations is local

def remove_dirs(self):
"""Remove existing output dirs"""
if os.path.exists(self.TARGET_DIR):
Expand All @@ -62,17 +55,11 @@ def remove_dirs(self):
else:
os.mkdir(self.BUILD_DIR)

def copy_configs(self):
"""Copy over configs from regulations"""
regulations_directory = self.find_regulations_directory()
frontend_files = (
"package.json",
"Gruntfile.js",
".eslintrc"
)
for f_file in frontend_files:
source = "%s/%s" % (regulations_directory, f_file)
shutil.copy(source, "%s/" % self.BUILD_DIR)
def create_configs(self):
for config_file in ('Gruntfile.js', 'package.json', '.babelrc'):
os.rename(os.path.join(self.BUILD_DIR, 'static', 'config',
config_file),
os.path.join(self.BUILD_DIR, config_file))
with codecs.open("%s/config.json" % self.BUILD_DIR, "w",
encoding="utf-8") as f:
f.write('{"frontEndPath": "static/regulations"}')
Expand All @@ -81,7 +68,7 @@ def _input_files(self):
"""Fetch all of the static files from the installed apps. Yield them
as pairs of (path, file)"""
files_seen = set()
pairs = (pr for finder in get_finders() for pr in finder.list([".*"]))
pairs = (pr for finder in get_finders() for pr in finder.list([]))
for path, storage in pairs:
# Prefix the relative path if the source storage contains it
if getattr(storage, 'prefix', None):
Expand Down Expand Up @@ -122,7 +109,7 @@ def cleanup(self):

def handle(self, **options):
self.remove_dirs()
self.copy_configs()
self.collect_files()
self.create_configs()
self.build_frontend(install=options['install'], dev=settings.JS_DEBUG)
self.cleanup()
6 changes: 6 additions & 0 deletions regulations/static/config/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"es2015",
"react"
]
}
162 changes: 162 additions & 0 deletions regulations/static/config/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
module.exports = function toExport(grunt) {
grunt.initConfig({

/**
* Pull in the package.json file so we can read its metadata.
*/
pkg: grunt.file.readJSON('package.json'),

/**
*
* Pull in config-specific vars
*
*/
config: grunt.file.readJSON('config.json'),

env: {
dev: {
NODE_ENV: 'development',
},
dist: {
NODE_ENV: 'production',
},
},

/**
* Copy dependencies into static paths
*/
copy: {
main: {
files: [
{
expand: true,
flatten: true,
src: ['node_modules/respond.js/dest/*'],
dest: '<%= config.frontEndPath %>/js/built/lib/respond/',
filter: 'isFile',
},
],
},
},

/**
* https://github.com/gruntjs/grunt-contrib-sass
*/
sass: {
dev: {
options: {
style: 'expanded',
},
files: {
'<%= config.frontEndPath %>/css/style.css': '<%= config.frontEndPath %>/css/scss/main.scss',
},
},
},

/**
* CSSMin: https://github.com/gruntjs/grunt-contrib-cssmin
*
* Minify CSS for production
*/
cssmin: {
target: {
files: {
'<%= config.frontEndPath %>/css/regulations.min.css': ['<%= config.frontEndPath %>/css/style.css'],
},
},
},
/**
* ESLint: https://github.com/sindresorhus/grunt-eslint
*
* Validate files with ESLint.
*/
eslint: {
target: [
'Gruntfile.js',
'<%= config.frontEndPath %>/js/source/*.js',
'<%= config.frontEndPath %>/js/source/events/**/*.js',
'<%= config.frontEndPath %>/js/source/models/**/*.js',
'<%= config.frontEndPath %>/js/source/views/**/*.js',
'<%= config.frontEndPath %>/js/source/views/**/*.jsx',
],
},

/**
* Browserify:
*
* Require('modules') in the browser/bundle up dependencies.
*/
browserify: {
dev: {
files: {
'<%= config.frontEndPath %>/js/built/regulations.js': ['<%= config.frontEndPath %>/js/source/regulations.js', '<%= config.frontEndPath %>/js/source/regulations.js'],
},
options: {
transform: ['babelify', 'browserify-shim'],
browserifyOptions: {
debug: true,
},
},
},
dist: {
files: {
'<%= config.frontEndPath %>/js/built/regulations.min.js': ['<%= config.frontEndPath %>/js/source/regulations.js'],
},
options: {
transform: ['babelify', 'browserify-shim'],
browserifyOptions: {
debug: true,
extensions: ['.js', '.jsx'],
},
plugin: [
[function minifyify(b) {
b.plugin('minifyify', {
map: '/static/regulations/js/built/regulations.min.map',
output: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
});
}],
],
},
},
},

mocha_istanbul: {
coverage: {
src: ['<%= config.frontEndPath %>/js/unittests/specs/**/*.js'],
options: {
root: '<%= config.frontEndPath %>/js',
scriptPath: require.resolve('isparta/lib/cli'),
istanbulOptions: ['--include-all-sources'],
mochaOptions: ['--compilers', 'js:babel-register'],
nodeExec: require.resolve('.bin/babel-node'),
coverageFolder: '<%= config.frontEndPath %>/js/unittests/coverage',
coverage: false,
},
},
},
});

/* eslint-disable global-require,import/no-extraneous-dependencies */
grunt.event.on('coverage', (lcov, done) => {
require('coveralls').handleInput(lcov, (err) => {
if (err) {
done(err);
}
done();
});
});
/**
* The above tasks are loaded here.
*/
require('load-grunt-tasks')(grunt);
/* eslint-enable */

/**
* Create task aliases by registering new tasks
*/
grunt.registerTask('test', ['eslint', 'mocha_istanbul']);
grunt.registerTask('test-js', ['eslint', 'mocha_istanbul']);
grunt.registerTask('build-dev', ['env:dev', 'copy', 'browserify:dev', 'sass']);
grunt.registerTask('build-dist', ['env:dist', 'copy', 'browserify:dist', 'sass', 'cssmin']);
grunt.registerTask('default', ['build-dist']);
};
101 changes: 101 additions & 0 deletions regulations/static/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"name": "regulations-site",
"version": "7.0.0",
"homepage": "https://eregs.github.io/",
"contributors": [
{
"name": "Consumer Financial Protection Bureau",
"url": "http://cfpb.github.io/"
},
{
"name": "18F",
"url": "https://18f.gsa.gov/"
}
],
"repository": {
"type": "git",
"url": "http://github.com/eregs/regulations-site.git"
},
"bugs": {
"url": "http://github.com/eregs/regulations-site/issues"
},
"licenses": [
{
"type": "Public Domain",
"url": "http://github.com/eregs/regulations-site/blob/master/TERMS.md"
}
],
"engines": {
"node": "6.9.2"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babelify": "^7.3.0",
"browserify": "^13.0.0",
"browserify-shim": "^3.8.12",
"chai": "^3.5.0",
"coveralls": "^2.11.2",
"deamdify": "^0.1.1",
"eslint": "^3.12.2",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.8.0",
"expect.js": "~0.2.0",
"grunt": "^0.4.5",
"grunt-browserify": "^5.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^1.0.1",
"grunt-env": "^0.4.4",
"grunt-eslint": "^19.0.0",
"grunt-mocha-istanbul": "^5.0.2",
"grunt-sass": "^2.0.0",
"grunt-shell": "^1.2.1",
"isparta": "^4.0.0",
"istanbul": "^0.4.2",
"jsdom": "^8.1.0",
"load-grunt-tasks": "^3.4.1",
"minifyify": "^7.2.1",
"mocha": "^3.2.0",
"mocha-jsdom": "^1.1.0",
"node-localstorage": "^1.3.0",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"watch": "^0.17.1"
},
"keywords": [],
"browser": {
"jquery": "./node_modules/jquery/dist/jquery.js"
},
"browserify-shim": {
"jquery": {
"exports": "jQuery"
}
},
"dependencies": {
"backbone": "1.2.3",
"backbone-query-parameters": "0.4.0",
"backbone.localstorage": "1.1.16",
"clipboard": "1.5.5",
"datatables.net": "1.10.10",
"filesize": "3.2.1",
"jquery": "1.12.2",
"jquery-lazyload": "1.9.7",
"jquery-scrollstop": "1.2.0",
"prosemirror": "0.4.0",
"query-command-supported": "1.0.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"redux": "^3.6.0",
"respond.js": "1.4.2",
"underscore": "1.8.3",
"urijs": "1.17.1"
},
"config": {
"travis-cov": {
"threshold": 70
}
}
}
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

setup(
name="regulations",
version="7.0.0",
version="7.0.1",
packages=find_packages(),
include_package_data=True,
install_requires=[
'boto3',
'cached-property',
Expand Down

0 comments on commit 55695b1

Please sign in to comment.