From f021ce3657806986ffa5131df10cddcdc1ce3a01 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 14 Aug 2013 09:06:16 -0700 Subject: [PATCH] Compile bundled package files in compile task Any .coffee, .cson, and .less files found in bundled Atom packages in node_modules are now compiled during the compile task --- Gruntfile.coffee | 91 ++++++++++++++++++++++++----------------- tasks/build-task.coffee | 20 +++++---- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 9591ca321..e9a77e0ab 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,3 +1,4 @@ +fs = require 'fs' path = require 'path' module.exports = (grunt) -> @@ -8,51 +9,65 @@ module.exports = (grunt) -> appDir = path.join(contentsDir, 'Resources', 'app') installDir = path.join('/Applications', appName) + coffeeConfig = + options: + sourceMap: true + glob_to_multiple: + expand: true + src: [ + 'src/**/*.coffee' + 'static/**/*.coffee' + ] + dest: appDir + ext: '.js' + + lessConfig = + options: + paths: [ + 'static' + 'vendor' + ] + glob_to_multiple: + expand: true + src: [ + 'src/**/*.less' + 'static/**/*.less' + 'themes/**/*.less' + ] + dest: appDir + ext: '.css' + + csonConfig = + options: + rootObject: true + glob_to_multiple: + expand: true + src: [ + 'src/**/*.cson' + 'static/**/*.cson' + 'themes/**/*.cson' + ] + dest: appDir + ext: '.json' + + for child in fs.readdirSync('node_modules') when child isnt '.bin' + directory = path.join('node_modules', child) + {engines} = grunt.file.readJSON(path.join(directory, 'package.json')) + if engines?.atom? + coffeeConfig.glob_to_multiple.src.push("#{directory}/**/*.coffee") + lessConfig.glob_to_multiple.src.push("#{directory}/**/*.less") + csonConfig.glob_to_multiple.src.push("#{directory}/**/*.cson") + grunt.initConfig pkg: grunt.file.readJSON('package.json') atom: {appDir, appName, buildDir, contentsDir, installDir, shellAppDir} - coffee: - options: - sourceMap: true - glob_to_multiple: - expand: true - src: [ - 'src/**/*.coffee' - 'static/**/*.coffee' - ] - dest: appDir - ext: '.js' + coffee: coffeeConfig - less: - options: - paths: [ - 'static' - 'vendor' - ] - glob_to_multiple: - expand: true - src: [ - 'src/**/*.less' - 'static/**/*.less' - 'themes/**/*.less' - ] - dest: appDir - ext: '.css' + less: lessConfig - cson: - options: - rootObject: true - glob_to_multiple: - expand: true - src: [ - 'src/**/*.cson' - 'static/**/*.cson' - 'themes/**/*.cson' - ] - dest: appDir - ext: '.json' + cson: csonConfig coffeelint: options: diff --git a/tasks/build-task.coffee b/tasks/build-task.coffee index dd865d664..93862f994 100644 --- a/tasks/build-task.coffee +++ b/tasks/build-task.coffee @@ -18,22 +18,26 @@ module.exports = (grunt) -> cp 'atom.sh', path.join(appDir, 'atom.sh') cp 'package.json', path.join(appDir, 'package.json') - directories = [ + packageDirectories = [] + nonPackageDirectories = [ 'benchmark' 'dot-atom' 'spec' 'vendor' ] - {devDependencies, dependencies} = grunt.file.readJSON('package.json') + {devDependencies} = grunt.file.readJSON('package.json') for child in fs.readdirSync('node_modules') directory = path.join('node_modules', child) try - {name} = grunt.file.readJSON(path.join(directory, 'package.json')) - if not devDependencies[name]? or dependencies[name]? - directories.push(directory) + {name, engines} = grunt.file.readJSON(path.join(directory, 'package.json')) + continue if devDependencies[name]? + if engines?.atom? + packageDirectories.push(directory) + else + nonPackageDirectories.push(directory) catch e - directories.push(directory) + nonPackageDirectories.push(directory) ignoredPaths = [ path.join('git-utils', 'deps') @@ -43,8 +47,10 @@ module.exports = (grunt) -> ] ignoredPaths = ignoredPaths.map (ignoredPath) -> "(#{ignoredPath})" nodeModulesFilter = new RegExp(ignoredPaths.join('|')) - for directory in directories + for directory in nonPackageDirectories cp directory, path.join(appDir, directory), filter: nodeModulesFilter + for directory in packageDirectories + cp directory, path.join(appDir, directory), filter: /.+\.(cson|coffee|less)$/ cp 'src', path.join(appDir, 'src'), filter: /.+\.(cson|coffee|less)$/ cp 'static', path.join(appDir, 'static'), filter: /.+\.less$/