From 0b5f40e66c6045c007c30e4362e19279e7fd6f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 10 Sep 2015 13:34:32 +0200 Subject: [PATCH] tech(): made config system check for generated css or javascript files and panic if there are none, also if there is a public_gen directory it will use that, even if static root is set to public --- pkg/setting/setting.go | 19 ++++++++++++++++++- tasks/build_task.js | 10 +++++----- tasks/options/compress.js | 2 +- tasks/options/requirejs.js | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index cc74456971e..9254bada6d4 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -354,6 +354,23 @@ func setHomePath(args *CommandLineArgs) { } } +func getStaticRootPath(configValue string) string { + if configValue != "public" { + return configValue + } + + if _, err := os.Stat(path.Join(HomePath, configValue, "css")); err == nil { + return configValue + } + + if _, err := os.Stat(path.Join(HomePath, "public_gen", "css")); err == nil { + return "public_gen" + } + + log.Fatal(3, "Failed to detect generated css or javascript files in static root (%s), have you executed default grunt task?", configValue) + return "" +} + func NewConfigContext(args *CommandLineArgs) { setHomePath(args) loadConfiguration(args) @@ -373,7 +390,7 @@ func NewConfigContext(args *CommandLineArgs) { Domain = server.Key("domain").MustString("localhost") HttpAddr = server.Key("http_addr").MustString("0.0.0.0") HttpPort = server.Key("http_port").MustString("3000") - StaticRootPath = makeAbsolute(server.Key("static_root_path").String(), HomePath) + StaticRootPath = makeAbsolute(getStaticRootPath(server.Key("static_root_path").String()), HomePath) RouterLogging = server.Key("router_logging").MustBool(false) EnableGzip = server.Key("enable_gzip").MustBool(false) EnforceDomain = server.Key("enforce_domain").MustBool(false) diff --git a/tasks/build_task.js b/tasks/build_task.js index 546b2fed6cf..63334cbec5a 100644 --- a/tasks/build_task.js +++ b/tasks/build_task.js @@ -43,27 +43,27 @@ module.exports = function(grunt) { }); grunt.registerTask('build-post-process', function() { - grunt.config('copy.public_gen_to_dest', { + grunt.config('copy.public_gen_to_temp', { expand: true, cwd: '<%= genDir %>', src: '**/*', - dest: '<%= destDir %>/public/', + dest: '<%= tempDir %>/public/', }); grunt.config('copy.backend_bin', { cwd: 'bin', expand: true, src: ['*'], options: { mode: true}, - dest: '<%= destDir %>/bin/' + dest: '<%= tempDir %>/bin/' }); grunt.config('copy.backend_files', { expand: true, src: ['conf/defaults.ini', 'conf/sample.ini', 'vendor/**/*', 'scripts/*'], options: { mode: true}, - dest: '<%= destDir %>' + dest: '<%= tempDir %>' }); - grunt.task.run('copy:public_gen_to_dest'); + grunt.task.run('copy:public_gen_to_temp'); grunt.task.run('copy:backend_bin'); grunt.task.run('copy:backend_files'); }); diff --git a/tasks/options/compress.js b/tasks/options/compress.js index 99524dfd0cd..4dc77ec82f8 100644 --- a/tasks/options/compress.js +++ b/tasks/options/compress.js @@ -9,7 +9,7 @@ module.exports = function(config) { files : [ { expand: true, - cwd: '<%= destDir %>', + cwd: '<%= tempDir %>', src: ['**/*'], dest: '<%= pkg.name %>-<%= pkg.version %>/', }, diff --git a/tasks/options/requirejs.js b/tasks/options/requirejs.js index a7a9d5b8dda..f3a113048c9 100644 --- a/tasks/options/requirejs.js +++ b/tasks/options/requirejs.js @@ -74,7 +74,7 @@ module.exports = function(config,grunt) { ]; var fs = require('fs'); - var panelPath = config.genDir+'/app/panels'; + var panelPath = config.srcDir + '/app/panels'; // create a module for each directory in public/app/panels/ fs.readdirSync(panelPath).forEach(function (panelName) {