Skip to content

Commit

Permalink
running npm run eslint -- --fix locally to fix var->let/const eslint …
Browse files Browse the repository at this point in the history
…failures
  • Loading branch information
loshjawrence committed Nov 6, 2018
1 parent 3c28bf9 commit bf199a7
Show file tree
Hide file tree
Showing 83 changed files with 1,514 additions and 1,514 deletions.
92 changes: 46 additions & 46 deletions bin/gltf-pipeline.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env node
'use strict';
var Cesium = require('cesium');
var fsExtra = require('fs-extra');
var path = require('path');
var Promise = require('bluebird');
var yargs = require('yargs');
var compressDracoMeshes = require('../lib/compressDracoMeshes');
var glbToGltf = require('../lib/glbToGltf');
var gltfToGlb = require('../lib/gltfToGlb');
var processGlb = require('../lib/processGlb');
var processGltf = require('../lib/processGltf');

var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;

var defaults = processGltf.defaults;
var dracoDefaults = compressDracoMeshes.defaults;

var args = process.argv;

var argv = yargs
const Cesium = require('cesium');
const fsExtra = require('fs-extra');
const path = require('path');
const Promise = require('bluebird');
const yargs = require('yargs');
const compressDracoMeshes = require('../lib/compressDracoMeshes');
const glbToGltf = require('../lib/glbToGltf');
const gltfToGlb = require('../lib/gltfToGlb');
const processGlb = require('../lib/processGlb');
const processGltf = require('../lib/processGltf');

const defaultValue = Cesium.defaultValue;
const defined = Cesium.defined;

const defaults = processGltf.defaults;
const dracoDefaults = compressDracoMeshes.defaults;

const args = process.argv;

const argv = yargs
.usage('Usage: node $0 -i inputPath -o outputPath')
.example('node $0 -i model.gltf')
.example('node $0 -i model.gltf -b')
Expand Down Expand Up @@ -122,18 +122,18 @@ var argv = yargs
}
}).parse(args);

var inputPath = argv.input;
var outputPath = argv.output;
const inputPath = argv.input;
let outputPath = argv.output;

var inputDirectory = path.dirname(inputPath);
var inputName = path.basename(inputPath, path.extname(inputPath));
var inputExtension = path.extname(inputPath).toLowerCase();
const inputDirectory = path.dirname(inputPath);
const inputName = path.basename(inputPath, path.extname(inputPath));
const inputExtension = path.extname(inputPath).toLowerCase();
if (inputExtension !== '.gltf' && inputExtension !== '.glb') {
console.log('Error: unrecognized file extension "' + inputExtension + '".');
return;
}

var outputExtension;
let outputExtension;
if (!defined(outputPath)) {
if (argv.binary) {
outputExtension = '.glb';
Expand All @@ -145,25 +145,25 @@ if (!defined(outputPath)) {
outputPath = path.join(inputDirectory, inputName + '-processed' + outputExtension);
}

var outputDirectory = path.dirname(outputPath);
var outputName = path.basename(outputPath, path.extname(outputPath));
const outputDirectory = path.dirname(outputPath);
const outputName = path.basename(outputPath, path.extname(outputPath));
outputExtension = path.extname(outputPath).toLowerCase();
if (outputExtension !== '.gltf' && outputExtension !== '.glb') {
console.log('Error: unrecognized file extension "' + outputExtension + '".');
return;
}

var i;
var dracoOptions;
var length = args.length;
let i;
let dracoOptions;
const length = args.length;
for (i = 0; i < length; ++i) {
var arg = args[i];
const arg = args[i];
if (arg.indexOf('--draco.') === 0 || arg === '-d') {
dracoOptions = defaultValue(argv.draco, {});
}
}

var options = {
const options = {
resourceDirectory: inputDirectory,
separate: argv.separate,
separateTextures: argv.separateTextures,
Expand All @@ -173,24 +173,24 @@ var options = {
dracoOptions: dracoOptions
};

var inputIsBinary = inputExtension === '.glb';
var outputIsBinary = outputExtension === '.glb';
const inputIsBinary = inputExtension === '.glb';
const outputIsBinary = outputExtension === '.glb';

var jsonOptions = {
const jsonOptions = {
spaces: 2
};

var read = inputIsBinary ? fsExtra.readFile : fsExtra.readJson;
var write = outputIsBinary ? fsExtra.outputFile : fsExtra.outputJson;
var writeOptions = outputIsBinary ? undefined : jsonOptions;
var run = inputIsBinary ? (outputIsBinary ? processGlb : glbToGltf) : (outputIsBinary ? gltfToGlb : processGltf);
const read = inputIsBinary ? fsExtra.readFile : fsExtra.readJson;
const write = outputIsBinary ? fsExtra.outputFile : fsExtra.outputJson;
const writeOptions = outputIsBinary ? undefined : jsonOptions;
const run = inputIsBinary ? (outputIsBinary ? processGlb : glbToGltf) : (outputIsBinary ? gltfToGlb : processGltf);

function saveSeparateResources(separateResources) {
var resourcePromises = [];
for (var relativePath in separateResources) {
const resourcePromises = [];
for (const relativePath in separateResources) {
if (separateResources.hasOwnProperty(relativePath)) {
var resource = separateResources[relativePath];
var resourcePath = path.join(outputDirectory, relativePath);
const resource = separateResources[relativePath];
const resourcePath = path.join(outputDirectory, relativePath);
resourcePromises.push(fsExtra.outputFile(resourcePath, resource));
}
}
Expand All @@ -204,8 +204,8 @@ read(inputPath)
return run(gltf, options);
})
.then(function(results) {
var gltf = defaultValue(results.gltf, results.glb);
var separateResources = results.separateResources;
const gltf = defaultValue(results.gltf, results.glb);
const separateResources = results.separateResources;
return Promise.all([
write(outputPath, gltf, writeOptions),
saveSeparateResources(separateResources)
Expand Down
114 changes: 57 additions & 57 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
'use strict';

var Cesium = require('cesium');
var child_process = require('child_process');
var dependencyTree = require('dependency-tree');
var fsExtra = require('fs-extra');
var gulp = require('gulp');
var Jasmine = require('jasmine');
var JasmineSpecReporter = require('jasmine-spec-reporter').SpecReporter;
var open = require('open');
var path = require('path');
var Promise = require('bluebird');
var yargs = require('yargs');

var defined = Cesium.defined;
var argv = yargs.argv;
const Cesium = require('cesium');
const child_process = require('child_process');
const dependencyTree = require('dependency-tree');
const fsExtra = require('fs-extra');
const gulp = require('gulp');
const Jasmine = require('jasmine');
const JasmineSpecReporter = require('jasmine-spec-reporter').SpecReporter;
const open = require('open');
const path = require('path');
const Promise = require('bluebird');
const yargs = require('yargs');

const defined = Cesium.defined;
const argv = yargs.argv;

// Add third-party node module binaries to the system path
// since some tasks need to call them directly.
var environmentSeparator = process.platform === 'win32' ? ';' : ':';
var nodeBinaries = path.join(__dirname, 'node_modules', '.bin');
const environmentSeparator = process.platform === 'win32' ? ';' : ':';
const nodeBinaries = path.join(__dirname, 'node_modules', '.bin');
process.env.PATH += environmentSeparator + nodeBinaries;

var specFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**', '!bin/**', '!dist/**'];
const specFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!doc/**', '!bin/**', '!dist/**'];

gulp.task('test', function (done) {
var jasmine = new Jasmine();
const jasmine = new Jasmine();
jasmine.loadConfigFile('specs/jasmine.json');
jasmine.addReporter(new JasmineSpecReporter({
displaySuccessfulSpec: !defined(argv.suppressPassed) || !argv.suppressPassed
Expand Down Expand Up @@ -64,11 +64,11 @@ gulp.task('coverage', function () {
});

gulp.task('cloc', function() {
var cmdLine;
var clocPath = path.join('node_modules', 'cloc', 'lib', 'cloc');
let cmdLine;
const clocPath = path.join('node_modules', 'cloc', 'lib', 'cloc');

// Run cloc on primary Source files only
var source = new Promise(function(resolve, reject) {
const source = new Promise(function(resolve, reject) {
cmdLine = 'perl ' + clocPath + ' --quiet --progress-rate=0' +
' lib/ bin/';

Expand Down Expand Up @@ -102,18 +102,18 @@ gulp.task('cloc', function() {
});

function amdify(source, subDependencyMapping) {
var fullMatch;
var variableName;
var requireVariable;
var requirePath;
let fullMatch;
let variableName;
let requireVariable;
let requirePath;

source = source.replace(/\r\n/g, '\n');
var outputSource = source;
let outputSource = source;

// find module exports
var returnValue;
var findModuleExportsRegex = /module.exports\s*=\s*(.*?);\n/;
var findModuleExports = findModuleExportsRegex.exec(source);
let returnValue;
const findModuleExportsRegex = /module.exports\s*=\s*(.*?);\n/;
const findModuleExports = findModuleExportsRegex.exec(source);
if (defined(findModuleExports && findModuleExports.length > 0)) {
fullMatch = findModuleExports[0];
returnValue = findModuleExports[1];
Expand All @@ -122,9 +122,9 @@ function amdify(source, subDependencyMapping) {
}

// create require mapping for dependencies
var findRequireRegex = /var\s+(.+?)\s*=\s*require\('(.+?)'\);\n/g;
var findRequire = findRequireRegex.exec(source);
var requireMapping = {};
const findRequireRegex = /var\s+(.+?)\s*=\s*require\('(.+?)'\);\n/g;
let findRequire = findRequireRegex.exec(source);
const requireMapping = {};
while (defined(findRequire) && findRequire.length > 0) {
fullMatch = findRequire[0];
variableName = findRequire[1];
Expand All @@ -135,23 +135,23 @@ function amdify(source, subDependencyMapping) {
findRequire = findRequireRegex.exec(source);
}
// find places where sub-dependencies are pulled from a require
var subdependencyMapping = {};
var removeRequireMapping = [];
const subdependencyMapping = {};
const removeRequireMapping = [];
for (requireVariable in requireMapping) {
if (requireMapping.hasOwnProperty(requireVariable)) {
requirePath = requireMapping[requireVariable];
var findSubdependencyString = 'var\\s+(.+?)\\s*?=\\s*?' + requireVariable + '\\.(.+?);\n';
var findSubdependencyRegex = new RegExp(findSubdependencyString, 'g');
var findSubdependency = findSubdependencyRegex.exec(source);
const findSubdependencyString = 'var\\s+(.+?)\\s*?=\\s*?' + requireVariable + '\\.(.+?);\n';
const findSubdependencyRegex = new RegExp(findSubdependencyString, 'g');
let findSubdependency = findSubdependencyRegex.exec(source);
while (defined(findSubdependency) && findSubdependency.length > 0) {
var mapping = subDependencyMapping[requirePath];
const mapping = subDependencyMapping[requirePath];
if (!defined(mapping)) {
throw new Error('Build Failed: Module sub-dependency found for ' + requirePath + ' with no defined mapping behavior.');
}
removeRequireMapping.push(requireVariable);
fullMatch = findSubdependency[0];
variableName = findSubdependency[1];
var subdependencyPath = findSubdependency[2];
const subdependencyPath = findSubdependency[2];
subdependencyMapping[variableName] = mapping.prefix + subdependencyPath;
// remove sub-dependency declarations from output source
outputSource = outputSource.replace(fullMatch, '');
Expand All @@ -161,11 +161,11 @@ function amdify(source, subDependencyMapping) {
}
// Top-level modules can be removed if mapped
while (removeRequireMapping.length > 0) {
var removeVariableName = removeRequireMapping.pop();
const removeVariableName = removeRequireMapping.pop();
delete requireMapping[removeVariableName];
}
// join sub-dependencies with requireMapping
for (var subdependencyVariable in subdependencyMapping) {
for (const subdependencyVariable in subdependencyMapping) {
if (subdependencyMapping.hasOwnProperty(subdependencyVariable)) {
requireMapping[subdependencyVariable] = subdependencyMapping[subdependencyVariable];
}
Expand All @@ -174,25 +174,25 @@ function amdify(source, subDependencyMapping) {
// indent
outputSource = outputSource.replace(/\n/g, '\n ');
// wrap define header
var variables = [];
var paths = [];
for (var variable in requireMapping) {
const variables = [];
const paths = [];
for (const variable in requireMapping) {
if (requireMapping.hasOwnProperty(variable)) {
variables.push(variable);
paths.push(requireMapping[variable]);
}
}
var defineHeader = 'define([], function() {\n ';
let defineHeader = 'define([], function() {\n ';
if (paths.length > 0) {
var definePathsHeader = '\'' + paths.join('\',\n \'') + '\'';
var defineVariablesHeader = variables.join(',\n ');
const definePathsHeader = '\'' + paths.join('\',\n \'') + '\'';
const defineVariablesHeader = variables.join(',\n ');
defineHeader =
'define([\n' +
' ' + definePathsHeader + '\n' +
' ], function(\n' +
' ' + defineVariablesHeader + ') {\n ';
}
var defineFooter = '\n});\n';
let defineFooter = '\n});\n';
if (defined(returnValue)) {
defineFooter = '\n return ' + returnValue + ';' + defineFooter;
}
Expand All @@ -203,9 +203,9 @@ function amdify(source, subDependencyMapping) {
}

gulp.task('build-cesium', function () {
var basePath = 'lib';
var outputDir = 'dist/cesium';
var files = [
const basePath = 'lib';
const outputDir = 'dist/cesium';
const files = [
'addDefaults.js',
'addPipelineExtras.js',
'ForEach.js',
Expand All @@ -214,15 +214,15 @@ gulp.task('build-cesium', function () {
'updateVersion.js'
];

var subDependencyMapping = {
const subDependencyMapping = {
cesium : {
prefix : '../../Core/'
}
};

var filesToAmdify = {};
const filesToAmdify = {};
Promise.map(files, function (fileName) {
var filePath = path.join(basePath, fileName);
const filePath = path.join(basePath, fileName);

// Get list of dependant files
filesToAmdify[filePath] = true;
Expand All @@ -237,12 +237,12 @@ gulp.task('build-cesium', function () {
});
}).then(function () {
return Promise.map(Object.keys(filesToAmdify), function(filePath) {
var fileName = path.relative(basePath, filePath);
const fileName = path.relative(basePath, filePath);
return fsExtra.readFile(filePath)
.then(function (buffer) {
var source = buffer.toString();
let source = buffer.toString();
source = amdify(source, subDependencyMapping);
var outputPath = path.join(outputDir, fileName);
const outputPath = path.join(outputDir, fileName);
return fsExtra.outputFile(outputPath, source);
});
});
Expand Down
Loading

0 comments on commit bf199a7

Please sign in to comment.