Browse Source

Iterating on install

pull/1785/head
jlukic 9 years ago
parent
commit
42b176cc7a
2 changed files with 72 additions and 68 deletions
  1. 32
      tasks/config/project/install.js
  2. 108
      tasks/install.js

32
tasks/config/project/install.js

@ -81,42 +81,39 @@ module.exports = {
getPackageManager: function(directory) {
var
// returns last matching result (avoid sub-module detection)
packageManager,
walk = function(directory) {
var
pathArray = directory.split('/'),
folder = pathArray[pathArray.length - 1],
nextDirectory = path.normalize(directory + '../')
folder = pathArray[pathArray.length - 2],
nextDirectory = path.normalize(directory + '/../')
;
if( folder == 'bower_components') {
packageManager = {
return {
name: 'Bower',
root: nextDirectory
};
}
else if(folder == 'node_modules') {
packageManager = {
return {
name: 'NPM',
root: nextDirectory
};
}
else if(folder == 'composer') {
packageManager = {
return {
name: 'Composer',
root: nextDirectory
};
}
console.log(folder);
if(path.resolve(directory) == '/') {
console.log(packageManager);
return packageManager || false;
return false;
}
// recurse downward
return walk(nextDirectory);
}
;
// start walk from outside component folder
directory = directory || (__dirname);
// start walk from current directory if none specified
directory = directory || (__dirname + '/');
return walk(directory);
},
@ -188,12 +185,6 @@ module.exports = {
'./src/_site'
],
files: {
config : 'semantic.json',
site : 'src/site',
theme : 'src/theme.config'
},
regExp: {
// used to match siteFolder variable in theme.less
siteVariable: /@siteFolder .*\'(.*)/mg
@ -212,6 +203,13 @@ module.exports = {
userGulpFile : './tasks/config/npm/gulpfile.js'
},
// expected final filenames
files: {
config : 'semantic.json',
site : 'src/site',
themeConfig : 'src/theme.config'
},
// folder paths to files relative to root
folders: {
config : './',

108
tasks/install.js

@ -45,11 +45,11 @@ var
// shorthand
questions = install.questions,
files = install.files,
folders = install.folders,
regExp = install.regExp,
settings = install.settings,
source = install.source
;
// Export install task
@ -61,9 +61,9 @@ module.exports = function () {
rootQuestions = questions.root
;
/* console.clear();
console.clear();
// use to debug NPM install from standard git clone
/* use to debug NPM install from standard git clone
manager = {
name : 'NPM',
root : path.normalize(__dirname + '/../')
@ -79,7 +79,7 @@ module.exports = function () {
var
updateFolder = manager.root,
updatePaths = {
config : path.join(updateFolder, install.files.config),
config : path.join(updateFolder, files.config),
modules : path.join(updateFolder, currentConfig.base, folders.modules),
tasks : path.join(updateFolder, currentConfig.base, folders.tasks),
definition : path.join(updateFolder, currentConfig.paths.source.definitions),
@ -201,11 +201,16 @@ module.exports = function () {
};
// 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);
try {
mkdirp.sync(installFolder);
mkdirp.sync(installPaths.definition);
mkdirp.sync(installPaths.theme);
mkdirp.sync(installPaths.modules);
mkdirp.sync(installPaths.tasks);
}
catch(error) {
console.error('NPM does not have permissions to create folders at your specified path. Adjust your folders permissions and run "npm install" again');
}
// fs.renameSync(oldPath, newPath); swap to move before debut
// copy gulp node_modules
@ -229,59 +234,59 @@ module.exports = function () {
}
/*--------------
Site Theme
Resolve Paths
---------------*/
var
configDestination,
siteDestination,
pathToSite,
siteVariable
;
installPaths = {
config : files.config,
site : answers.site || folders.site,
themeConfig : files.themeConfig
};
// determine path to site folder from src/
siteDestination = answers.site || folders.site;
configDestination = folders.themeConfig;
// add base path when npm install
// add install folder to all output paths
if(installFolder) {
siteDestination = installFolder + siteDestination;
configDestination = installFolder + configDestination;
for(var destination in installPaths) {
if(installPaths.hasOwnProperty(destination)) {
installPaths[destination] = path.normalize( path.join(installFolder, installPaths[destination]) );
}
}
}
// 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 + "/';";
/*--------------
Site Theme
---------------*/
// force less variables to use forward slashes for paths
pathToSite = pathToSite.replace(/\\/g,'/');
// create site files
if( fs.existsSync(siteDestination) ) {
console.info('Site folder exists, merging files (no overwrite)', siteDestination);
// Copy _site templates folder to destination
if( fs.existsSync(installPaths.site) ) {
console.info('Site folder exists, merging files (no overwrite)', installPaths.site);
}
else {
console.info('Creating site theme folder', siteDestination);
console.info('Creating site theme folder', installPaths.site);
}
wrench.copyDirSyncRecursive(source.site, installPaths.site, settings.wrench.site);
/*--------------
Theme Config
---------------*/
var
// determine path to site theme folder from theme config
// force CSS path variable to use forward slashes for paths
pathToSite = path.relative(path.resolve(files.themeConfig), path.resolve(installPaths.site)).replace(/\\/g,'/'),
siteVariable = "@siteFolder : '" + pathToSite + "/';"
;
// rewrite site variable in theme.less
console.info('Adjusting @siteFolder', siteVariable);
if(fs.existsSync(config.files.theme)) {
if(fs.existsSync(installPaths.themeConfig)) {
console.info('Modifying src/theme.config (LESS config)');
gulp.src(config.files.site)
gulp.src(installPaths.themeConfig)
.pipe(plumber())
.pipe(replace(regExp.siteVariable, siteVariable))
.pipe(gulp.dest(folders.themeConfig))
.pipe(gulp.dest(installPaths.themeConfig))
;
}
else {
@ -290,7 +295,7 @@ module.exports = function () {
.pipe(plumber())
.pipe(rename({ extname : '' }))
.pipe(replace(regExp.siteVariable, siteVariable))
.pipe(gulp.dest(folders.themeConfig))
.pipe(gulp.dest(installPaths.themeConfig))
;
}
@ -299,29 +304,30 @@ module.exports = function () {
---------------*/
var
configExists = fs.existsSync(config.files.config),
json = install.createJSON(answers),
jsonSource = (configExists)
? config.files.config
: source.config
jsonConfig = install.createJSON(answers)
;
// add base path when given an install folder (theme.config must exist in specified location)
if(installFolder) {
installPaths.config = path.resolve(path.join(installFolder, installPaths.config));
}
// adjust variables in theme.less
if(configExists) {
if( fs.existsSync(files.config) ) {
console.info('Extending config file (semantic.json)');
gulp.src(jsonSource)
gulp.src(files.config)
.pipe(plumber())
.pipe(rename(settings.rename.json)) // preserve file extension
.pipe(jsonEditor(json))
.pipe(jsonEditor(jsonConfig))
.pipe(gulp.dest('./'))
;
}
else {
console.info('Creating config file (semantic.json)');
gulp.src(jsonSource)
gulp.src(source.config)
.pipe(plumber())
.pipe(rename({ extname : '' })) // remove .template from ext
.pipe(jsonEditor(json))
.pipe(jsonEditor(jsonConfig))
.pipe(gulp.dest('./'))
;
}
@ -334,7 +340,7 @@ module.exports = function () {
}
if(answers.build == 'yes') {
// needs replacement for rewrite
// config = require(config.files.config);
// config = require(files.config);
// getConfigValues();
gulp.start('build');
}

Loading…
Cancel
Save