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

Commit 55695b1

Browse files
Merge pull request #482 from cmc333333/package-files
Include templates, static files in python distro
2 parents 0ba4a44 + eb101e7 commit 55695b1

7 files changed

Lines changed: 286 additions & 22 deletions

File tree

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module.exports = function toExport(grunt) {
111111
plugin: [
112112
[function minifyify(b) {
113113
b.plugin('minifyify', {
114-
map: '/static/regulations/js/built/regulations.min.map',
114+
map: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
115115
output: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
116116
});
117117
}],

MANIFEST.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include CONTRIBUTING.md
2+
include TERMS.md
3+
include COPYING.txt
4+
include README.md
5+
graft regulations/templates
6+
graft regulations/static
7+
graft regulations/frontend-config

regulations/management/commands/compile_frontend.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from django.contrib.staticfiles.finders import get_finders
99
from django.contrib.staticfiles.storage import StaticFilesStorage
1010

11-
import regulations
12-
1311

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

41-
def find_regulations_directory(self):
42-
child = regulations.__file__
43-
child_dir = os.path.split(child)[0]
44-
return os.path.split(child_dir)[0] or "." # if regulations is local
45-
4639
def remove_dirs(self):
4740
"""Remove existing output dirs"""
4841
if os.path.exists(self.TARGET_DIR):
@@ -62,17 +55,11 @@ def remove_dirs(self):
6255
else:
6356
os.mkdir(self.BUILD_DIR)
6457

65-
def copy_configs(self):
66-
"""Copy over configs from regulations"""
67-
regulations_directory = self.find_regulations_directory()
68-
frontend_files = (
69-
"package.json",
70-
"Gruntfile.js",
71-
".eslintrc"
72-
)
73-
for f_file in frontend_files:
74-
source = "%s/%s" % (regulations_directory, f_file)
75-
shutil.copy(source, "%s/" % self.BUILD_DIR)
58+
def create_configs(self):
59+
for config_file in ('Gruntfile.js', 'package.json', '.babelrc'):
60+
os.rename(os.path.join(self.BUILD_DIR, 'static', 'config',
61+
config_file),
62+
os.path.join(self.BUILD_DIR, config_file))
7663
with codecs.open("%s/config.json" % self.BUILD_DIR, "w",
7764
encoding="utf-8") as f:
7865
f.write('{"frontEndPath": "static/regulations"}')
@@ -81,7 +68,7 @@ def _input_files(self):
8168
"""Fetch all of the static files from the installed apps. Yield them
8269
as pairs of (path, file)"""
8370
files_seen = set()
84-
pairs = (pr for finder in get_finders() for pr in finder.list([".*"]))
71+
pairs = (pr for finder in get_finders() for pr in finder.list([]))
8572
for path, storage in pairs:
8673
# Prefix the relative path if the source storage contains it
8774
if getattr(storage, 'prefix', None):
@@ -122,7 +109,7 @@ def cleanup(self):
122109

123110
def handle(self, **options):
124111
self.remove_dirs()
125-
self.copy_configs()
126112
self.collect_files()
113+
self.create_configs()
127114
self.build_frontend(install=options['install'], dev=settings.JS_DEBUG)
128115
self.cleanup()

regulations/static/config/.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"react"
5+
]
6+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
module.exports = function toExport(grunt) {
2+
grunt.initConfig({
3+
4+
/**
5+
* Pull in the package.json file so we can read its metadata.
6+
*/
7+
pkg: grunt.file.readJSON('package.json'),
8+
9+
/**
10+
*
11+
* Pull in config-specific vars
12+
*
13+
*/
14+
config: grunt.file.readJSON('config.json'),
15+
16+
env: {
17+
dev: {
18+
NODE_ENV: 'development',
19+
},
20+
dist: {
21+
NODE_ENV: 'production',
22+
},
23+
},
24+
25+
/**
26+
* Copy dependencies into static paths
27+
*/
28+
copy: {
29+
main: {
30+
files: [
31+
{
32+
expand: true,
33+
flatten: true,
34+
src: ['node_modules/respond.js/dest/*'],
35+
dest: '<%= config.frontEndPath %>/js/built/lib/respond/',
36+
filter: 'isFile',
37+
},
38+
],
39+
},
40+
},
41+
42+
/**
43+
* https://github.com/gruntjs/grunt-contrib-sass
44+
*/
45+
sass: {
46+
dev: {
47+
options: {
48+
style: 'expanded',
49+
},
50+
files: {
51+
'<%= config.frontEndPath %>/css/style.css': '<%= config.frontEndPath %>/css/scss/main.scss',
52+
},
53+
},
54+
},
55+
56+
/**
57+
* CSSMin: https://github.com/gruntjs/grunt-contrib-cssmin
58+
*
59+
* Minify CSS for production
60+
*/
61+
cssmin: {
62+
target: {
63+
files: {
64+
'<%= config.frontEndPath %>/css/regulations.min.css': ['<%= config.frontEndPath %>/css/style.css'],
65+
},
66+
},
67+
},
68+
/**
69+
* ESLint: https://github.com/sindresorhus/grunt-eslint
70+
*
71+
* Validate files with ESLint.
72+
*/
73+
eslint: {
74+
target: [
75+
'Gruntfile.js',
76+
'<%= config.frontEndPath %>/js/source/*.js',
77+
'<%= config.frontEndPath %>/js/source/events/**/*.js',
78+
'<%= config.frontEndPath %>/js/source/models/**/*.js',
79+
'<%= config.frontEndPath %>/js/source/views/**/*.js',
80+
'<%= config.frontEndPath %>/js/source/views/**/*.jsx',
81+
],
82+
},
83+
84+
/**
85+
* Browserify:
86+
*
87+
* Require('modules') in the browser/bundle up dependencies.
88+
*/
89+
browserify: {
90+
dev: {
91+
files: {
92+
'<%= config.frontEndPath %>/js/built/regulations.js': ['<%= config.frontEndPath %>/js/source/regulations.js', '<%= config.frontEndPath %>/js/source/regulations.js'],
93+
},
94+
options: {
95+
transform: ['babelify', 'browserify-shim'],
96+
browserifyOptions: {
97+
debug: true,
98+
},
99+
},
100+
},
101+
dist: {
102+
files: {
103+
'<%= config.frontEndPath %>/js/built/regulations.min.js': ['<%= config.frontEndPath %>/js/source/regulations.js'],
104+
},
105+
options: {
106+
transform: ['babelify', 'browserify-shim'],
107+
browserifyOptions: {
108+
debug: true,
109+
extensions: ['.js', '.jsx'],
110+
},
111+
plugin: [
112+
[function minifyify(b) {
113+
b.plugin('minifyify', {
114+
map: '/static/regulations/js/built/regulations.min.map',
115+
output: grunt.template.process('<%= config.frontEndPath %>/js/built/regulations.min.map'),
116+
});
117+
}],
118+
],
119+
},
120+
},
121+
},
122+
123+
mocha_istanbul: {
124+
coverage: {
125+
src: ['<%= config.frontEndPath %>/js/unittests/specs/**/*.js'],
126+
options: {
127+
root: '<%= config.frontEndPath %>/js',
128+
scriptPath: require.resolve('isparta/lib/cli'),
129+
istanbulOptions: ['--include-all-sources'],
130+
mochaOptions: ['--compilers', 'js:babel-register'],
131+
nodeExec: require.resolve('.bin/babel-node'),
132+
coverageFolder: '<%= config.frontEndPath %>/js/unittests/coverage',
133+
coverage: false,
134+
},
135+
},
136+
},
137+
});
138+
139+
/* eslint-disable global-require,import/no-extraneous-dependencies */
140+
grunt.event.on('coverage', (lcov, done) => {
141+
require('coveralls').handleInput(lcov, (err) => {
142+
if (err) {
143+
done(err);
144+
}
145+
done();
146+
});
147+
});
148+
/**
149+
* The above tasks are loaded here.
150+
*/
151+
require('load-grunt-tasks')(grunt);
152+
/* eslint-enable */
153+
154+
/**
155+
* Create task aliases by registering new tasks
156+
*/
157+
grunt.registerTask('test', ['eslint', 'mocha_istanbul']);
158+
grunt.registerTask('test-js', ['eslint', 'mocha_istanbul']);
159+
grunt.registerTask('build-dev', ['env:dev', 'copy', 'browserify:dev', 'sass']);
160+
grunt.registerTask('build-dist', ['env:dist', 'copy', 'browserify:dist', 'sass', 'cssmin']);
161+
grunt.registerTask('default', ['build-dist']);
162+
};
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"name": "regulations-site",
3+
"version": "7.0.0",
4+
"homepage": "https://eregs.github.io/",
5+
"contributors": [
6+
{
7+
"name": "Consumer Financial Protection Bureau",
8+
"url": "http://cfpb.github.io/"
9+
},
10+
{
11+
"name": "18F",
12+
"url": "https://18f.gsa.gov/"
13+
}
14+
],
15+
"repository": {
16+
"type": "git",
17+
"url": "http://github.com/eregs/regulations-site.git"
18+
},
19+
"bugs": {
20+
"url": "http://github.com/eregs/regulations-site/issues"
21+
},
22+
"licenses": [
23+
{
24+
"type": "Public Domain",
25+
"url": "http://github.com/eregs/regulations-site/blob/master/TERMS.md"
26+
}
27+
],
28+
"engines": {
29+
"node": "6.9.2"
30+
},
31+
"devDependencies": {
32+
"babel-cli": "^6.18.0",
33+
"babel-preset-es2015": "^6.18.0",
34+
"babel-preset-react": "^6.16.0",
35+
"babelify": "^7.3.0",
36+
"browserify": "^13.0.0",
37+
"browserify-shim": "^3.8.12",
38+
"chai": "^3.5.0",
39+
"coveralls": "^2.11.2",
40+
"deamdify": "^0.1.1",
41+
"eslint": "^3.12.2",
42+
"eslint-config-airbnb": "^13.0.0",
43+
"eslint-plugin-import": "^2.2.0",
44+
"eslint-plugin-jsx-a11y": "^2.2.3",
45+
"eslint-plugin-react": "^6.8.0",
46+
"expect.js": "~0.2.0",
47+
"grunt": "^0.4.5",
48+
"grunt-browserify": "^5.0.0",
49+
"grunt-contrib-copy": "^1.0.0",
50+
"grunt-contrib-cssmin": "^1.0.1",
51+
"grunt-env": "^0.4.4",
52+
"grunt-eslint": "^19.0.0",
53+
"grunt-mocha-istanbul": "^5.0.2",
54+
"grunt-sass": "^2.0.0",
55+
"grunt-shell": "^1.2.1",
56+
"isparta": "^4.0.0",
57+
"istanbul": "^0.4.2",
58+
"jsdom": "^8.1.0",
59+
"load-grunt-tasks": "^3.4.1",
60+
"minifyify": "^7.2.1",
61+
"mocha": "^3.2.0",
62+
"mocha-jsdom": "^1.1.0",
63+
"node-localstorage": "^1.3.0",
64+
"sinon": "^1.17.3",
65+
"sinon-chai": "^2.8.0",
66+
"watch": "^0.17.1"
67+
},
68+
"keywords": [],
69+
"browser": {
70+
"jquery": "./node_modules/jquery/dist/jquery.js"
71+
},
72+
"browserify-shim": {
73+
"jquery": {
74+
"exports": "jQuery"
75+
}
76+
},
77+
"dependencies": {
78+
"backbone": "1.2.3",
79+
"backbone-query-parameters": "0.4.0",
80+
"backbone.localstorage": "1.1.16",
81+
"clipboard": "1.5.5",
82+
"datatables.net": "1.10.10",
83+
"filesize": "3.2.1",
84+
"jquery": "1.12.2",
85+
"jquery-lazyload": "1.9.7",
86+
"jquery-scrollstop": "1.2.0",
87+
"prosemirror": "0.4.0",
88+
"query-command-supported": "1.0.0",
89+
"react": "^15.4.1",
90+
"react-dom": "^15.4.1",
91+
"redux": "^3.6.0",
92+
"respond.js": "1.4.2",
93+
"underscore": "1.8.3",
94+
"urijs": "1.17.1"
95+
},
96+
"config": {
97+
"travis-cov": {
98+
"threshold": 70
99+
}
100+
}
101+
}

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
setup(
55
name="regulations",
6-
version="7.0.0",
6+
version="7.0.1",
77
packages=find_packages(),
8+
include_package_data=True,
89
install_requires=[
910
'boto3',
1011
'cached-property',

0 commit comments

Comments
 (0)