Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Add concat, compile and minify Grunt tasks #5776

Merged
merged 13 commits into from
Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Thumbs.db
src/brackets.css
src/brackets.min.css

# ignore jenkins build info
/build.prop
Expand All @@ -9,19 +7,22 @@ src/brackets.min.css
/node_modules
/npm-debug.log

# ignore compiled files
/dist
/src/styles/brackets.css

# ignore everything in the dev extension directory EXCEPT the README
# (so that the directory is non-empty and can be in git)
src/extensions/dev/*
!src/extensions/dev/README
/src/extensions/dev/*
!/src/extensions/dev/README

src/extensions/disabled
/src/extensions/disabled

#OSX .DS_Store files
.DS_Store

# unit test working directory
test/results
/test/results

# Netbeans
/nbproject
Expand All @@ -30,4 +31,4 @@ test/results
.idea

# Files that can be automatically downloaded that we don't want to ship with our builds
src/extensibility/node/node_modules/request/tests/
/src/extensibility/node/node_modules/request/tests/
131 changes: 123 additions & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,121 @@
module.exports = function (grunt) {
'use strict';

// load dependencies
require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-usemin']});
grunt.loadTasks('tasks');

var common = require("./tasks/lib/common")(grunt);

// Project configuration.
grunt.initConfig({
pkg : grunt.file.readJSON("package.json"),
clean: {
dist: ['dist']
},
copy: {
dist: {
files: [
/* static files */
{
expand: true,
dest: 'dist/',
cwd: 'src/',
src: [
'config.json',
'nls/{,*/}*.js',
'xorigin.js',
'dependencies.js',
'thirdparty/requirejs/require.js',
'thirdparty/CodeMirror2/**/*',
'thirdparty/i18n/*.js',
'thirdparty/text/*.js'
]
},
/* extensions and CodeMirror modes */
{
expand: true,
dest: 'dist/',
cwd: 'src/',
src: [
'extensibility/**/*',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need this for finding the extension manager node domain.

'extensions/default/**/*',
'thirdparty/CodeMirror2/**/*',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep these files in dist for language extensions and CodeMirror themes.

'thirdparty/i18n/*.js',
'thirdparty/text/*.js'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need these for ExtensionLoader when creating new require contexts.

]
},
/* styles, fonts and images */
{
expand: true,
dest: 'dist/styles',
cwd: 'src/styles',
src: ['jsTreeTheme.css', 'fonts/{,*/}*.*', 'images/*']
}
]
}
},
less: {
css: {
files: {
"src/styles/brackets.css": "src/styles/brackets.less"
}
}
},
requirejs: {
dist: {
// Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js
options: {
// `name` and `out` is set by grunt-usemin
baseUrl: 'src',
optimize: 'none',
// TODO: Figure out how to make sourcemaps work with grunt-usemin
// https://github.com/yeoman/grunt-usemin/issues/30
//generateSourceMaps: true,
// required to support SourceMaps
// http://requirejs.org/docs/errors.html#sourcemapcomments
preserveLicenseComments: true,
useStrict: true,
// Disable closure, we want define/require to be globals
wrap: false
//uglify2: {} // https://github.com/mishoo/UglifyJS2
}
}
},
useminPrepare: {
options: {
dest: 'dist'
},
html: 'src/index.html'
},
usemin: {
options: {
dirs: ['dist']
},
html: ['dist/{,*/}*.html'],
css: ['dist/css/{,*/}*.css']
},
htmlmin: {
dist: {
options: {
/*removeCommentsFromCDATA: true,
// https://github.com/yeoman/grunt-usemin/issues/44
//collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true*/
},
files: [{
expand: true,
cwd: 'src',
src: '*.html',
dest: 'dist'
}]
}
},
meta : {
src : [
'src/**/*.js',
Expand Down Expand Up @@ -144,13 +254,6 @@ module.exports = function (grunt) {
linux: "<%= shell.repo %>/installer/linux/debian/package-root/opt/brackets/brackets"
}
});

// load dependencies
grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-jasmine-node');

// task: install
grunt.registerTask('install', ['write-config']);
Expand All @@ -164,5 +267,17 @@ module.exports = function (grunt) {
grunt.registerTask('set-sprint', ['update-sprint-number', 'write-config']);

// Default task.
grunt.registerTask('default', ['test']);
grunt.registerTask('default', [
'test',
'less',
'clean',
'useminPrepare',
'htmlmin',
'requirejs',
'concat',
'cssmin',
'uglify',
'copy',
'usemin'
]);
};
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
"grunt-contrib-watch": "0.3.1",
"grunt-contrib-jasmine": "0.4.2",
"grunt-template-jasmine-requirejs": "0.1.0",
"grunt-contrib-cssmin": "0.6.0",
"grunt-contrib-clean": "0.4.1",
"grunt-contrib-copy": "0.4.1",
"grunt-contrib-htmlmin": "0.1.3",
"grunt-contrib-less": "0.5.1",
"grunt-contrib-requirejs": "0.4.1",
"grunt-contrib-uglify": "0.2.0",
"grunt-contrib-concat": "0.3.0",
"grunt-contrib-watch": "0.4.3",
"grunt-usemin": "0.1.11",
"load-grunt-tasks": "0.2.0",
"q": "0.9.2",
"jshint": "2.1.4"
},
Expand Down
12 changes: 0 additions & 12 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, define, brackets: true, $, window, navigator, Mustache */

require.config({
paths: {
"text" : "thirdparty/text/text",
"i18n" : "thirdparty/i18n/i18n"
},
// Use custom brackets property until CEF sets the correct navigator.language
// NOTE: When we change to navigator.language here, we also should change to
// navigator.language in ExtensionLoader (when making require contexts for each
// extension).
locale: window.localStorage.getItem("locale") || (typeof (brackets) !== "undefined" ? brackets.app.language : navigator.language)
});

/**
* brackets is the root of the Brackets codebase. This file pulls in all other modules as
* dependencies (or dependencies thereof), initializes the UI, and binds global menus & keyboard
Expand Down
12 changes: 11 additions & 1 deletion src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@
"phantomjs": "1.9.0-1",
"grunt-lib-phantomjs": "0.3.0",
"grunt-contrib-jshint": "0.6.0",
"grunt-contrib-watch": "0.3.1",
"grunt-contrib-watch": "0.4.3",
"grunt-contrib-jasmine": "0.4.2",
"grunt-template-jasmine-requirejs": "0.1.0",
"grunt-contrib-cssmin": "0.6.0",
"grunt-contrib-clean": "0.4.1",
"grunt-contrib-copy": "0.4.1",
"grunt-contrib-htmlmin": "0.1.3",
"grunt-contrib-less": "0.5.1",
"grunt-contrib-requirejs": "0.4.1",
"grunt-contrib-uglify": "0.2.0",
"grunt-contrib-concat": "0.3.0",
"grunt-usemin": "0.1.11",
"load-grunt-tasks": "0.2.0",
"q": "0.9.2",
"jshint": "2.1.4"
},
Expand Down
21 changes: 12 additions & 9 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
<script type="application/javascript" src="xorigin.js">
</script>

<!-- TODO (Issue #278): switch between runtime LESS compilation in dev mode and precompiled version -->
<link rel="stylesheet/less" href="styles/brackets.less">
<script src="thirdparty/less-1.4.2.min.js"></script>
<script src="thirdparty/mustache/mustache.js"></script>
<!-- <link rel="stylesheet" href="brackets.min.css"> -->

<!-- build:css styles/brackets.min.css -->
<link rel="stylesheet" type="text/css" href="thirdparty/CodeMirror2/lib/codemirror.css">
<link rel="stylesheet" type="text/css" href="styles/brackets.css">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that we are no longer dynamically generating CSS at startup from our LESS files. Developers will need to run grunt less when making changes or we may choose to add a grunt watch:less task to compile in the background.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if .css file was automatically generated when changes were made so we'd get the best of both worlds. The BracketsLESS extension does this, but I'm not sure if it works when you update an @imported .less file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see if I can have an alternate index.html that lets us keep our current workflow of dynamically compiling LESS at startup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I added another task grunt-targethtml that let's us include brackets.less at dev time, then replace it with the compiled brackets.css at build time. This means we no longer require node+grunt for devs and we can keep our current process.

<!-- endbuild -->

<!-- JavaScript -->

<!-- Pre-load third party scripts that cannot be async loaded. -->
<!-- build:js thirdparty/thirdparty.min.js -->
<script src="thirdparty/less-1.4.2.min.js"></script>
<script src="thirdparty/mustache/mustache.js"></script>
<script src="thirdparty/jquery-2.0.1.min.js"></script>
<script src="thirdparty/CodeMirror2/lib/codemirror.js"></script>
<script src="thirdparty/CodeMirror2/addon/fold/xml-fold.js"></script>
Expand All @@ -52,9 +54,8 @@
<script src="thirdparty/CodeMirror2/addon/edit/closebrackets.js"></script>
<script src="thirdparty/CodeMirror2/addon/edit/closetag.js"></script>
<script src="thirdparty/CodeMirror2/addon/selection/active-line.js"></script>

<!-- JS for CodeMirror search support -->
<script src="thirdparty/CodeMirror2/addon/search/searchcursor.js"></script>
<!-- endbuild -->

</head>
<body>
Expand All @@ -66,7 +67,9 @@
-->

<!-- All other scripts are loaded through require. -->
<script src="thirdparty/requirejs/require.js" data-main="brackets"></script>
<!-- build:js main.js -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see the change caused by the build:js for thirdparty.min.js, but the only difference I see here is that the attributes switched order... otherwise, the script tag seems exactly the same. What should this be doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sets up configuration used by the requirejs (r.js) task. You're right that it sort of looks like a no-op though. Anyhow, the config is printed to the terminal:

  requirejs:
  { dist: 
   { options: 
      { baseUrl: 'src',
        optimize: 'uglify2',
        generateSourceMaps: true,
        useSourceUrl: true,
        preserveLicenseComments: false,
        useStrict: true,
        wrap: false,
        exclude: [ 'text!config.json' ],
        uglify2: {},
        name: 'main',
        out: 'dist/main.js',
        mainConfigFile: 'src/main.js' } } }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's like magic voodoo. There's nothing in the Gruntfile that runs r.js (looks like usemin takes care of it).

<script src="thirdparty/requirejs/require.js" data-main="main"></script>
<!-- endbuild -->

<!-- Verify that all dependencies are loaded. -->
<script src="dependencies.js"></script>
Expand Down
43 changes: 43 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, window, brackets, navigator */
(function () {
"use strict";

require.config({
paths: {
"text" : "thirdparty/text/text",
"i18n" : "thirdparty/i18n/i18n"
}
});

// hack for r.js optimization
require.config({
locale: window.localStorage.getItem("locale") || (typeof (brackets) !== "undefined" ? brackets.app.language : navigator.language)
});

require(["brackets"], function (brackets) {});
}());
6 changes: 0 additions & 6 deletions src/styles/brackets_shared.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
* processing order.
*/

/* CSS imports */

// CodeMirror
// Must wrap in quotes to avoid issue #1015 (true for all relative URLs to non-LESS files)
@import "../thirdparty/CodeMirror2/lib/codemirror.css";

/* LESS imports */

// Bootstrap @ v.2.3.1
Expand Down
16 changes: 12 additions & 4 deletions src/utils/ExtensionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ define(function (require, exports, module) {
* C:\Users\<user>\AppData\Roaming\Brackets\extensions\user on windows.
*/
function getUserExtensionPath() {
return brackets.app.getApplicationSupportDirectory() + "/extensions/user";
if (brackets.app.getApplicationSupportDirectory) {
return brackets.app.getApplicationSupportDirectory() + "/extensions/user";
}

return null;
}

/**
Expand Down Expand Up @@ -270,7 +274,9 @@ define(function (require, exports, module) {
},
function (error) {
console.error("[Extension] Error -- could not open native directory: " + directory);
result.reject();

// Silently ignore error
result.resolve();
});

return result.promise();
Expand Down Expand Up @@ -337,8 +343,10 @@ define(function (require, exports, module) {
// If the directory *does* exist, nothing else needs to be done. It will be scanned normally
// during extension loading.
var extensionPath = getUserExtensionPath();
new NativeFileSystem.DirectoryEntry().getDirectory(extensionPath,
{create: true});

if (extensionPath) {
new NativeFileSystem.DirectoryEntry().getDirectory(extensionPath, {create: true});
}

// Create the extensions/disabled directory, too.
var disabledExtensionPath = extensionPath.replace(/\/user$/, "/disabled");
Expand Down
Loading