diff --git a/tasks/config/project/docs.js b/tasks/config/docs.js similarity index 90% rename from tasks/config/project/docs.js rename to tasks/config/docs.js index 43ad2f6fa..ff53354e3 100644 --- a/tasks/config/project/docs.js +++ b/tasks/config/docs.js @@ -2,8 +2,7 @@ Docs *******************************/ -/* Custom paths config for serving docs */ - +/* Paths used for "serve-docs" and "build-docs" tasks */ module.exports = { base: '', paths: { diff --git a/tasks/config/npm/gulpfile.js b/tasks/config/npm/gulpfile.js new file mode 100644 index 000000000..edf0422f5 --- /dev/null +++ b/tasks/config/npm/gulpfile.js @@ -0,0 +1,31 @@ +/******************************* + Set-up +*******************************/ + +var + gulp = require('gulp-help')(require('gulp')), + + // read user config to know what task to load + config = require('./tasks/config/user'), + + // import tasks + build = require('./tasks/build'), + clean = require('./tasks/clean'), + version = require('./tasks/version'), + watch = require('./tasks/watch') +; + + +/*-------------- + Public +---------------*/ + +gulp.task('watch', 'Watch for site/theme changes', watch); +gulp.task('build', 'Builds all files from source', build); + +gulp.task('clean', 'Clean dist folder', clean); +gulp.task('version', 'Displays current version of Semantic', version); + +gulp.task('default', false, [ + 'watch' +]); \ No newline at end of file diff --git a/tasks/config/project/install.js b/tasks/config/project/install.js index adb34c62f..fbb3122ed 100644 --- a/tasks/config/project/install.js +++ b/tasks/config/project/install.js @@ -6,6 +6,7 @@ var fs = require('fs'), path = require('path'), defaults = require('../defaults'), + release = require('./release'), requireDotFile = require('require-dot-file') ; @@ -82,6 +83,8 @@ module.exports = { // checks if files are in a PM directory getPackageManager: function(directory) { var + // returns last matching result (avoid sub-module detection) + packageManager, walk = function(directory) { var pathArray = directory.split('/'), @@ -89,40 +92,32 @@ module.exports = { nextDirectory = path.normalize(directory + '../') ; if( folder == 'bower_components') { - return { + packageManager = { name: 'Bower', root: nextDirectory }; } else if(folder == 'node_modules') { - return { + packageManager = { name: 'NPM', root: nextDirectory }; } else if(folder == 'composer') { - return { + packageManager = { name: 'Composer', root: nextDirectory }; } - else if(folder == 'components' || folder == 'modules') { - return { - name: 'a custom module system', - root: nextDirectory - }; - } else { - // reached file system root, let's stop if(path.resolve(directory) == '/') { - return false; + return packageManager; } // recurse return walk(nextDirectory); } } ; - // start walk from outside component folder directory = directory || (__dirname + '/../'); return walk(directory); @@ -138,49 +133,53 @@ module.exports = { } ; - // add path to semantic - if(answers.semanticRoot) { - json.base = answers.semanticRoot; - } - // add components if(answers.components) { json.components = answers.components; } + // add rtl choice + if(answers.rtl) { + json.rtl = answers.rtl; + } + // add permissions if(answers.permission) { json.permission = answers.permission; } + // add path to semantic + if(answers.semanticRoot) { + json.base = path.normalize(answers.semanticRoot); + } + + // record version number to avoid re-installing on same version + json.version = release.version; + // add dist folder paths if(answers.dist) { - answers.dist = answers.dist; + answers.dist = path.normalize(answers.dist); + json.paths.output = { - packaged : answers.dist + '/', - uncompressed : answers.dist + '/components/', - compressed : answers.dist + '/components/', - themes : answers.dist + '/themes/' + packaged : path.normalize(answers.dist + '/'), + uncompressed : path.normalize(answers.dist + '/components/'), + compressed : path.normalize(answers.dist + '/components/'), + themes : path.normalize(answers.dist + '/themes/') }; } - // add rtl choice - if(answers.rtl) { - json.rtl = answers.rtl; - } - // add site path if(answers.site) { - json.paths.source.site = answers.site + '/'; + json.paths.source.site = path.normalize(answers.site + '/'); } if(answers.packaged) { - json.paths.output.packaged = answers.packaged + '/'; + json.paths.output.packaged = path.normalize(answers.packaged + '/'); } if(answers.compressed) { - json.paths.output.compressed = answers.compressed + '/'; + json.paths.output.compressed = path.normalize(answers.compressed + '/'); } if(answers.uncompressed) { - json.paths.output.uncompressed = answers.uncompressed + '/'; + json.paths.output.uncompressed = path.normalize(answers.uncompressed + '/'); } return json; }, @@ -198,27 +197,33 @@ module.exports = { theme : 'src/theme.co nfig' }, + regExp: { + // used to match siteFolder variable in theme.less + siteVariable: /@siteFolder .*\'(.*)/mg + }, + // source paths (relative to tasks/install.js ) source: { - config : './semantic.json.example', - definitions : './src/definitions', - gulpFile : './gulpfile.js', - modules : './node_modules/', - site : './src/_site', - tasks : './tasks', - themes : './src/themes', - themeConfig : './src/theme.config.example' + config : './semantic.json.example', + definitions : './src/definitions', + gulpFile : './gulpfile.js', + modules : './node_modules/', + site : './src/_site', + tasks : './tasks', + themeConfig : './src/theme.config.example', + themes : './src/themes', + userGulpFile : './tasks/config/npm/gulpfile.js' }, // folder paths to files relative to root folders: { + config : './', definitions : 'src/definitions/', - themes : 'src/themes/', modules : 'node_modules/', - tasks : 'tasks/', site : 'src/site', - config : './', - theme : './src/' + tasks : 'tasks/', + themeConfig : 'src/', + themes : 'src/themes/' }, // questions asked during install diff --git a/tasks/config/project/release.js b/tasks/config/project/release.js index 7a4152c2c..3dcf2f01b 100644 --- a/tasks/config/project/release.js +++ b/tasks/config/project/release.js @@ -4,7 +4,9 @@ var requireDotFile = require('require-dot-file'), - package + config, + package, + version ; @@ -13,8 +15,16 @@ var *******************************/ try { - // looks for config file across all parent directories + + config = requireDotFile('semantic.json'); package = requireDotFile('package.json'); + + // looks for version in config or package.json (whichever is available) + version = (config && config.version !== undefined) + ? config.version + : package.version + ; + } catch(error) { diff --git a/tasks/install.js b/tasks/install.js index cafaf077e..badfa9db5 100644 --- a/tasks/install.js +++ b/tasks/install.js @@ -32,6 +32,7 @@ var // shorthand questions = install.questions, folders = install.folders, + regExp = install.regExp, settings = install.settings, source = install.source @@ -65,8 +66,8 @@ module.exports = function () { definition : path.join(manager.root, currentConfig.paths.source.definitions), theme : path.join(manager.root, currentConfig.paths.source.themes), site : path.join(manager.root, currentConfig.paths.source.site), - modules : path.join(manager.root, folders.modules), - tasks : path.join(manager.root, folders.tasks) + modules : path.join(manager.root, currentConfig.base + folders.modules), + tasks : path.join(manager.root, currentConfig.base + folders.tasks) } ; @@ -74,12 +75,13 @@ module.exports = function () { if( fs.existsSync(updatePaths.definition) ) { console.info('Updating ui definitions to ' + release.version); + // fs.renameSync(oldPath, newPath); swap to move before debut wrench.copyDirSyncRecursive(source.definitions, updatePaths.definition, settings.wrench.update); - console.info('Updating default theme to' + release.version); + console.info('Updating default theme to ' + release.version); wrench.copyDirSyncRecursive(source.themes, updatePaths.theme, settings.wrench.update); - console.info('Updating additional files...'); + console.info('Updating gulp tasks...'); wrench.copyDirSyncRecursive(source.modules, updatePaths.modules, settings.wrench.update); wrench.copyDirSyncRecursive(source.tasks, updatePaths.tasks, settings.wrench.update); wrench.copyDirSyncRecursive(source.site, updatePaths.site, settings.wrench.site); @@ -137,21 +139,21 @@ module.exports = function () { /*-------------- NPM Install ---------------*/ + var + installPaths = {}, + installFolder + ; if(answers.useRoot || answers.customRoot) { - var - installFolder, - installPaths = {}, - gulpRoot, - gulpFileExists - ; - // Set root to custom root path if set if(answers.customRoot) { manager.root = answers.customRoot; } + console.log(currentConfig.version, release.version); + return; + // Copy semantic if(answers.semanticRoot) { @@ -165,25 +167,26 @@ module.exports = function () { tasks : path.resolve( path.join(installFolder, folders.tasks) ) }; - // create project folder if doesnt exist + // create project folders if doesnt exist mkdirp.sync(installFolder); mkdirp.sync(installPaths.definition); mkdirp.sync(installPaths.theme); mkdirp.sync(installPaths.modules); mkdirp.sync(installPaths.tasks); + // fs.renameSync(oldPath, newPath); swap to move before debut // copy gulp node_modules - console.info('Copying definitions to ', answers.semanticRoot); + console.info('Copying definitions to ', installPaths.definition); wrench.copyDirSyncRecursive(source.definitions, installPaths.definition, settings.wrench.install); wrench.copyDirSyncRecursive(source.themes, installPaths.theme, settings.wrench.install); - console.info('Copying build tools', answers.semanticRoot); + console.info('Copying build tools', installPaths.tasks); wrench.copyDirSyncRecursive(source.modules, installPaths.modules, settings.wrench.install); wrench.copyDirSyncRecursive(source.tasks, installPaths.tasks, settings.wrench.install); // create gulp file console.info('Creating gulp-file.js'); - gulp.src(source.gulpFile) + gulp.src(source.userGulpFile) .pipe(plumber()) .pipe(gulp.dest(installFolder)) ; @@ -195,39 +198,57 @@ module.exports = function () { /*-------------- - Site Themes + Site Theme ---------------*/ var - siteVariable = /@siteFolder .*\'(.*)/mg, - siteDestination = answers.site || folders.site, + configDestination, + siteDestination, + pathToSite, + siteVariable + ; - siteExists = fs.existsSync(siteDestination), - themeConfigExists = fs.existsSync(config.files.theme), + // determine path to site folder from src/ + siteDestination = answers.site || folders.site; + configDestination = folders.themeConfig; - pathToSite = path.relative(path.resolve(folders.theme), path.resolve(siteDestination)).replace(/\\/g,'/'), - sitePathReplace = "@siteFolder : '" + pathToSite + "/';" - ; + // add base path when npm install + if(installFolder) { + siteDestination = installFolder + siteDestination; + configDestination = installFolder + configDestination; + } + + // Copy _site templates without overwrite current site theme + wrench.copyDirSyncRecursive(source.site, siteDestination, settings.wrench.site); + + // determine path to _site folder from theme config + pathToSite = path.relative(path.resolve(folders.themeConfig), path.resolve(siteDestination)); + siteVariable = "@siteFolder : '" + pathToSite + "/';"; + + // force less variables to use forward slashes for paths + pathToSite = pathToSite.replace(/\\/g,'/'); // create site files - if(siteExists) { + if( fs.existsSync(siteDestination) ) { console.info('Site folder exists, merging files (no overwrite)', siteDestination); } else { console.info('Creating site theme folder', siteDestination); } - // Copy _site template without overwrite - wrench.copyDirSyncRecursive(source.site, siteDestination, settings.wrench.site); + /*-------------- + Theme Config + ---------------*/ + // rewrite site variable in theme.less + console.info('Adjusting @siteFolder', siteVariable); - // Adjust theme.less in project folder - console.info('Adjusting @siteFolder', sitePathReplace); - if(themeConfigExists) { + if(fs.existsSync(config.files.theme)) { + console.info('Modifying src/theme.config (LESS config)'); gulp.src(config.files.site) .pipe(plumber()) - .pipe(replace(siteVariable, sitePathReplace)) - .pipe(gulp.dest(folders.theme)) + .pipe(replace(regExp.siteVariable, siteVariable)) + .pipe(gulp.dest(folders.themeConfig)) ; } else { @@ -235,8 +256,8 @@ module.exports = function () { gulp.src(source.themeConfig) .pipe(plumber()) .pipe(rename({ extname : '' })) - .pipe(replace(siteVariable, sitePathReplace)) - .pipe(gulp.dest(folders.theme)) + .pipe(replace(regExp.siteVariable, siteVariable)) + .pipe(gulp.dest(folders.themeConfig)) ; }