-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathGruntfile.js
executable file
·256 lines (249 loc) · 10.3 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
const fs = require('fs');
const sass = require('sass');
const process = require('process');
const path = require('path');
partial_install_site = "http://www.onezoom.org";
partial_local_install_site = "http://127.0.0.1:8000"; // if you are running a local installation
preferred_python3 = "python3.10"; // in case you have multiple python3 versions installed
version_uikit = "3.21.13";
web2py_py = path.join(path.dirname(path.dirname(process.cwd())), 'web2py.py');
venv_python = path.join(path.dirname(path.dirname(process.cwd())), 'bin/python');
/** Generate a function to execute a web2py script, handing over all arguments */
function exec_web2py_script(script_name, init_args) {
return function () {
return [
venv_python,
web2py_py,
'-S OZtree/default',
'-M',
'-e',
'-R', 'applications/OZtree/' + script_name,
'--args',
...(init_args || []),
...arguments,
].join(' ');
}
}
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
exec: {
web2py_configure: {
cwd: "../../",
command: [
'( [ -d .git ] && git submodule update --init --recursive || true )',
'ln -sf applications/OZtree/_COPY_CONTENTS_TO_WEB2PY_DIR/routes.py routes.py',
'ln -sf handlers/wsgihandler.py handler.py',
'( [ -d applications/welcome ] && rm -r -- "applications/welcome" || true )',
'( [ -d applications/examples ] && rm -r -- "applications/examples" || true )',
'( [ -f applications/OZtree/private/appconfig.ini ] || { cp applications/OZtree/private/appconfig.ini.example applications/OZtree/private/appconfig.ini ; echo "****** edit private/appconfig.ini"; exit 1; } )',
preferred_python3 + ' -m venv .',
'./bin/pip install -r applications/OZtree/requirements.txt',
// Make web2py.py use the venv
'mv web2py.py web2py.py.o',
'echo "#!' + venv_python + '" > web2py.py',
'tail -n +2 web2py.py.o >> web2py.py',
].join(" && "),
},
web2py_start_dev: {
cwd: "./",
command: [
'./web2py-run',
].join(" && "),
},
compile_python: {
// compile python to make it faster on the server and hence reduce server load.
// should probably be run using the same python version as used to run web2py
cwd: "../../",
command:
venv_python + ' -c "import gluon.compileapp; gluon.compileapp.compile_application(\''
+ process.cwd()
+ '\', skip_failed_views=True)"'
},
background_tasks: {
cwd: "../../",
command: exec_web2py_script("private/background_tasks.py"),
},
db_fixtures: {
command: function () {
// Either accept a list of test filenames, or work it out ourselves and run all tests
var tests = arguments.length > 0 ? arguments : fs.readdirSync('tests/fixtures/').filter(function (x) {
return x.match('^.*\.py');
});
return Array.prototype.map.call(tests, function (test_path) {
return exec_web2py_script('tests/fixtures/' + test_path)();
}).join(" && ");
}
},
make_release_info: {
command: 'git describe --tags > RELEASE_INFO && ' + venv_python + ' OZprivate/ServerScripts/Utilities/get_release_name.py RELEASE_INFO >> RELEASE_INFO'
},
test_server: {
command: function () {
// Either accept a list of test filenames, or work it out ourselves and run all tests
var tests = arguments.length > 0 ? arguments : fs.readdirSync('tests/unit/').filter(function (x) {
return x.match('^test_.*\.py');
});
return Array.prototype.map.call(tests, function (test_path) {
return exec_web2py_script('tests/unit/' + test_path)();
}).join(" && ");
}
},
test_server_functional: {
command: 'nosetests3 tests/functional/'
},
test_client: {
command: 'npm run test'
},
compile_js: {
command: [
'npm run compile_js',
].join(" && "),
},
compile_js_dev: {
command: [
'npm run compile_js_dev',
].join(" && "),
},
fetch_uikit: {
cwd: "static/uikit-3/",
command: '[ -f "uikit-'+version_uikit+'.zip" ] || { rm -rf -- "uikit-*.zip"; curl -LO "https://github.com/uikit/uikit/releases/download/v'+version_uikit+'/uikit-'+version_uikit+'.zip" && unzip -o "uikit-'+version_uikit+'.zip" || rm -- "uikit-'+version_uikit+'.zip"; }',
},
unify_docs: {
//put all markdown files referred to in OZTreeModule/docs/index.markdown in a single _compiled.markdown file
//and substitute .png / svg images with data (base64 encoded for png) so they become embedded in the doc
cwd: "OZprivate/rawJS/OZTreeModule/docs",
command: "perl compile_docs.pl index.markdown > _compiled.markdown"
},
convert_links_to_local: {
// Any .html file in /static is fair game. See documentation in
// https://github.com/OneZoom/OZtree#onezoom-setup
command:
venv_python + " OZprivate/ServerScripts/Utilities/partial_install.py" +
" --search " + partial_local_install_site + // replace local urls, for partial local install
" --replace " + partial_install_site +
" static/*.html"
}
},
jsdoc2md: {
separateOutputFilePerInput: {
files: [
{ expand: true,
cwd: '<%=pkg.directories.js_src%>',
src: '**/*.js',
dest: 'OZprivate/rawJS/OZTreeModule/docs/src',
ext: '.md' }
]
},
withOptions: {
options: {
'heading-depth': 4,
'global-index-format': 'none'
}
}
},
sass: {
// SCSS -> CSS files
options: {
implementation: sass,
sourceMap: true,
outputStyle: 'compressed'
},
dist: {
files: [{
expand: true,
cwd: '<%=pkg.directories.css_src%>',
src: ['*.scss'],
ext: '.css',
dest: '<%=pkg.directories.css_dist%>'
}]
}
},
clean: [
'compiled',
'<%=pkg.directories.js_dest%>/*',
'<%=pkg.directories.js_dist%>/*.js*',
],
compress: { // NB: the main tree viewer is compressed using webpack, not directly in grunt
main: {
options: {
mode: 'gzip'
},
files: [
{
expand: true,
cwd: '<%=pkg.directories.css_dist%>',
src: ['*.css'],
dest: '<%=pkg.directories.css_dist%>',
ext: '.css.gz'
},
{
expand: true,
cwd: '<%=pkg.directories.old_css_dest_and_dist%>',
src: ['*.css'],
dest: '<%=pkg.directories.old_css_dest_and_dist%>',
ext: '.css.gz'
}
]
}
},
copy: {
prod: {
files: [
{expand: true, cwd: '<%=pkg.directories.js_dist%>', src: "**", dest: '<%=pkg.directories.js_dest%>/', filter: 'isFile'}
]
},
dev: {
files: [
{expand: true, cwd: '<%=pkg.directories.js_dist%>', src: "**", dest: '<%=pkg.directories.js_dest%>/', filter: 'isFile'}
]
},
},
'curl-dir': {
'get_minlife': {
src: [
partial_install_site + '/treeviewer/minlife.html', // TODO - add language specific option: /?lang=' + (grunt.option('lang') || ''),
partial_install_site + '/treeviewer/minlife_tour.html' // TODO - add language specific option:
],
dest:'static',
},
'get_local_minlife': {
//used for development only. This will create the minlife file as normal, but
//using your local machine to source the page, rather than downloading the minlife
//file from the main OneZoom server. This means that as well as local changes to
//the treeviewer javascript, local changes you make to other files (such as
// treeviewer/layout.html and treeviewer/UI_layer.load) will be incorporated
//into the minlife tree. However, it assumes you have a local server running on
//127.0.0.1:8000, and pics_dir = http://images.onezoom.org/ set in your appconfig.ini.
src: [
partial_local_install_site + '/treeviewer/minlife.html',
partial_local_install_site + '/treeviewer/minlife_tour.html',
],
dest:'static',
}
}
});
grunt.loadNpmTasks("grunt-exec");
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-jsdoc-to-markdown');
grunt.loadNpmTasks('grunt-curl');
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask("make_release_info", ["exec:make_release_info"]);
grunt.registerTask("test", ["exec:test_server", "exec:test_client"]);
grunt.registerTask("test-client", ["exec:test_client"]);
grunt.registerTask("test-server", ["exec:test_server"]);
grunt.registerTask("test-server-functional", ["exec:test_server", "exec:test_server_functional"]);
grunt.registerTask("css", ["sass"]);
grunt.registerTask("docs", ["jsdoc2md", "exec:unify_docs"]);
grunt.registerTask("compile-python", ["exec:compile_python"]);
grunt.registerTask("compile-js", ["exec:compile_js"]);
grunt.registerTask("compile-js_dev", ["exec:compile_js_dev"]);
grunt.registerTask("partial-install", ["compile-js", "css", "copy:dev", "curl-dir:get_minlife", "exec:convert_links_to_local"]);
grunt.registerTask("partial-local-install", ["compile-js", "css", "copy:dev", "curl-dir:get_local_minlife", "exec:convert_links_to_local"]);
grunt.registerTask("web2py", ["exec:web2py_configure"]);
grunt.registerTask("prod", ["clean", "web2py", "exec:fetch_uikit", "compile-python", "compile-js", "css", "compress", "copy:prod", "make_release_info", "docs"]);
grunt.registerTask("dev", ["clean", "web2py", "exec:fetch_uikit", "compile-js_dev", "css", "compress", "copy:dev", "make_release_info", "docs"]);
grunt.registerTask("start-dev", ['exec:web2py_start_dev']);
};