2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2012-09-09 03:07:49 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2012-09-09 03:07:49 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
2012-09-09 03:07:49 +00:00
|
|
|
|
2012-09-09 02:25:02 +00:00
|
|
|
/**
|
|
|
|
|
* @fileoverview Script used to prepare WebDriverJS as a Node module.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var assert = require('assert'),
|
|
|
|
|
fs = require('fs'),
|
2020-07-12 02:22:07 +05:30
|
|
|
path = require('path');
|
2012-09-09 02:25:02 +00:00
|
|
|
|
|
|
|
|
var optparse = require('./optparse');
|
2016-03-15 14:14:55 -07:00
|
|
|
var gendocs = require('./gendocs');
|
2012-09-09 02:25:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-19 20:10:39 -08:00
|
|
|
* @param {string} srcDir Path to the main source directory.
|
2012-09-09 02:25:02 +00:00
|
|
|
* @param {string} outputDirPath Path to the directory to copy src files to.
|
|
|
|
|
*/
|
2013-02-19 20:10:39 -08:00
|
|
|
function copySrcs(srcDir, outputDirPath) {
|
|
|
|
|
var filePaths = fs.readdirSync(srcDir);
|
2012-09-09 02:25:02 +00:00
|
|
|
filePaths.forEach(function(filePath) {
|
2014-08-20 17:44:23 -07:00
|
|
|
if (filePath === 'node_modules') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-02-19 20:10:39 -08:00
|
|
|
filePath = path.join(srcDir, filePath);
|
|
|
|
|
if (fs.statSync(filePath).isDirectory()) {
|
|
|
|
|
copySrcs(filePath, path.join(outputDirPath, path.basename(filePath)));
|
|
|
|
|
} else {
|
|
|
|
|
var dest = path.join(outputDirPath, path.basename(filePath));
|
|
|
|
|
copyFile(filePath, dest);
|
2012-09-09 02:25:02 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function copyFile(src, dest) {
|
|
|
|
|
createDirectoryIfNecessary(path.dirname(dest));
|
|
|
|
|
|
2013-06-29 22:59:48 -07:00
|
|
|
var buffer = fs.readFileSync(src);
|
|
|
|
|
fs.writeFileSync(dest, buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function copyDirectory(baseDir, dest, exclusions) {
|
|
|
|
|
createDirectoryIfNecessary(dest);
|
|
|
|
|
if (!fs.statSync(dest).isDirectory()) {
|
|
|
|
|
throw Error(dest + ' is not a directory!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs.readdirSync(path.resolve(baseDir)).
|
|
|
|
|
map(function(filePath) {
|
|
|
|
|
return path.join(baseDir, filePath);
|
|
|
|
|
}).
|
|
|
|
|
filter(function(filePath) {
|
|
|
|
|
return !exclusions.some(function(exclusion) {
|
|
|
|
|
return exclusion.test(filePath);
|
|
|
|
|
});
|
|
|
|
|
}).
|
|
|
|
|
forEach(function(srcFile) {
|
|
|
|
|
var destFile = path.join(dest, srcFile.substring(baseDir.length));
|
|
|
|
|
if (fs.statSync(srcFile).isDirectory()) {
|
|
|
|
|
copyDirectory(srcFile, destFile, exclusions);
|
|
|
|
|
} else {
|
|
|
|
|
copyFile(path.resolve(srcFile), destFile);
|
|
|
|
|
}
|
|
|
|
|
});
|
2012-09-09 02:25:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createDirectoryIfNecessary(dirPath) {
|
|
|
|
|
var toCreate = [];
|
|
|
|
|
var current = dirPath;
|
|
|
|
|
while (!fs.existsSync(current)) {
|
|
|
|
|
toCreate.push(path.basename(current));
|
|
|
|
|
current = path.dirname(current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (toCreate.length) {
|
|
|
|
|
current = path.join(current, toCreate.pop());
|
|
|
|
|
fs.mkdirSync(current);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 22:59:48 -07:00
|
|
|
function copyResources(outputDirPath, resources, exclusions) {
|
2012-09-09 02:25:02 +00:00
|
|
|
resources.forEach(function(resource) {
|
|
|
|
|
var parts = resource.split(':', 2);
|
|
|
|
|
var src = path.resolve(parts[0]);
|
|
|
|
|
var dest = outputDirPath;
|
|
|
|
|
|
|
|
|
|
var isAbsolute = path.resolve(parts[1]) === parts[1];
|
|
|
|
|
if (!isAbsolute) {
|
|
|
|
|
dest = path.join(dest, 'lib');
|
|
|
|
|
}
|
|
|
|
|
dest = path.join(dest, parts[1]);
|
2013-06-29 22:59:48 -07:00
|
|
|
|
|
|
|
|
if (fs.statSync(src).isDirectory()) {
|
|
|
|
|
copyDirectory(parts[0], dest, exclusions);
|
|
|
|
|
} else {
|
|
|
|
|
copyFile(src, dest);
|
|
|
|
|
}
|
2012-09-09 02:25:02 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
|
var parser = new optparse.OptionParser().
|
|
|
|
|
path('output', { help: 'Path to the output directory' }).
|
|
|
|
|
path('src', {
|
2013-02-19 20:10:39 -08:00
|
|
|
help: 'Path to the module source directory. The entire contents of ' +
|
|
|
|
|
'this directory will be copied recursively to the main output ' +
|
|
|
|
|
'directory.'
|
2012-09-09 02:25:02 +00:00
|
|
|
}).
|
|
|
|
|
string('resource', {
|
|
|
|
|
help: 'A resource which should be copied into the final module, in ' +
|
2012-09-09 03:07:49 +00:00
|
|
|
'the form of a ":" colon separated pair, the first part ' +
|
|
|
|
|
'designating the source, and the second its destination. If ' +
|
|
|
|
|
'the destination path is absolute, it is relative to the ' +
|
|
|
|
|
'module root, otherwise it will be treated relative to the ' +
|
2013-06-29 22:59:48 -07:00
|
|
|
'lib/ directory. If the source refers to a directory, the ' +
|
|
|
|
|
'recursive contents of that directory will be copied to the ' +
|
|
|
|
|
'destination directory.',
|
|
|
|
|
list: true
|
|
|
|
|
}).
|
|
|
|
|
regex('exclude_resource', {
|
|
|
|
|
help: 'A pattern for files to exclude when copying ' +
|
|
|
|
|
'an entire directory of resources.',
|
2012-09-09 02:25:02 +00:00
|
|
|
list: true
|
|
|
|
|
});
|
|
|
|
|
parser.parse();
|
2012-09-09 03:07:49 +00:00
|
|
|
|
2012-09-09 02:25:02 +00:00
|
|
|
var options = parser.options;
|
|
|
|
|
|
2014-02-08 11:43:55 -08:00
|
|
|
console.log('Copying sources...');
|
2013-02-19 20:10:39 -08:00
|
|
|
copySrcs(options.src, options.output);
|
2014-02-08 11:43:55 -08:00
|
|
|
console.log('Copying resource files...');
|
2013-06-29 22:59:48 -07:00
|
|
|
copyResources(options.output, options.resource, options.exclude_resource);
|
2014-02-08 11:43:55 -08:00
|
|
|
console.log('Generating documentation...');
|
2016-03-15 14:14:55 -07:00
|
|
|
gendocs().then(() => console.log('ALL DONE'), function(e) {
|
|
|
|
|
setTimeout(() => {throw e}, 0);
|
2014-07-06 16:19:51 -04:00
|
|
|
});
|
2012-09-09 02:25:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(module, require.main, 'This module may not be included');
|
|
|
|
|
main();
|