Update Semantic
Fixes #40,#24
This commit is contained in:
parent
1715f27f44
commit
2027b94179
621 changed files with 172488 additions and 15939 deletions
332
web/semantic/tasks/admin/components/create.js
Normal file
332
web/semantic/tasks/admin/components/create.js
Normal file
|
@ -0,0 +1,332 @@
|
|||
/*******************************
|
||||
Create Component Repos
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
This will create individual component repositories for each SUI component
|
||||
|
||||
* copy component files from release
|
||||
* create commonjs files as index.js for NPM release
|
||||
* create release notes that filter only items related to component
|
||||
* custom package.json file from template
|
||||
* create bower.json from template
|
||||
* create README from template
|
||||
* create meteor.js file
|
||||
*/
|
||||
|
||||
var
|
||||
gulp = require('gulp'),
|
||||
|
||||
// node dependencies
|
||||
console = require('better-console'),
|
||||
del = require('del'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
runSequence = require('run-sequence'),
|
||||
|
||||
// admin dependencies
|
||||
concatFileNames = require('gulp-concat-filenames'),
|
||||
debug = require('gulp-debug'),
|
||||
flatten = require('gulp-flatten'),
|
||||
git = require('gulp-git'),
|
||||
jsonEditor = require('gulp-json-editor'),
|
||||
plumber = require('gulp-plumber'),
|
||||
rename = require('gulp-rename'),
|
||||
replace = require('gulp-replace'),
|
||||
tap = require('gulp-tap'),
|
||||
util = require('gulp-util'),
|
||||
|
||||
// config
|
||||
config = require('../../config/user'),
|
||||
release = require('../../config/admin/release'),
|
||||
project = require('../../config/project/release'),
|
||||
|
||||
// shorthand
|
||||
version = project.version,
|
||||
output = config.paths.output
|
||||
|
||||
;
|
||||
|
||||
|
||||
module.exports = function(callback) {
|
||||
var
|
||||
stream,
|
||||
index,
|
||||
tasks = []
|
||||
;
|
||||
|
||||
for(index in release.components) {
|
||||
|
||||
var
|
||||
component = release.components[index]
|
||||
;
|
||||
|
||||
// streams... designed to save time and make coding fun...
|
||||
(function(component) {
|
||||
|
||||
var
|
||||
outputDirectory = path.join(release.outputRoot, component),
|
||||
isJavascript = fs.existsSync(output.compressed + component + '.js'),
|
||||
isCSS = fs.existsSync(output.compressed + component + '.css'),
|
||||
capitalizedComponent = component.charAt(0).toUpperCase() + component.slice(1),
|
||||
packageName = release.packageRoot + component,
|
||||
repoName = release.componentRepoRoot + capitalizedComponent,
|
||||
gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
|
||||
repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
|
||||
concatSettings = {
|
||||
newline : '',
|
||||
root : outputDirectory,
|
||||
prepend : " '",
|
||||
append : "',"
|
||||
},
|
||||
regExp = {
|
||||
match : {
|
||||
// templated values
|
||||
name : '{component}',
|
||||
titleName : '{Component}',
|
||||
version : '{version}',
|
||||
files : '{files}',
|
||||
// release notes
|
||||
spacedVersions : /(###.*\n)\n+(?=###)/gm,
|
||||
spacedLists : /(^- .*\n)\n+(?=^-)/gm,
|
||||
trim : /^\s+|\s+$/g,
|
||||
unrelatedNotes : new RegExp('^((?!(^.*(' + component + ').*$|###.*)).)*$', 'gmi'),
|
||||
whitespace : /\n\s*\n\s*\n/gm,
|
||||
// npm
|
||||
export : /\$\.fn\.\w+\s*=\s*function\(parameters\)\s*{/g,
|
||||
formExport : /\$\.fn\.\w+\s*=\s*function\(fields, parameters\)\s*{/g,
|
||||
settingsExport : /\$\.fn\.\w+\.settings\s*=/g,
|
||||
settingsReference : /\$\.fn\.\w+\.settings/g,
|
||||
trailingComma : /,(?=[^,]*$)/,
|
||||
jQuery : /jQuery/g,
|
||||
},
|
||||
replace : {
|
||||
// readme
|
||||
name : component,
|
||||
titleName : capitalizedComponent,
|
||||
// release notes
|
||||
spacedVersions : '',
|
||||
spacedLists : '$1',
|
||||
trim : '',
|
||||
unrelatedNotes : '',
|
||||
whitespace : '\n\n',
|
||||
// npm
|
||||
export : 'module.exports = function(parameters) {\n var _module = module;\n',
|
||||
formExport : 'module.exports = function(fields, parameters) {\n var _module = module;\n',
|
||||
settingsExport : 'module.exports.settings =',
|
||||
settingsReference : '_module.exports.settings',
|
||||
jQuery : 'require("jquery")'
|
||||
}
|
||||
},
|
||||
task = {
|
||||
all : component + ' creating',
|
||||
repo : component + ' create repo',
|
||||
bower : component + ' create bower.json',
|
||||
readme : component + ' create README',
|
||||
npm : component + ' create NPM Module',
|
||||
notes : component + ' create release notes',
|
||||
composer : component + ' create composer.json',
|
||||
package : component + ' create package.json',
|
||||
meteor : component + ' create meteor package.js',
|
||||
},
|
||||
// paths to includable assets
|
||||
manifest = {
|
||||
assets : outputDirectory + '/assets/**/' + component + '?(s).*',
|
||||
component : outputDirectory + '/' + component + '+(.js|.css)'
|
||||
}
|
||||
;
|
||||
|
||||
// copy dist files into output folder adjusting asset paths
|
||||
gulp.task(task.repo, false, function() {
|
||||
return gulp.src(release.source + component + '.*')
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(replace(release.paths.source, release.paths.output))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// create npm module
|
||||
gulp.task(task.npm, false, function() {
|
||||
return gulp.src(release.source + component + '!(*.min|*.map).js')
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(replace(regExp.match.export, regExp.replace.export))
|
||||
.pipe(replace(regExp.match.formExport, regExp.replace.formExport))
|
||||
.pipe(replace(regExp.match.settingsExport, regExp.replace.settingsExport))
|
||||
.pipe(replace(regExp.match.settingsReference, regExp.replace.settingsReference))
|
||||
.pipe(replace(regExp.match.jQuery, regExp.replace.jQuery))
|
||||
.pipe(rename('index.js'))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// create readme
|
||||
gulp.task(task.readme, false, function() {
|
||||
return gulp.src(release.templates.readme)
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(replace(regExp.match.name, regExp.replace.name))
|
||||
.pipe(replace(regExp.match.titleName, regExp.replace.titleName))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// extend bower.json
|
||||
gulp.task(task.bower, false, function() {
|
||||
return gulp.src(release.templates.bower)
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(jsonEditor(function(bower) {
|
||||
bower.name = packageName;
|
||||
bower.description = capitalizedComponent + ' - Semantic UI';
|
||||
if(isJavascript) {
|
||||
if(isCSS) {
|
||||
bower.main = [
|
||||
component + '.js',
|
||||
component + '.css'
|
||||
];
|
||||
}
|
||||
else {
|
||||
bower.main = [
|
||||
component + '.js'
|
||||
];
|
||||
}
|
||||
bower.dependencies = {
|
||||
jquery: '>=1.8'
|
||||
};
|
||||
}
|
||||
else {
|
||||
bower.main = [
|
||||
component + '.css'
|
||||
];
|
||||
}
|
||||
return bower;
|
||||
}))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// extend package.json
|
||||
gulp.task(task.package, false, function() {
|
||||
return gulp.src(release.templates.package)
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(jsonEditor(function(package) {
|
||||
if(isJavascript) {
|
||||
package.dependencies = {
|
||||
jquery: 'x.x.x'
|
||||
};
|
||||
package.main = 'index.js';
|
||||
}
|
||||
package.name = packageName;
|
||||
if(version) {
|
||||
package.version = version;
|
||||
}
|
||||
package.title = 'Semantic UI - ' + capitalizedComponent;
|
||||
package.description = 'Single component release of ' + component;
|
||||
package.repository = {
|
||||
type : 'git',
|
||||
url : gitURL
|
||||
};
|
||||
return package;
|
||||
}))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// extend composer.json
|
||||
gulp.task(task.composer, false, function() {
|
||||
return gulp.src(release.templates.composer)
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(jsonEditor(function(composer) {
|
||||
if(isJavascript) {
|
||||
composer.dependencies = {
|
||||
jquery: 'x.x.x'
|
||||
};
|
||||
composer.main = component + '.js';
|
||||
}
|
||||
composer.name = 'semantic/' + component;
|
||||
if(version) {
|
||||
composer.version = version;
|
||||
}
|
||||
composer.description = 'Single component release of ' + component;
|
||||
return composer;
|
||||
}))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// create release notes
|
||||
gulp.task(task.notes, false, function() {
|
||||
return gulp.src(release.templates.notes)
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
// Remove release notes for lines not mentioning component
|
||||
.pipe(replace(regExp.match.unrelatedNotes, regExp.replace.unrelatedNotes))
|
||||
.pipe(replace(regExp.match.whitespace, regExp.replace.whitespace))
|
||||
.pipe(replace(regExp.match.spacedVersions, regExp.replace.spacedVersions))
|
||||
.pipe(replace(regExp.match.spacedLists, regExp.replace.spacedLists))
|
||||
.pipe(replace(regExp.match.trim, regExp.replace.trim))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
// Creates meteor package.js
|
||||
gulp.task(task.meteor, function() {
|
||||
var
|
||||
filenames = ''
|
||||
;
|
||||
return gulp.src(manifest.component)
|
||||
.pipe(concatFileNames('empty.txt', concatSettings))
|
||||
.pipe(tap(function(file) {
|
||||
filenames += file.contents;
|
||||
}))
|
||||
.on('end', function() {
|
||||
gulp.src(manifest.assets)
|
||||
.pipe(concatFileNames('empty.txt', concatSettings))
|
||||
.pipe(tap(function(file) {
|
||||
filenames += file.contents;
|
||||
}))
|
||||
.on('end', function() {
|
||||
// remove trailing slash
|
||||
filenames = filenames.replace(regExp.match.trailingComma, '').trim();
|
||||
gulp.src(release.templates.meteor.component)
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(replace(regExp.match.name, regExp.replace.name))
|
||||
.pipe(replace(regExp.match.titleName, regExp.replace.titleName))
|
||||
.pipe(replace(regExp.match.version, version))
|
||||
.pipe(replace(regExp.match.files, filenames))
|
||||
.pipe(rename(release.files.meteor))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
})
|
||||
;
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
|
||||
// synchronous tasks in orchestrator? I think not
|
||||
gulp.task(task.all, false, function(callback) {
|
||||
runSequence([
|
||||
task.repo,
|
||||
task.npm,
|
||||
task.bower,
|
||||
task.readme,
|
||||
task.package,
|
||||
task.composer,
|
||||
task.notes,
|
||||
task.meteor
|
||||
], callback);
|
||||
});
|
||||
|
||||
tasks.push(task.all);
|
||||
|
||||
})(component);
|
||||
}
|
||||
|
||||
runSequence(tasks, callback);
|
||||
};
|
170
web/semantic/tasks/admin/components/init.js
Normal file
170
web/semantic/tasks/admin/components/init.js
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*******************************
|
||||
Init Repos
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
|
||||
This task pulls the latest version of each component from GitHub
|
||||
|
||||
* Creates new repo if doesnt exist (locally & GitHub)
|
||||
* Adds remote it doesnt exists
|
||||
* Pulls latest changes from repo
|
||||
|
||||
*/
|
||||
|
||||
var
|
||||
gulp = require('gulp'),
|
||||
|
||||
// node dependencies
|
||||
console = require('better-console'),
|
||||
del = require('del'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
git = require('gulp-git'),
|
||||
githubAPI = require('github'),
|
||||
mkdirp = require('mkdirp'),
|
||||
|
||||
// admin files
|
||||
github = require('../../config/admin/github.js'),
|
||||
release = require('../../config/admin/release'),
|
||||
project = require('../../config/project/release'),
|
||||
|
||||
|
||||
// oAuth configuration for GitHub
|
||||
oAuth = fs.existsSync(__dirname + '/../../config/admin/oauth.js')
|
||||
? require('../../config/admin/oauth')
|
||||
: false,
|
||||
|
||||
// shorthand
|
||||
version = project.version
|
||||
;
|
||||
|
||||
module.exports = function(callback) {
|
||||
|
||||
var
|
||||
index = -1,
|
||||
total = release.components.length,
|
||||
timer,
|
||||
stream,
|
||||
stepRepo
|
||||
;
|
||||
|
||||
if(!oAuth) {
|
||||
console.error('Must add oauth token for GitHub in tasks/config/admin/oauth.js');
|
||||
return;
|
||||
}
|
||||
|
||||
// Do Git commands synchronously per component, to avoid issues
|
||||
stepRepo = function() {
|
||||
|
||||
index = index + 1;
|
||||
|
||||
if(index >= total) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var
|
||||
component = release.components[index]
|
||||
outputDirectory = path.resolve(release.outputRoot + component),
|
||||
capitalizedComponent = component.charAt(0).toUpperCase() + component.slice(1),
|
||||
repoName = release.componentRepoRoot + capitalizedComponent,
|
||||
|
||||
gitOptions = { cwd: outputDirectory },
|
||||
pullOptions = { args: '-q', cwd: outputDirectory, quiet: true },
|
||||
resetOptions = { args: '-q --hard', cwd: outputDirectory, quiet: true },
|
||||
|
||||
gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
|
||||
repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
|
||||
localRepoSetup = fs.existsSync(path.join(outputDirectory, '.git'))
|
||||
;
|
||||
|
||||
console.log('Processing repository: ' + outputDirectory);
|
||||
|
||||
// create folder if doesn't exist
|
||||
if( !fs.existsSync(outputDirectory) ) {
|
||||
mkdirp.sync(outputDirectory);
|
||||
}
|
||||
|
||||
// clean folder
|
||||
if(release.outputRoot.search('../repos') == 0) {
|
||||
console.info('Cleaning dir', outputDirectory);
|
||||
del.sync([outputDirectory + '**/*'], {silent: true, force: true});
|
||||
}
|
||||
|
||||
// set-up local repo
|
||||
function setupRepo() {
|
||||
if(localRepoSetup) {
|
||||
addRemote();
|
||||
}
|
||||
else {
|
||||
initRepo();
|
||||
}
|
||||
}
|
||||
|
||||
function initRepo() {
|
||||
console.info('Initializing repository for ' + component);
|
||||
git.init(gitOptions, function(error) {
|
||||
if(error) {
|
||||
console.error('Error initializing repo', error);
|
||||
}
|
||||
addRemote();
|
||||
});
|
||||
}
|
||||
|
||||
function createRepo() {
|
||||
console.info('Creating GitHub repo ' + repoURL);
|
||||
github.repos.createFromOrg({
|
||||
org : release.org,
|
||||
name : repoName,
|
||||
homepage : release.homepage
|
||||
}, function() {
|
||||
setupRepo();
|
||||
});
|
||||
}
|
||||
|
||||
function addRemote() {
|
||||
console.info('Adding remote origin as ' + gitURL);
|
||||
git.addRemote('origin', gitURL, gitOptions, function(){
|
||||
pullFiles();
|
||||
});
|
||||
}
|
||||
|
||||
function pullFiles() {
|
||||
console.info('Pulling ' + component + ' files');
|
||||
git.pull('origin', 'master', pullOptions, function(error) {
|
||||
resetFiles();
|
||||
});
|
||||
}
|
||||
|
||||
function resetFiles() {
|
||||
console.info('Resetting files to head');
|
||||
git.reset('HEAD', resetOptions, function(error) {
|
||||
nextRepo();
|
||||
});
|
||||
}
|
||||
|
||||
function nextRepo() {
|
||||
//console.log('Sleeping for 1 second...');
|
||||
// avoid rate throttling
|
||||
global.clearTimeout(timer);
|
||||
timer = global.setTimeout(function() {
|
||||
stepRepo()
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
||||
if(localRepoSetup) {
|
||||
pullFiles();
|
||||
}
|
||||
else {
|
||||
setupRepo();
|
||||
// createRepo() only use to create remote repo (easier to do manually)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
stepRepo();
|
||||
|
||||
|
||||
};
|
184
web/semantic/tasks/admin/components/update.js
Normal file
184
web/semantic/tasks/admin/components/update.js
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*******************************
|
||||
Update Repos
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
|
||||
This task update all SUI individual component repos with new versions of components
|
||||
|
||||
* Commits changes from create repo
|
||||
* Pushes changes to GitHub
|
||||
* Tag new releases if version changed in main repo
|
||||
|
||||
*/
|
||||
|
||||
var
|
||||
gulp = require('gulp'),
|
||||
|
||||
// node dependencies
|
||||
console = require('better-console'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
git = require('gulp-git'),
|
||||
githubAPI = require('github'),
|
||||
requireDotFile = require('require-dot-file'),
|
||||
|
||||
// admin files
|
||||
github = require('../../config/admin/github.js'),
|
||||
release = require('../../config/admin/release'),
|
||||
project = require('../../config/project/release'),
|
||||
|
||||
|
||||
// oAuth configuration for GitHub
|
||||
oAuth = fs.existsSync(__dirname + '/../../config/admin/oauth.js')
|
||||
? require('../../config/admin/oauth')
|
||||
: false,
|
||||
|
||||
// shorthand
|
||||
version = project.version
|
||||
;
|
||||
|
||||
module.exports = function(callback) {
|
||||
|
||||
var
|
||||
index = -1,
|
||||
total = release.components.length,
|
||||
timer,
|
||||
stream,
|
||||
stepRepo
|
||||
;
|
||||
|
||||
if(!oAuth) {
|
||||
console.error('Must add oauth token for GitHub in tasks/config/admin/oauth.js');
|
||||
return;
|
||||
}
|
||||
|
||||
// Do Git commands synchronously per component, to avoid issues
|
||||
stepRepo = function() {
|
||||
|
||||
index = index + 1;
|
||||
if(index >= total) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var
|
||||
component = release.components[index],
|
||||
outputDirectory = path.resolve(path.join(release.outputRoot, component)),
|
||||
capitalizedComponent = component.charAt(0).toUpperCase() + component.slice(1),
|
||||
repoName = release.componentRepoRoot + capitalizedComponent,
|
||||
|
||||
gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
|
||||
repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
|
||||
|
||||
commitArgs = (oAuth.name !== undefined && oAuth.email !== undefined)
|
||||
? '--author "' + oAuth.name + ' <' + oAuth.email + '>"'
|
||||
: '',
|
||||
|
||||
componentPackage = fs.existsSync(outputDirectory + 'package.json' )
|
||||
? require(outputDirectory + 'package.json')
|
||||
: false,
|
||||
|
||||
isNewVersion = (version && componentPackage.version != version),
|
||||
|
||||
commitMessage = (isNewVersion)
|
||||
? 'Updated component to version ' + version
|
||||
: 'Updated files from main repo',
|
||||
|
||||
gitOptions = { cwd: outputDirectory },
|
||||
commitOptions = { args: commitArgs, cwd: outputDirectory },
|
||||
releaseOptions = { tag_name: version, owner: release.org, repo: repoName },
|
||||
|
||||
fileModeOptions = { args : 'config core.fileMode false', cwd: outputDirectory },
|
||||
usernameOptions = { args : 'config user.name "' + oAuth.name + '"', cwd: outputDirectory },
|
||||
emailOptions = { args : 'config user.email "' + oAuth.email + '"', cwd: outputDirectory },
|
||||
versionOptions = { args : 'rev-parse --verify HEAD', cwd: outputDirectory },
|
||||
|
||||
localRepoSetup = fs.existsSync(path.join(outputDirectory, '.git')),
|
||||
canProceed = true
|
||||
;
|
||||
|
||||
|
||||
console.info('Processing repository:' + outputDirectory);
|
||||
|
||||
function setConfig() {
|
||||
git.exec(fileModeOptions, function() {
|
||||
git.exec(usernameOptions, function () {
|
||||
git.exec(emailOptions, function () {
|
||||
commitFiles();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// standard path
|
||||
function commitFiles() {
|
||||
// commit files
|
||||
console.info('Committing ' + component + ' files', commitArgs);
|
||||
gulp.src('**/*', gitOptions)
|
||||
.pipe(git.add(gitOptions))
|
||||
.pipe(git.commit(commitMessage, commitOptions))
|
||||
.on('error', function(error) {
|
||||
// canProceed = false; bug in git commit <https://github.com/stevelacy/gulp-git/issues/49>
|
||||
})
|
||||
.on('finish', function(callback) {
|
||||
if(canProceed) {
|
||||
pushFiles();
|
||||
}
|
||||
else {
|
||||
console.info('Nothing new to commit');
|
||||
nextRepo();
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
// push changes to remote
|
||||
function pushFiles() {
|
||||
console.info('Pushing files for ' + component);
|
||||
git.push('origin', 'master', { args: '', cwd: outputDirectory }, function(error) {
|
||||
console.info('Push completed successfully');
|
||||
getSHA();
|
||||
});
|
||||
}
|
||||
|
||||
// gets SHA of last commit
|
||||
function getSHA() {
|
||||
git.exec(versionOptions, function(error, version) {
|
||||
version = version.trim();
|
||||
createRelease(version);
|
||||
});
|
||||
}
|
||||
|
||||
// create release on GitHub.com
|
||||
function createRelease(version) {
|
||||
if(version) {
|
||||
releaseOptions.target_commitish = version;
|
||||
}
|
||||
github.releases.createRelease(releaseOptions, function() {
|
||||
nextRepo();
|
||||
});
|
||||
}
|
||||
|
||||
// Steps to next repository
|
||||
function nextRepo() {
|
||||
console.log('Sleeping for 1 second...');
|
||||
// avoid rate throttling
|
||||
global.clearTimeout(timer);
|
||||
timer = global.setTimeout(stepRepo, 1000);
|
||||
}
|
||||
|
||||
|
||||
if(localRepoSetup) {
|
||||
setConfig();
|
||||
}
|
||||
else {
|
||||
console.error('Repository must be setup before running update components');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
stepRepo();
|
||||
|
||||
};
|
216
web/semantic/tasks/admin/distributions/create.js
Normal file
216
web/semantic/tasks/admin/distributions/create.js
Normal file
|
@ -0,0 +1,216 @@
|
|||
/*******************************
|
||||
Create Distributions
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
This will create individual distribution repositories for each SUI distribution
|
||||
|
||||
* copy distribution files to release
|
||||
* update package.json file
|
||||
*/
|
||||
|
||||
var
|
||||
gulp = require('gulp'),
|
||||
|
||||
// node dependencies
|
||||
console = require('better-console'),
|
||||
del = require('del'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
runSequence = require('run-sequence'),
|
||||
mergeStream = require('merge-stream'),
|
||||
|
||||
// admin dependencies
|
||||
concatFileNames = require('gulp-concat-filenames'),
|
||||
debug = require('gulp-debug'),
|
||||
flatten = require('gulp-flatten'),
|
||||
git = require('gulp-git'),
|
||||
jsonEditor = require('gulp-json-editor'),
|
||||
plumber = require('gulp-plumber'),
|
||||
rename = require('gulp-rename'),
|
||||
replace = require('gulp-replace'),
|
||||
tap = require('gulp-tap'),
|
||||
|
||||
// config
|
||||
config = require('../../config/user'),
|
||||
release = require('../../config/admin/release'),
|
||||
project = require('../../config/project/release'),
|
||||
|
||||
// shorthand
|
||||
version = project.version,
|
||||
output = config.paths.output
|
||||
|
||||
;
|
||||
|
||||
|
||||
module.exports = function(callback) {
|
||||
var
|
||||
stream,
|
||||
index,
|
||||
tasks = []
|
||||
;
|
||||
|
||||
for(index in release.distributions) {
|
||||
|
||||
var
|
||||
distribution = release.distributions[index]
|
||||
;
|
||||
|
||||
// streams... designed to save time and make coding fun...
|
||||
(function(distribution) {
|
||||
|
||||
var
|
||||
distLowerCase = distribution.toLowerCase(),
|
||||
outputDirectory = path.join(release.outputRoot, distLowerCase),
|
||||
packageFile = path.join(outputDirectory, release.files.npm),
|
||||
repoName = release.distRepoRoot + distribution,
|
||||
regExp = {
|
||||
match : {
|
||||
files : '{files}',
|
||||
version : '{version}'
|
||||
}
|
||||
},
|
||||
task = {
|
||||
all : distribution + ' copying files',
|
||||
repo : distribution + ' create repo',
|
||||
meteor : distribution + ' create meteor package.js',
|
||||
package : distribution + ' create package.json'
|
||||
},
|
||||
gatherFiles,
|
||||
createList
|
||||
;
|
||||
|
||||
// get files for meteor
|
||||
gatherFiles = function(dir) {
|
||||
var
|
||||
dir = dir || path.resolve('.'),
|
||||
list = fs.readdirSync(dir),
|
||||
omitted = [
|
||||
'.git',
|
||||
'node_modules',
|
||||
'package.js',
|
||||
'LICENSE',
|
||||
'README.md',
|
||||
'package.json',
|
||||
'bower.json',
|
||||
'.gitignore'
|
||||
]
|
||||
files = []
|
||||
;
|
||||
list.forEach(function(file) {
|
||||
var
|
||||
isOmitted = (omitted.indexOf(file) > -1),
|
||||
filePath = path.join(dir, file),
|
||||
stat = fs.statSync(filePath)
|
||||
;
|
||||
if(!isOmitted) {
|
||||
if(stat && stat.isDirectory()) {
|
||||
files = files.concat(gatherFiles(filePath));
|
||||
}
|
||||
else {
|
||||
files.push(filePath.replace(outputDirectory + path.sep, ''));
|
||||
}
|
||||
}
|
||||
})
|
||||
return files
|
||||
};
|
||||
|
||||
// spaces out list correctly
|
||||
createList = function(files) {
|
||||
var filenames = '';
|
||||
for(file in files) {
|
||||
if(file == (files.length - 1) ) {
|
||||
filenames += "'" + files[file] + "'";
|
||||
}
|
||||
else {
|
||||
filenames += "'" + files[file] + "',\n ";
|
||||
}
|
||||
}
|
||||
return filenames;
|
||||
};
|
||||
|
||||
|
||||
gulp.task(task.meteor, function() {
|
||||
var
|
||||
files = gatherFiles(outputDirectory)
|
||||
filenames = createList(files)
|
||||
;
|
||||
gulp.src(release.templates.meteor[distLowerCase])
|
||||
.pipe(plumber())
|
||||
.pipe(flatten())
|
||||
.pipe(replace(regExp.match.version, version))
|
||||
.pipe(replace(regExp.match.files, filenames))
|
||||
.pipe(rename(release.files.meteor))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
if(distribution == 'CSS') {
|
||||
gulp.task(task.repo, function() {
|
||||
var
|
||||
themes,
|
||||
component,
|
||||
releases
|
||||
;
|
||||
themes = gulp.src('dist/themes/default/**/*', { base: 'dist/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
components = gulp.src('dist/components/*', { base: 'dist/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
releases = gulp.src('dist/*', { base: 'dist/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
return mergeStream(themes, components, releases);
|
||||
});
|
||||
}
|
||||
else if(distribution == 'LESS') {
|
||||
gulp.task(task.repo, function() {
|
||||
var
|
||||
definitions,
|
||||
themeImport,
|
||||
themeConfig,
|
||||
siteTheme,
|
||||
themes
|
||||
;
|
||||
definitions = gulp.src('src/definitions/**/*', { base: 'src/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
themeImport = gulp.src('src/theme.less', { base: 'src/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
themeConfig = gulp.src('src/theme.config.example', { base: 'src/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
siteTheme = gulp.src('src/_site/**/*', { base: 'src/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
themes = gulp.src('src/themes/**/*', { base: 'src/' })
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
return mergeStream(definitions, themeImport, themeConfig, siteTheme, themes);
|
||||
});
|
||||
}
|
||||
|
||||
// extend package.json
|
||||
gulp.task(task.package, function() {
|
||||
return gulp.src(packageFile)
|
||||
.pipe(plumber())
|
||||
.pipe(jsonEditor(function(package) {
|
||||
if(version) {
|
||||
package.version = version;
|
||||
}
|
||||
return package;
|
||||
}))
|
||||
.pipe(gulp.dest(outputDirectory))
|
||||
;
|
||||
});
|
||||
|
||||
tasks.push(task.meteor);
|
||||
tasks.push(task.repo);
|
||||
tasks.push(task.package);
|
||||
|
||||
})(distribution);
|
||||
}
|
||||
runSequence(tasks, callback);
|
||||
};
|
170
web/semantic/tasks/admin/distributions/init.js
Normal file
170
web/semantic/tasks/admin/distributions/init.js
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*******************************
|
||||
Init Dist Repos
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
|
||||
This task pulls the latest version of distribution from GitHub
|
||||
|
||||
* Creates new repo if doesnt exist (locally & GitHub)
|
||||
* Adds remote it doesnt exists
|
||||
* Pulls latest changes from repo
|
||||
|
||||
*/
|
||||
|
||||
var
|
||||
gulp = require('gulp'),
|
||||
|
||||
// node dependencies
|
||||
console = require('better-console'),
|
||||
del = require('del'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
git = require('gulp-git'),
|
||||
githubAPI = require('github'),
|
||||
mkdirp = require('mkdirp'),
|
||||
|
||||
// admin files
|
||||
github = require('../../config/admin/github.js'),
|
||||
release = require('../../config/admin/release'),
|
||||
project = require('../../config/project/release'),
|
||||
|
||||
|
||||
// oAuth configuration for GitHub
|
||||
oAuth = fs.existsSync(__dirname + '/../../config/admin/oauth.js')
|
||||
? require('../../config/admin/oauth')
|
||||
: false,
|
||||
|
||||
// shorthand
|
||||
version = project.version
|
||||
;
|
||||
|
||||
module.exports = function(callback) {
|
||||
|
||||
var
|
||||
index = -1,
|
||||
total = release.distributions.length,
|
||||
timer,
|
||||
stream,
|
||||
stepRepo
|
||||
;
|
||||
|
||||
if(!oAuth) {
|
||||
console.error('Must add oauth token for GitHub in tasks/config/admin/oauth.js');
|
||||
return;
|
||||
}
|
||||
|
||||
// Do Git commands synchronously per component, to avoid issues
|
||||
stepRepo = function() {
|
||||
|
||||
index = index + 1;
|
||||
|
||||
if(index >= total) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var
|
||||
component = release.distributions[index],
|
||||
lowerCaseComponent = component.toLowerCase(),
|
||||
outputDirectory = path.resolve(release.outputRoot + lowerCaseComponent),
|
||||
repoName = release.distRepoRoot + component,
|
||||
|
||||
gitOptions = { cwd: outputDirectory },
|
||||
pullOptions = { args: '-q', cwd: outputDirectory, quiet: true },
|
||||
resetOptions = { args: '-q --hard', cwd: outputDirectory, quiet: true },
|
||||
|
||||
gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
|
||||
repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
|
||||
localRepoSetup = fs.existsSync(path.join(outputDirectory, '.git'))
|
||||
;
|
||||
|
||||
console.log('Processing repository: ' + outputDirectory);
|
||||
|
||||
// create folder if doesn't exist
|
||||
if( !fs.existsSync(outputDirectory) ) {
|
||||
mkdirp.sync(outputDirectory);
|
||||
}
|
||||
|
||||
// clean folder
|
||||
if(release.outputRoot.search('../repos') == 0) {
|
||||
console.info('Cleaning dir', outputDirectory);
|
||||
del.sync([outputDirectory + '**/*'], {silent: true, force: true});
|
||||
}
|
||||
|
||||
// set-up local repo
|
||||
function setupRepo() {
|
||||
if(localRepoSetup) {
|
||||
addRemote();
|
||||
}
|
||||
else {
|
||||
initRepo();
|
||||
}
|
||||
}
|
||||
|
||||
function initRepo() {
|
||||
console.info('Initializing repository for ' + component);
|
||||
git.init(gitOptions, function(error) {
|
||||
if(error) {
|
||||
console.error('Error initializing repo', error);
|
||||
}
|
||||
addRemote();
|
||||
});
|
||||
}
|
||||
|
||||
function createRepo() {
|
||||
console.info('Creating GitHub repo ' + repoURL);
|
||||
github.repos.createFromOrg({
|
||||
org : release.org,
|
||||
name : repoName,
|
||||
homepage : release.homepage
|
||||
}, function() {
|
||||
setupRepo();
|
||||
});
|
||||
}
|
||||
|
||||
function addRemote() {
|
||||
console.info('Adding remote origin as ' + gitURL);
|
||||
git.addRemote('origin', gitURL, gitOptions, function(){
|
||||
pullFiles();
|
||||
});
|
||||
}
|
||||
|
||||
function pullFiles() {
|
||||
console.info('Pulling ' + component + ' files');
|
||||
git.pull('origin', 'master', pullOptions, function(error) {
|
||||
resetFiles();
|
||||
});
|
||||
}
|
||||
|
||||
function resetFiles() {
|
||||
console.info('Resetting files to head');
|
||||
git.reset('HEAD', resetOptions, function(error) {
|
||||
nextRepo();
|
||||
});
|
||||
}
|
||||
|
||||
function nextRepo() {
|
||||
//console.log('Sleeping for 1 second...');
|
||||
// avoid rate throttling
|
||||
global.clearTimeout(timer);
|
||||
timer = global.setTimeout(function() {
|
||||
stepRepo()
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
||||
if(localRepoSetup) {
|
||||
pullFiles();
|
||||
}
|
||||
else {
|
||||
setupRepo();
|
||||
// createRepo() only use to create remote repo (easier to do manually)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
stepRepo();
|
||||
|
||||
|
||||
};
|
182
web/semantic/tasks/admin/distributions/update.js
Normal file
182
web/semantic/tasks/admin/distributions/update.js
Normal file
|
@ -0,0 +1,182 @@
|
|||
/*******************************
|
||||
Update Repos
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
|
||||
This task update all SUI individual distribution repos with new versions of distributions
|
||||
|
||||
* Commits changes from create repo
|
||||
* Pushes changes to GitHub
|
||||
* Tag new releases if version changed in main repo
|
||||
|
||||
*/
|
||||
|
||||
var
|
||||
gulp = require('gulp'),
|
||||
|
||||
// node dependencies
|
||||
console = require('better-console'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
git = require('gulp-git'),
|
||||
githubAPI = require('github'),
|
||||
requireDotFile = require('require-dot-file'),
|
||||
|
||||
// admin files
|
||||
github = require('../../config/admin/github.js'),
|
||||
release = require('../../config/admin/release'),
|
||||
project = require('../../config/project/release'),
|
||||
|
||||
|
||||
// oAuth configuration for GitHub
|
||||
oAuth = fs.existsSync(__dirname + '/../../config/admin/oauth.js')
|
||||
? require('../../config/admin/oauth')
|
||||
: false,
|
||||
|
||||
// shorthand
|
||||
version = project.version
|
||||
;
|
||||
|
||||
module.exports = function(callback) {
|
||||
|
||||
var
|
||||
index = -1,
|
||||
total = release.distributions.length,
|
||||
timer,
|
||||
stream,
|
||||
stepRepo
|
||||
;
|
||||
|
||||
if(!oAuth) {
|
||||
console.error('Must add oauth token for GitHub in tasks/config/admin/oauth.js');
|
||||
return;
|
||||
}
|
||||
|
||||
// Do Git commands synchronously per distribution, to avoid issues
|
||||
stepRepo = function() {
|
||||
|
||||
index = index + 1;
|
||||
if(index >= total) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var
|
||||
distribution = release.distributions[index],
|
||||
outputDirectory = path.resolve(path.join(release.outputRoot, distribution.toLowerCase() )),
|
||||
repoName = release.distRepoRoot + distribution,
|
||||
|
||||
gitURL = 'https://github.com/' + release.org + '/' + repoName + '.git',
|
||||
repoURL = 'https://github.com/' + release.org + '/' + repoName + '/',
|
||||
|
||||
commitArgs = (oAuth.name !== undefined && oAuth.email !== undefined)
|
||||
? '--author "' + oAuth.name + ' <' + oAuth.email + '>"'
|
||||
: '',
|
||||
|
||||
distributionPackage = fs.existsSync(outputDirectory + 'package.json' )
|
||||
? require(outputDirectory + 'package.json')
|
||||
: false,
|
||||
|
||||
isNewVersion = (version && distributionPackage.version != version),
|
||||
|
||||
commitMessage = (isNewVersion)
|
||||
? 'Updated distribution to version ' + version
|
||||
: 'Updated files from main repo',
|
||||
|
||||
gitOptions = { cwd: outputDirectory },
|
||||
commitOptions = { args: commitArgs, cwd: outputDirectory },
|
||||
releaseOptions = { tag_name: version, owner: release.org, repo: repoName },
|
||||
|
||||
fileModeOptions = { args : 'config core.fileMode false', cwd: outputDirectory },
|
||||
usernameOptions = { args : 'config user.name "' + oAuth.name + '"', cwd: outputDirectory },
|
||||
emailOptions = { args : 'config user.email "' + oAuth.email + '"', cwd: outputDirectory },
|
||||
versionOptions = { args : 'rev-parse --verify HEAD', cwd: outputDirectory },
|
||||
|
||||
localRepoSetup = fs.existsSync(path.join(outputDirectory, '.git')),
|
||||
canProceed = true
|
||||
;
|
||||
|
||||
|
||||
console.info('Processing repository:' + outputDirectory);
|
||||
|
||||
function setConfig() {
|
||||
git.exec(fileModeOptions, function() {
|
||||
git.exec(usernameOptions, function () {
|
||||
git.exec(emailOptions, function () {
|
||||
commitFiles();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// standard path
|
||||
function commitFiles() {
|
||||
// commit files
|
||||
console.info('Committing ' + distribution + ' files', commitArgs);
|
||||
gulp.src('**/*', gitOptions)
|
||||
.pipe(git.add(gitOptions))
|
||||
.pipe(git.commit(commitMessage, commitOptions))
|
||||
.on('error', function(error) {
|
||||
// canProceed = false; bug in git commit <https://github.com/stevelacy/gulp-git/issues/49>
|
||||
})
|
||||
.on('finish', function(callback) {
|
||||
if(canProceed) {
|
||||
pushFiles();
|
||||
}
|
||||
else {
|
||||
console.info('Nothing new to commit');
|
||||
nextRepo();
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
// push changes to remote
|
||||
function pushFiles() {
|
||||
console.info('Pushing files for ' + distribution);
|
||||
git.push('origin', 'master', { args: '', cwd: outputDirectory }, function(error) {
|
||||
console.info('Push completed successfully');
|
||||
getSHA();
|
||||
});
|
||||
}
|
||||
|
||||
// gets SHA of last commit
|
||||
function getSHA() {
|
||||
git.exec(versionOptions, function(error, version) {
|
||||
version = version.trim();
|
||||
createRelease(version);
|
||||
});
|
||||
}
|
||||
|
||||
// create release on GitHub.com
|
||||
function createRelease(version) {
|
||||
if(version) {
|
||||
releaseOptions.target_commitish = version;
|
||||
}
|
||||
github.releases.createRelease(releaseOptions, function() {
|
||||
nextRepo();
|
||||
});
|
||||
}
|
||||
|
||||
// Steps to next repository
|
||||
function nextRepo() {
|
||||
console.log('Sleeping for 1 second...');
|
||||
// avoid rate throttling
|
||||
global.clearTimeout(timer);
|
||||
timer = global.setTimeout(stepRepo, 500);
|
||||
}
|
||||
|
||||
|
||||
if(localRepoSetup) {
|
||||
setConfig();
|
||||
}
|
||||
else {
|
||||
console.error('Repository must be setup before running update distributions');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
stepRepo();
|
||||
|
||||
};
|
25
web/semantic/tasks/admin/publish.js
Normal file
25
web/semantic/tasks/admin/publish.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*******************************
|
||||
Release All
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
This task update all SUI individual component repos with new versions of components
|
||||
|
||||
* Commits changes from create components to GitHub and Tags
|
||||
|
||||
*/
|
||||
|
||||
var
|
||||
runSequence = require('run-sequence')
|
||||
;
|
||||
|
||||
/* Release All */
|
||||
module.exports = function(callback) {
|
||||
|
||||
runSequence(
|
||||
'update distributions', // commit less/css versions to github
|
||||
'update components', // commit components to github
|
||||
callback
|
||||
);
|
||||
|
||||
};
|
55
web/semantic/tasks/admin/register.js
Normal file
55
web/semantic/tasks/admin/register.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*******************************
|
||||
Register PM
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
Task to register component repos with Package Managers
|
||||
* Registers component with bower
|
||||
* Registers component with NPM
|
||||
*/
|
||||
|
||||
var
|
||||
// node dependencies
|
||||
process = require('child_process'),
|
||||
|
||||
// config
|
||||
release = require('../config/admin/release'),
|
||||
|
||||
// register components and distributions
|
||||
repos = release.distributions.concat(release.components),
|
||||
total = repos.length,
|
||||
index = -1,
|
||||
|
||||
stream,
|
||||
stepRepo
|
||||
;
|
||||
|
||||
module.exports = function(callback) {
|
||||
|
||||
console.log('Registering repos with package managers');
|
||||
|
||||
// Do Git commands synchronously per component, to avoid issues
|
||||
stepRepo = function() {
|
||||
index = index + 1;
|
||||
if(index >= total) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
var
|
||||
repo = repos[index].toLowerCase(),
|
||||
outputDirectory = release.outputRoot + repo + '/',
|
||||
exec = process.exec,
|
||||
execSettings = {cwd: outputDirectory},
|
||||
updateNPM = 'npm publish'
|
||||
;
|
||||
|
||||
/* Register with NPM */
|
||||
exec(updateNPM, execSettings, function(err, stdout, stderr) {
|
||||
console.log(err, stdout, stderr);
|
||||
stepRepo();
|
||||
});
|
||||
|
||||
};
|
||||
stepRepo();
|
||||
};
|
||||
|
29
web/semantic/tasks/admin/release.js
Normal file
29
web/semantic/tasks/admin/release.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*******************************
|
||||
Release
|
||||
*******************************/
|
||||
|
||||
/*
|
||||
This task update all SUI individual component repos with new versions of components
|
||||
|
||||
* Initializes repositories with current versions
|
||||
* Creates local files at ../distributions/ with each repo for release
|
||||
|
||||
*/
|
||||
|
||||
var
|
||||
runSequence = require('run-sequence')
|
||||
;
|
||||
|
||||
/* Release All */
|
||||
module.exports = function(callback) {
|
||||
|
||||
runSequence(
|
||||
//'build', // build Semantic
|
||||
'init distributions', // sync with current github version
|
||||
'create distributions', // update each repo with changes from master repo
|
||||
'init components', // sync with current github version
|
||||
'create components', // update each repo
|
||||
callback
|
||||
);
|
||||
|
||||
};
|
Reference in a new issue