init
This commit is contained in:
58
public/tinymce/tools/tasks/bundle.js
Normal file
58
public/tinymce/tools/tasks/bundle.js
Normal file
@@ -0,0 +1,58 @@
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerMultiTask("bundle", "Bundles code, themes and bundles to a single file.", function () {
|
||||
var options, contents, themes, plugins;
|
||||
|
||||
function appendFile(src) {
|
||||
src = src.replace(/\\/g, '/');
|
||||
|
||||
if (fs.existsSync(src)) {
|
||||
grunt.log.writeln("Appending file:", src);
|
||||
contents += grunt.file.read(src);
|
||||
} else {
|
||||
grunt.fail.fatal("Could not find file: " + src);
|
||||
}
|
||||
}
|
||||
|
||||
function append(dirPath, fileName, value) {
|
||||
if (value) {
|
||||
value.split(/,/).forEach(function (src) {
|
||||
appendFile(path.join(dirPath, src, fileName));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
options = grunt.config([this.name, this.target]).options;
|
||||
options.themesDir = options.themesDir || "plugins";
|
||||
options.themeFileName = options.themeFileName || "theme.min.js";
|
||||
options.pluginsDir = options.pluginsDir || "plugins";
|
||||
options.pluginFileName = options.pluginFileName || "plugin.min.js";
|
||||
options.outputPath = options.outputPath || "full.min.js";
|
||||
|
||||
themes = grunt.option("themes");
|
||||
plugins = grunt.option("plugins");
|
||||
|
||||
if (!themes && !plugins) {
|
||||
grunt.log.writeln("Use: grunt bundle --themes <comma separated list of themes> --plugins <comma separated list of plugins>");
|
||||
process.exit(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
contents = "";
|
||||
this.files.forEach(function (filePair) {
|
||||
filePair.src.forEach(function (src) {
|
||||
appendFile(src);
|
||||
});
|
||||
});
|
||||
|
||||
append(options.themesDir, options.themeFileName, themes);
|
||||
append(options.pluginsDir, options.pluginFileName, plugins);
|
||||
|
||||
if (contents.length > 0) {
|
||||
grunt.file.write(options.outputPath, contents);
|
||||
grunt.log.ok("Created bundle js:", options.outputPath);
|
||||
}
|
||||
});
|
||||
};
|
||||
98
public/tinymce/tools/tasks/globals.js
Normal file
98
public/tinymce/tools/tasks/globals.js
Normal file
@@ -0,0 +1,98 @@
|
||||
var child_process = require('child_process');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var readFile = function (filePath) {
|
||||
return fs.readFileSync(filePath, 'utf8').toString();
|
||||
};
|
||||
|
||||
var writeFile = function (filePath, content) {
|
||||
fs.writeFileSync(filePath, content);
|
||||
};
|
||||
|
||||
var parseConfig = function (filePath) {
|
||||
var data = JSON.parse(readFile(filePath));
|
||||
return data;
|
||||
};
|
||||
|
||||
var mkdirp = function (grunt, dirPath) {
|
||||
grunt.file.mkdir(dirPath);
|
||||
};
|
||||
|
||||
var fail = function (msg) {
|
||||
throw new Error(msg);
|
||||
};
|
||||
|
||||
var required = function (config, propName) {
|
||||
var failMsg = 'Required property \'' + propName + '\' not defined in:\n' + JSON.stringify(config, null, ' ');
|
||||
return propName in config ? config[propName] : fail(failMsg);
|
||||
};
|
||||
|
||||
var createTargetInfo = function (filePath, targetId, globalId) {
|
||||
return {
|
||||
filePath: filePath,
|
||||
targetId: targetId,
|
||||
globalId: globalId,
|
||||
globalName: globalId.split('.').pop()
|
||||
};
|
||||
};
|
||||
|
||||
var targetIdToTargetInfo = function (outputPath, replacer) {
|
||||
return function (targetId) {
|
||||
var filePath = path.join(outputPath, targetId.replace(/\./g, '\/'));
|
||||
var globalId = replacer(targetId);
|
||||
return createTargetInfo(filePath, targetId, globalId);
|
||||
};
|
||||
};
|
||||
|
||||
var replaceVariables = function (str, variables) {
|
||||
Object.keys(variables).forEach(function (variable) {
|
||||
str = str.replace(new RegExp('\\{\\$' + variable + '\\}', 'g'), variables[variable]);
|
||||
});
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
var generateGlobaliserModule = function (templateFile, targetInfo) {
|
||||
var template = readFile(templateFile);
|
||||
writeFile(targetInfo.filePath + '.js', replaceVariables(template, targetInfo));
|
||||
};
|
||||
|
||||
var replacePrefixes = function (id, search, replace) {
|
||||
return search.reduce(function (id, item) {
|
||||
return id.replace(item, replace);
|
||||
}, id);
|
||||
};
|
||||
|
||||
var replacePrefix = function (grunt, templateFile, outputPath, config) {
|
||||
var search = required(config, 'search');
|
||||
var replace = required(config, 'replace');
|
||||
var targets = required(config, 'targets');
|
||||
|
||||
targets
|
||||
.map(targetIdToTargetInfo(outputPath, id => replacePrefixes(id, search, replace)))
|
||||
.forEach(function (targetInfo) {
|
||||
mkdirp(grunt, path.dirname(targetInfo.filePath));
|
||||
generateGlobaliserModule(templateFile, targetInfo);
|
||||
});
|
||||
};
|
||||
|
||||
var executeAction = function (grunt, action, templateFile, outputPath, config) {
|
||||
if (action === 'replace.prefix') {
|
||||
replacePrefix(grunt, templateFile, outputPath, config);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('globals', 'Generates a globals layer', function () {
|
||||
var options = grunt.config([this.name]).options;
|
||||
var templateFile = required(options, 'templateFile');
|
||||
var outputDir = required(options, 'outputDir');
|
||||
var configJson = required(options, 'configFile');
|
||||
var config = parseConfig(configJson);
|
||||
|
||||
Object.keys(config).forEach(function (action) {
|
||||
executeAction(grunt, action, templateFile, outputDir, config[action]);
|
||||
});
|
||||
});
|
||||
};
|
||||
95
public/tinymce/tools/tasks/moxiezip.js
Normal file
95
public/tinymce/tools/tasks/moxiezip.js
Normal file
@@ -0,0 +1,95 @@
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var ZipWriter = require('moxie-zip').ZipWriter;
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerMultiTask("moxiezip", "Creates zip files.", function () {
|
||||
var target = grunt.config([this.name, this.target]);
|
||||
var archive = new ZipWriter();
|
||||
var done = this.async();
|
||||
var options = target.options || {}, excludePaths = {};
|
||||
|
||||
options.baseDir = (options.baseDir || '').replace(/\\/g, '/');
|
||||
|
||||
function addExcludes(excludes) {
|
||||
if (Array.isArray(excludes)) {
|
||||
excludes.forEach(function (excludePath) {
|
||||
excludePaths[path.resolve(excludePath)] = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function filterZipPath(zipFilePath) {
|
||||
if (options.pathFilter) {
|
||||
return options.pathFilter(zipFilePath);
|
||||
}
|
||||
|
||||
return zipFilePath;
|
||||
}
|
||||
|
||||
function process(filePath, zipFilePath) {
|
||||
var args, stat = fs.statSync(filePath);
|
||||
|
||||
if (excludePaths[path.resolve(filePath)]) {
|
||||
return;
|
||||
}
|
||||
|
||||
zipFilePath = zipFilePath || filePath;
|
||||
filePath = filePath.replace(/\\/g, '/');
|
||||
zipFilePath = zipFilePath.replace(/\\/g, '/');
|
||||
zipFilePath = filterZipPath(zipFilePath);
|
||||
|
||||
if (stat.isFile()) {
|
||||
var data = fs.readFileSync(filePath);
|
||||
|
||||
if (options.dataFilter) {
|
||||
args = { filePath: filePath, zipFilePath: zipFilePath, data: data };
|
||||
options.dataFilter(args);
|
||||
data = args.data;
|
||||
}
|
||||
|
||||
archive.addData(path.join(options.baseDir, zipFilePath), data);
|
||||
} else if (stat.isDirectory()) {
|
||||
fs.readdirSync(filePath).forEach(function (fileName) {
|
||||
process(path.join(filePath, fileName), path.join(zipFilePath, fileName));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (options.concat) {
|
||||
options.concat.forEach(function (pair) {
|
||||
var chunks;
|
||||
|
||||
chunks = grunt.file.expand(pair.src).map(function (src) {
|
||||
return grunt.file.read(src);
|
||||
});
|
||||
|
||||
pair.dest.forEach(function (zipFilePath) {
|
||||
zipFilePath = filterZipPath(zipFilePath);
|
||||
archive.addData(path.join(options.baseDir, zipFilePath), chunks.join('\r\n'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (target.options.excludes) {
|
||||
addExcludes(grunt.file.expand(target.options.excludes));
|
||||
}
|
||||
|
||||
this.files.forEach(function (filePair) {
|
||||
filePair.src.forEach(function (src) {
|
||||
process(src);
|
||||
});
|
||||
});
|
||||
|
||||
if (options.onBeforeSave) {
|
||||
options.onBeforeSave(archive);
|
||||
}
|
||||
|
||||
grunt.file.mkdir(path.dirname(options.to));
|
||||
|
||||
archive.saveAs(options.to, function () {
|
||||
grunt.log.ok('Created zip file:', options.to);
|
||||
done();
|
||||
});
|
||||
});
|
||||
};
|
||||
20
public/tinymce/tools/tasks/validateVersion.js
Normal file
20
public/tinymce/tools/tasks/validateVersion.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/* eslint-env node */
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var package = require(path.join(__dirname, '../../package.json'));
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask("validateVersion", "Check that version number in changelog and package.json match", function () {
|
||||
var changelog = fs.readFileSync(path.join(__dirname, '../../changelog.txt'));
|
||||
var changelogVersion = /Version ([0-9.]+)/.exec(changelog)[1];
|
||||
|
||||
if (package.version !== changelogVersion) {
|
||||
grunt.fail.fatal(
|
||||
'Latest changelog version ' + changelogVersion +
|
||||
' and package.json version ' + package.version +
|
||||
' does not match.'
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user