Browse Source

Iteration on install process

pull/1191/head
jlukic 10 years ago
parent
commit
627056f67a
8 changed files with 202 additions and 126 deletions
  1. 214
      gulpfile.js
  2. 4
      package.json
  3. 20
      semantic.json
  4. 2
      semantic.json.example
  5. 20
      src/theme.config
  6. 20
      src/theme.config.example
  7. 9
      tasks/gulp-settings.js
  8. 39
      tasks/questions.js

214
gulpfile.js

@ -16,6 +16,7 @@ var
fs = require('fs'),
path = require('path'),
console = require('better-console'),
wrench = require('wrench'),
// gulp dependencies
autoprefixer = require('gulp-autoprefixer'),
@ -50,7 +51,7 @@ var
settings = require('./tasks/gulp-settings'),
// local
overwrite = false,
overwrite = true,
// derived
config,
@ -336,86 +337,10 @@ gulp.task('version', 'Displays current version of Semantic', function(callback)
console.log('Semantic UI ' + package.version);
});
/*--------------
Config
---------------*/
gulp.task('check install', false, function () {
setTimeout(function() {
if( !config ) {
gulp.start('install');
}
else {
gulp.start('watch');
}
}, 50);
});
gulp.task('install', 'Set-up project for first time', function () {
console.clear();
return gulp
.src(defaults.paths.source.config)
.pipe(prompt.prompt(questions.setup, function( answers ) {
var json;
console.info('Creating build.json (build config)');
// message: 'Where should we output Semantic UI?',
// update semantic.json
// message: 'Where should we put your site folder?',
// update semantic.json
// move file from src/_site to (value)
console.info('Creating site theme folder');
// message: 'Where should we put your theme.config file?',
console.info('Creating theme.config (theme config)');
// update semantic.json
// move theme.config.example to (value)
// message: 'Where should we output a packaged version?',
// update semantic.json
// message: 'Where should we output each compressed component?',
// update semantic.json
// message: 'Where should we output each uncompressed component?',
// update semantic.json
if(answers.install == 'auto') {
json = {};
}
else if(answers.install == 'express') {
}
console.log(answers);
gulp.src('semantic.json.example')
.pipe(plumber())
.pipe(rename(settings.rename.json))
.pipe(jeditor(answers))
.pipe(debug())
// .pipe(gulp.dest('./'))
;
// del('semantic.json.example');
console.log('');
console.log('');
}))
/* .pipe(prompt.prompt(questions.site, function( answers ) {
console.clear();
console.log('Creating site theme file');
console.info('Creating site variables file');
}))*/
;
});
gulp.task('config', 'Configure basic site settings', function () {
});
/*--------------
Internal
---------------*/
gulp.task('package uncompressed css', false, function() {
return gulp.src(output.uncompressed + '**/' + compiledFilter + '!(*.min|*.map).css')
.pipe(replace(assetPaths.uncompressed, assetPaths.packaged))
@ -424,6 +349,7 @@ gulp.task('package uncompressed css', false, function() {
.pipe(print(log.created))
;
});
gulp.task('package compressed css', false, function() {
return gulp.src(output.uncompressed + '**/' + compiledFilter + '!(*.min|*.map).css')
.pipe(replace(assetPaths.uncompressed, assetPaths.packaged))
@ -444,6 +370,7 @@ gulp.task('package uncompressed js', false, function() {
.pipe(print(log.created))
;
});
gulp.task('package compressed js', false, function() {
return gulp.src(output.uncompressed + '**/' + compiledFilter + '!(*.min|*.map).js')
.pipe(replace(assetPaths.uncompressed, assetPaths.packaged))
@ -456,6 +383,139 @@ gulp.task('package compressed js', false, function() {
});
/*--------------
Config
---------------*/
gulp.task('check install', false, function () {
setTimeout(function() {
if( !config ) {
console.log('No semantic.json file found. Starting install...');
gulp.start('install');
}
else {
gulp.start('watch');
}
}, 50);
});
gulp.task('install', 'Set-up project for first time', function () {
console.clear();
return gulp
.src(defaults.paths.source.config)
.pipe(prompt.prompt(questions.setup, function( answers ) {
var
trailingSlash = /(\/$)+/mg,
templates = {
theme : './src/theme.config.example',
json : './semantic.json.example',
site : './src/_site'
},
siteDestination = answers.site || './src/site',
configExists = fs.existsSync('./semantic.json'),
themeConfigExists = fs.existsSync('./src/theme.config'),
siteExists = fs.existsSync(siteDestination),
jsonSource = (configExists)
? './semantic.json'
: './semantic.json.example',
json = {
paths: {
source: {},
output: {}
}
}
;
if(answers.overwrite !== undefined && answers.overwrite == 'no') {
return;
}
// create site files
if(siteExists) {
console.info('Site folder exists, merging files (no overwrite)', siteDestination);
}
else {
console.info('Creating site theme folder', siteDestination);
}
// need wrench for recursive copy without overwrite
wrench.copyDirSyncRecursive(templates.site, siteDestination, settings.wrench.recursive);
// write theme less config
if(themeConfigExists) {
console.log('./src/theme.config already exists, skipping');
}
else {
console.info('Creating src/theme.config (LESS config)');
fs.createReadStream(templates.theme)
.pipe(fs.createWriteStream('./src/theme.config', { flags: 'wx+' }))
;
}
// write semantic json config
if(answers.components) {
json.components = answers.components;
}
if(answers.dist) {
answers.dist.replace(trailingSlash, '');
json.paths.output = {
packaged : answers.dist + '/',
uncompressed : answers.dist + '/components/',
compressed : answers.dist + '/components/',
themes : answers.dist + '/themes/'
};
}
if(answers.site) {
answers.site.replace(trailingSlash, '');
json.paths.source.site = answers.site + '/';
}
if(answers.packaged) {
answers.packaged.replace(trailingSlash, '');
json.paths.output.packaged = answers.packaged + '/';
}
if(answers.compressed) {
answers.compressed.replace(trailingSlash, '');
json.paths.output.compressed = answers.compressed + '/';
}
if(answers.uncompressed) {
answers.uncompressed.replace(trailingSlash, '');
json.paths.output.uncompressed = answers.uncompressed + '/';
}
if(configExists) {
console.info('Extending semantic.json (Gulp config)');
gulp.src(jsonSource)
.pipe(plumber())
.pipe(rename(settings.rename.json))
.pipe(jeditor(json))
.pipe(debug())
.pipe(gulp.dest('./'))
;
}
else {
console.info('Creating semantic.json (Gulp config)');
gulp.src(jsonSource)
.pipe(plumber())
.pipe(rename({ extname : '' }))
.pipe(jeditor(json))
.pipe(debug())
.pipe(gulp.dest('./'))
;
}
}))
/* .pipe(prompt.prompt(questions.site, function( answers ) {
console.clear();
console.log('Creating site theme file');
console.info('Creating site variables file');
}))*/
;
});
gulp.task('config', 'Configure basic site settings', function () {
});
/*--------------
Maintainer
---------------*/

4
package.json

@ -34,6 +34,7 @@
"gulp-flatten": "0.0.4",
"gulp-header": "^1.1.1",
"gulp-help": "^1.2.0",
"gulp-json-editor": "^2.1.0",
"gulp-karma": "0.0.4",
"gulp-less": "^1.3.6",
"gulp-minify-css": "^0.3.10",
@ -47,6 +48,7 @@
"gulp-uglify": "^1.0.1",
"gulp-util": "^3.0.1",
"gulp-watch": "^1.1.0",
"rtlcss": "^1.4.0"
"rtlcss": "^1.4.0",
"wrench": "^1.5.8"
}
}

20
semantic.json

@ -1,20 +0,0 @@
{
"base": "",
"paths": {
"source": {
"config" : "src/semantic.config",
"definitions" : "src/definitions/",
"site" : "src/site/",
"themes" : "src/themes/"
},
"output": {
"packaged" : "dist/",
"uncompressed" : "dist/components/",
"compressed" : "dist/components/",
"themes" : "dist/themes"
},
"clean" : "dist/"
}
}

2
semantic.json.example

@ -3,7 +3,7 @@
"paths": {
"source": {
"config" : "src/semantic.config",
"config" : "src/theme.config",
"definitions" : "src/definitions/",
"site" : "src/site/",
"themes" : "src/themes/"

20
src/theme.config

@ -14,10 +14,10 @@
*******************************/
/* Path to theme packages */
@packagesFolder : 'themes/';
@themesFolder : 'themes/';
/* Path to site override folder */
@userFolder : '_site/';
@siteFolder : '_site/';
/*******************************
@ -96,30 +96,30 @@
Load Default
-------------------*/
@import "@{packagesFolder}/default/globals/site.variables";
@import "@{packagesFolder}/default/@{type}s/@{element}.variables";
@import "@{themesFolder}/default/globals/site.variables";
@import "@{themesFolder}/default/@{type}s/@{element}.variables";
/*------------------
Load Theme
-------------------*/
@import "@{packagesFolder}/@{site}/globals/site.variables";
@import "@{packagesFolder}/@{theme}/@{type}s/@{element}.variables";
@import "@{themesFolder}/@{site}/globals/site.variables";
@import "@{themesFolder}/@{theme}/@{type}s/@{element}.variables";
/*------------------
Load Site
-------------------*/
@import "@{userFolder}/globals/site.variables";
@import "@{userFolder}/@{type}s/@{element}.variables";
@import "@{siteFolder}/globals/site.variables";
@import "@{siteFolder}/@{type}s/@{element}.variables";
/*------------------
Overrides
-------------------*/
.loadUIOverrides() {
@import "@{packagesFolder}/@{theme}/@{type}s/@{element}.overrides";
@import "@{userFolder}/@{type}s/@{element}.overrides";
@import "@{themesFolder}/@{theme}/@{type}s/@{element}.overrides";
@import "@{siteFolder}/@{type}s/@{element}.overrides";
}
/* End Config */

20
src/theme.config.example

@ -14,10 +14,10 @@
*******************************/
/* Path to theme packages */
@packagesFolder : 'themes/';
@themesFolder : 'themes/';
/* Path to site override folder */
@userFolder : '_site/';
@siteFolder : '_site/';
/*******************************
@ -96,30 +96,30 @@
Load Default
-------------------*/
@import "@{packagesFolder}/default/globals/site.variables";
@import "@{packagesFolder}/default/@{type}s/@{element}.variables";
@import "@{themesFolder}/default/globals/site.variables";
@import "@{themesFolder}/default/@{type}s/@{element}.variables";
/*------------------
Load Theme
-------------------*/
@import "@{packagesFolder}/@{site}/globals/site.variables";
@import "@{packagesFolder}/@{theme}/@{type}s/@{element}.variables";
@import "@{themesFolder}/@{site}/globals/site.variables";
@import "@{themesFolder}/@{theme}/@{type}s/@{element}.variables";
/*------------------
Load Site
-------------------*/
@import "@{userFolder}/globals/site.variables";
@import "@{userFolder}/@{type}s/@{element}.variables";
@import "@{siteFolder}/globals/site.variables";
@import "@{siteFolder}/@{type}s/@{element}.variables";
/*------------------
Overrides
-------------------*/
.loadUIOverrides() {
@import "@{packagesFolder}/@{theme}/@{type}s/@{element}.overrides";
@import "@{userFolder}/@{type}s/@{element}.overrides";
@import "@{themesFolder}/@{theme}/@{type}s/@{element}.overrides";
@import "@{siteFolder}/@{type}s/@{element}.overrides";
}
/* End Config */

9
tasks/gulp-settings.js

@ -31,8 +31,15 @@ module.exports = {
sourceRoot : '/src'
},
rename: {
json : { extname : '' },
json : { extname : '.json' },
minJS : { extname : '.min.js' },
minCSS : { extname : '.min.css' }
},
wrench: {
recursive: {
forceDelete: false,
excludeHiddenUnix: true,
preserveFiles: true
}
}
};

39
tasks/questions.js

@ -2,21 +2,31 @@
Install Questions
*******************************/
var defaults, when;
var defaults, fs, when;
fs = require('fs');
defaults = require('./defaults');
when = {
// set-up
hasConfig: function() {
return( fs.existsSync('./semantic.json') );
},
allowOverwrite: function(questions) {
return (questions.overwrite === undefined || questions.overwrite == 'yes');
},
notAuto: function(questions) {
console.log(questions.install);
return (questions.install !== 'auto');
return (questions.install !== 'auto' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
},
custom: function(questions) {
return (questions.install === 'custom');
return (questions.install === 'custom' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
},
express: function(questions) {
return (questions.install === 'express');
return (questions.install === 'express' && (questions.overwrite === undefined || questions.overwrite == 'yes'));
},
// customize
customize: function(questions) {
return (questions.customize === true);
},
@ -31,10 +41,27 @@ when = {
module.exports = {
setup: [
{
type: 'list',
name: 'overwrite',
message: 'It looks like you have a semantic.json file already.',
when: when.hasConfig,
choices: [
{
name: 'Yes, extend my current settings.',
value: 'yes'
},
{
name: 'Exit install',
value: 'no'
}
]
},
{
type: 'list',
name: 'install',
message: 'Set-up Themed Semantic UI (First-Run)',
message: 'Set-up Semantic UI',
when: when.allowOverwrite,
choices: [
{
name: 'Automatic (Use defaults locations and all components)',

Loading…
Cancel
Save