2013-05-09 23:56:32 +02:00
|
|
|
var path = require('path'),
|
|
|
|
parserlib = require('parserlib');
|
|
|
|
|
|
|
|
module.exports = function (grunt) {
|
|
|
|
|
|
|
|
// -- Config -------------------------------------------------------------------
|
|
|
|
|
|
|
|
grunt.initConfig({
|
|
|
|
|
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
|
|
|
|
// -- Constants ------------------------------------------------------------
|
|
|
|
|
|
|
|
NORMALIZE_LIB: path.join(process.cwd(), '../', 'normalize.css'),
|
|
|
|
BASE_DIR : 'src/base/',
|
|
|
|
PREFIX : '.k',
|
|
|
|
|
|
|
|
COMMENT: '/* THIS FILE IS GENERATED BY A BUILD SCRIPT - DO NOT EDIT! */\n',
|
|
|
|
LICENSE: [
|
|
|
|
'/*! normalize.css v1.1.1 | MIT License | git.io/normalize */',
|
|
|
|
'/*! Copyright (c) Nicolas Gallagher and Jonathan Neal */',
|
|
|
|
'\n'
|
|
|
|
].join('\n'),
|
|
|
|
|
2013-05-13 20:56:23 +02:00
|
|
|
// -- Clean Config ---------------------------------------------------------
|
|
|
|
|
|
|
|
clean: {
|
|
|
|
build: ['build/'],
|
|
|
|
base : ['src/base/css/', 'src/base/tests/', 'src/base/LICENSE.md']
|
|
|
|
},
|
|
|
|
|
2013-05-09 23:56:32 +02:00
|
|
|
// -- CSSMin Config --------------------------------------------------------
|
|
|
|
|
|
|
|
cssmin: {
|
|
|
|
options: {
|
|
|
|
report: 'gzip'
|
|
|
|
},
|
|
|
|
|
|
|
|
base: {
|
|
|
|
files: {
|
|
|
|
'build/base/base-min.css' : ['src/base/css/normalize.css'],
|
|
|
|
'build/base/base-context-min.css': ['src/base/css/normalize-context.css']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
forms: {
|
|
|
|
files: {
|
|
|
|
'build/forms/forms-min.css' : ['src/forms/css/*.css'],
|
|
|
|
'build/forms/forms-nr-min.css': ['src/forms/css/forms-core.css',
|
|
|
|
'src/forms/css/forms.css']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
grids: {
|
|
|
|
files: {
|
|
|
|
'build/grids/grids-min.css' : ['src/grids/css/*.css'],
|
|
|
|
'build/grids/grids-nr-min.css': ['src/grids/css/cssgrids-base.css',
|
|
|
|
'src/grids/css/cssgrids-units.css']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
menus: {
|
|
|
|
files: {
|
|
|
|
'build/menus/menus-min.css' : ['src/menus/css/*.css'],
|
|
|
|
'build/menus/menus-nr-min.css': ['src/menus/css/list-core.css',
|
|
|
|
'src/menus/css/list.css',
|
|
|
|
'src/menus/css/list-paginator.css']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
tables: {
|
|
|
|
files: {
|
|
|
|
'build/tables/tables-min.css': ['src/tables/css/*.css']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
buttons: {
|
|
|
|
files: {
|
|
|
|
'build/buttons/buttons-min.css': ['src/buttons/css/*.css']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// -- Main Tasks ---------------------------------------------------------------
|
|
|
|
|
2013-05-13 20:56:23 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
2013-05-09 23:56:32 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
|
|
|
|
2013-05-13 20:56:23 +02:00
|
|
|
grunt.registerTask('default', [
|
|
|
|
'clean:build',
|
|
|
|
'cssmin'
|
|
|
|
]);
|
|
|
|
|
2013-05-09 23:56:32 +02:00
|
|
|
grunt.registerTask('base', ['cssmin:base']);
|
|
|
|
grunt.registerTask('buttons', ['cssmin:buttons']);
|
|
|
|
grunt.registerTask('forms', ['cssmin:forms']);
|
|
|
|
grunt.registerTask('grids', ['cssmin:grids']);
|
|
|
|
grunt.registerTask('menus', ['cssmin:menus']);
|
|
|
|
grunt.registerTask('tables', ['cssmin:tables']);
|
|
|
|
|
|
|
|
// -- Import Tasks -------------------------------------------------------------
|
|
|
|
|
|
|
|
grunt.registerTask('base-import-css', 'Import Normalize CSS Files', function () {
|
|
|
|
var file = 'normalize.css',
|
|
|
|
src = path.join(grunt.config('NORMALIZE_LIB'), file),
|
|
|
|
dest = path.join(grunt.config('BASE_DIR'), 'css', file);
|
|
|
|
|
|
|
|
if (!grunt.file.exists(src)) {
|
|
|
|
grunt.fail.fatal('Did you clone normalize.css yet?');
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.log.writeln('Copying: '.green + file.cyan + ' to ' + dest.cyan);
|
|
|
|
grunt.file.write(dest, grunt.config('COMMENT') + grunt.file.read(src));
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.registerTask('base-import-tests', 'Import Normalize Tests', function () {
|
|
|
|
var file = 'test.html',
|
|
|
|
src = path.join(grunt.config('NORMALIZE_LIB'), file),
|
|
|
|
dest = path.join(grunt.config('BASE_DIR'), 'tests', 'manual', file);
|
|
|
|
|
|
|
|
if (!grunt.file.exists(src)) {
|
|
|
|
grunt.fail.fatal('Did you clone normalize.css yet?');
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.log.writeln('Copying: '.green + file.cyan + ' to ' + dest.cyan);
|
|
|
|
grunt.file.copy(src, dest);
|
|
|
|
});
|
|
|
|
|
2013-05-13 20:56:23 +02:00
|
|
|
grunt.registerTask('base-import-meta', 'Import Normalize License', function () {
|
|
|
|
var file = 'LICENSE.md',
|
|
|
|
src = path.join(grunt.config('NORMALIZE_LIB'), file),
|
|
|
|
dest = path.join(grunt.config('BASE_DIR'), file);
|
|
|
|
|
|
|
|
if (!grunt.file.exists(src)) {
|
|
|
|
grunt.fail.fatal('Did you clone normalize.css yet?');
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.log.writeln('Copying: '.green + file.cyan + ' to ' + dest.cyan);
|
|
|
|
grunt.file.copy(src, dest);
|
|
|
|
});
|
|
|
|
|
2013-05-09 23:56:32 +02:00
|
|
|
grunt.registerTask('base-create-context', 'Make context version', function () {
|
|
|
|
var context = grunt.config('COMMENT') + grunt.config('LICENSE'),
|
|
|
|
done = this.async(),
|
|
|
|
parser = new parserlib.css.Parser(),
|
|
|
|
raw = grunt.file.read(grunt.config('BASE_DIR') + 'css/normalize.css');
|
|
|
|
|
|
|
|
parser.addListener('startstylesheet', function () {
|
|
|
|
grunt.log.ok('Starting to parse style sheet...');
|
|
|
|
});
|
|
|
|
|
|
|
|
parser.addListener('endstylesheet', function () {
|
|
|
|
var contextFile = path.join(grunt.config('BASE_DIR'), 'css', 'normalize-context.css');
|
|
|
|
|
|
|
|
grunt.log.ok('Finished parsing style sheet...');
|
|
|
|
grunt.file.write(contextFile, context);
|
|
|
|
grunt.log.ok('Done creating context build!');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Fired right before CSS properties are parsed for a certain rule. Go
|
|
|
|
// through and add all the selectors to the `css` string.
|
|
|
|
parser.addListener('startrule', function (event) {
|
|
|
|
var prefix = grunt.config('PREFIX');
|
|
|
|
|
|
|
|
event.selectors.forEach(function (selector, i) {
|
|
|
|
var nextSelector = event.selectors[i + 1];
|
|
|
|
|
|
|
|
// If the selector does not contain the html selector, we can go
|
|
|
|
// ahead and prepend .k in front of it.
|
|
|
|
if (selector.text.indexOf('html') === -1) {
|
|
|
|
context += prefix + ' ' + selector.text;
|
|
|
|
} else if (selector.text.indexOf('html') !== -1) {
|
|
|
|
// If it contains `html`, replace the `html` with `.k`. Replace
|
|
|
|
// multiple spaces with a single space. This is for the case
|
|
|
|
// where `html input[type='button']` comes through as
|
|
|
|
// `html input[type='button']`.
|
|
|
|
context += selector.text.replace('html', prefix).replace(/ +/g, ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
// If theres another selector, add a comma.
|
|
|
|
if (nextSelector) {
|
|
|
|
context += ',\n';
|
|
|
|
} else {
|
|
|
|
// Otherwise, add an opening bracket for properties
|
|
|
|
context += ' {\n';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Fired right after CSS properties are parsed for a certain rule. Add the
|
|
|
|
// closing bracket to end the CSS Rule.
|
|
|
|
parser.addListener('endrule', function (event) {
|
|
|
|
context += '}\n';
|
|
|
|
});
|
|
|
|
|
|
|
|
// Fired for each property that the parser encounters. Add these properties
|
|
|
|
// to the `css` string with 4 spaces.
|
|
|
|
parser.addListener('property', function (event) {
|
|
|
|
// Add 4 spaces tab.
|
|
|
|
context += ' ' + event.property + ': ' + event.value + ';\n';
|
|
|
|
});
|
|
|
|
|
|
|
|
// Do the parsing.
|
|
|
|
parser.parse(raw);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.registerTask('base-prep', 'Prep Normalize.css import', function () {
|
|
|
|
var normalize = grunt.config('NORMALIZE_LIB');
|
|
|
|
|
|
|
|
grunt.log.write('Looking for Normalize.css'.green);
|
|
|
|
|
|
|
|
if (!grunt.file.exists(normalize)) {
|
|
|
|
grunt.log.writeln('');
|
|
|
|
grunt.fail.fatal('Could not locate Normalize.css repo: ' + normalize + '\nDid you clone it as a sibling of the Kimono');
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.log.writeln('...OK'.white);
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.registerTask('base-all', [
|
|
|
|
'base-prep',
|
2013-05-13 20:56:23 +02:00
|
|
|
'clean:base',
|
2013-05-09 23:56:32 +02:00
|
|
|
'base-import',
|
|
|
|
'base-create-context'
|
|
|
|
]);
|
|
|
|
|
|
|
|
grunt.registerTask('base-import', [
|
|
|
|
'base-import-css',
|
2013-05-13 20:56:23 +02:00
|
|
|
'base-import-tests',
|
|
|
|
'base-import-meta'
|
2013-05-09 23:56:32 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
};
|