[cleanup] remove npm lodash (#2155)

remove npm lodash and unused scripts directory.  Removes usage of
lodash 3.10 in node files.
This commit is contained in:
Pete Richards 2018-08-31 12:04:16 -07:00 committed by Pegah Sarram
parent a2b0d350d8
commit ca16892237
6 changed files with 2 additions and 265 deletions

View File

@ -31,7 +31,6 @@ var gulp = require('gulp'),
git = require('git-rev-sync'),
moment = require('moment'),
project = require('./package.json'),
_ = require('lodash'),
paths = {
main: 'openmct.js',
dist: 'dist',
@ -140,7 +139,7 @@ gulp.task('checkstyle', function () {
var mkdirp = require('mkdirp');
var reportName = 'jscs-html-report.html';
var reportPath = path.resolve(paths.reports, 'checkstyle', reportName);
var moveReport = fs.rename.bind(fs, reportName, reportPath, _.noop);
var moveReport = fs.rename.bind(fs, reportName, reportPath, function () {});
mkdirp.sync(path.resolve(paths.reports, 'checkstyle'));
@ -179,4 +178,4 @@ gulp.task('install', [ 'assets', 'scripts' ]);
gulp.task('verify', [ 'lint', 'test', 'checkstyle' ]);
gulp.task('build', [ 'verify', 'install' ]);
gulp.task('build', [ 'verify', 'install' ]);

View File

@ -43,7 +43,6 @@
"karma-html-reporter": "^0.2.7",
"karma-jasmine": "^1.1.2",
"karma-requirejs": "^1.1.0",
"lodash": "^3.10.1",
"markdown-toc": "^0.11.7",
"marked": "^0.3.5",
"merge-stream": "^1.0.0",

View File

@ -1,49 +0,0 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2018, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed 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
* http://www.apache.org/licenses/LICENSE-2.0.
*
* 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.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
// Converts all templateUrl references in bundle.js files to
// plain template references, loading said templates with the
// RequireJS text plugin.
var glob = require('glob'),
fs = require('fs');
function migrate(file) {
var sourceCode = fs.readFileSync(file, 'utf8'),
lines = sourceCode.split('\n')
.filter(function (line) {
return !(/^\W*['"]use strict['"];\W*$/.test(line));
})
.filter(function (line) {
return line.indexOf("/*global") !== 0;
});
fs.writeFileSync(file, lines.join('\n'));
}
glob('@(src|platform)/**/*.js', {}, function (err, files) {
if (err) {
console.log(err);
return;
}
files.forEach(migrate);
});

View File

@ -1,106 +0,0 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2018, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed 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
* http://www.apache.org/licenses/LICENSE-2.0.
*
* 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.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
// Converts all templateUrl references in bundle.js files to
// plain template references, loading said templates with the
// RequireJS text plugin.
var glob = require('glob'),
fs = require('fs'),
path = require('path'),
_ = require('lodash');
function toTemplateName(templateUrl) {
var parts = templateUrl.split('/');
return _.camelCase(parts[parts.length - 1].replace(".html", "")) +
"Template";
}
function getTemplateUrl(sourceLine) {
return _.trim(sourceLine.split(":")[1], "\", ");
}
function hasTemplateUrl(sourceLine) {
return sourceLine.indexOf("templateUrl") !== -1;
}
function findTemplateURLs(sourceCode) {
return sourceCode.split('\n')
.map(_.trim)
.filter(hasTemplateUrl)
.map(getTemplateUrl);
}
function injectRequireArgument(sourceCode, templateUrls) {
var lines = sourceCode.split('\n'),
index;
templateUrls = _.uniq(templateUrls);
// Add arguments for source paths...
index = lines.map(_.trim).indexOf("'legacyRegistry'");
lines = lines.slice(0, index).concat(templateUrls.map(function (url) {
return " \"text!./res/" + url + "\",";
}).concat(lines.slice(index)));
/// ...and for arguments
index = lines.map(_.trim).indexOf("legacyRegistry");
lines = lines.slice(0, index).concat(templateUrls.map(function (url) {
return " " + toTemplateName(url) + ",";
}).concat(lines.slice(index)));
return lines.join('\n');
}
function rewriteUrl(sourceLine) {
return [
sourceLine.substring(0, sourceLine.indexOf(sourceLine.trim())),
"\"template\": " + toTemplateName(getTemplateUrl(sourceLine)),
_.endsWith(sourceLine, ",") ? "," : ""
].join('');
}
function rewriteLine(sourceLine) {
return hasTemplateUrl(sourceLine) ?
rewriteUrl(sourceLine.replace("templateUrl", "template")) :
sourceLine;
}
function rewriteTemplateUrls(sourceCode) {
return sourceCode.split('\n').map(rewriteLine).join('\n');
}
function migrate(file) {
var sourceCode = fs.readFileSync(file, 'utf8');
fs.writeFileSync(file, rewriteTemplateUrls(
injectRequireArgument(sourceCode, findTemplateURLs(sourceCode))
), 'utf8');
}
glob('platform/**/bundle.js', {}, function (err, files) {
if (err) {
console.log(err);
return;
}
files.forEach(migrate);
});

View File

@ -1,34 +0,0 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2018, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed 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
* http://www.apache.org/licenses/LICENSE-2.0.
*
* 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.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define*/
define([
<%= implPaths %>
'legacyRegistry'
], function (
<%= implNames %>
legacyRegistry
) {
"use strict";
legacyRegistry.register("<%= bundleName %>", <%= bundleContents %>);
});

View File

@ -1,72 +0,0 @@
// Temporary utility script to rewrite bundle.json
// files as bundle.js files.
var glob = require('glob'),
fs = require('fs'),
path = require('path'),
_ = require('lodash'),
template = _.template(
fs.readFileSync(path.resolve(__dirname, 'rebundle-template.txt'), 'utf8')
);
function indent(str, depth) {
return _.trimLeft(str.split('\n').map(function (line) {
return _.repeat(' ', depth || 1) + line;
}).filter(function (line) {
return line.trim().length > 0;
}).join('\n'));
}
function findImpls(bundleContents) {
return _(bundleContents.extensions || {})
.map()
.flatten()
.pluck('implementation')
.filter()
.uniq()
.value();
}
function toIdentifier(impl) {
var parts = impl.replace(".js", "").split('/');
return parts[parts.length - 1];
}
function toPath(impl) {
return "\"./src/" + impl.replace(".js", "") + "\"";
}
function replaceImpls(bundleText) {
var rx = /"implementation": "([^"]*)"/;
return bundleText.split('\n').map(function (line) {
var m = line.match(rx);
return m !== null ?
line.replace(rx, '"implementation": ' + toIdentifier(m[1])) :
line;
}).join('\n');
}
function rebundle(file) {
var plainJson = fs.readFileSync(file, 'utf8'),
bundleContents = JSON.parse(plainJson),
impls = findImpls(bundleContents),
bundleName = file.replace("/bundle.json", ""),
outputFile = file.replace(".json", ".js"),
contents = template({
bundleName: bundleName,
implPaths: indent(impls.map(toPath).concat([""]).join(",\n")),
implNames: indent(impls.map(toIdentifier).concat([""]).join(",\n")),
bundleContents: indent(replaceImpls(JSON.stringify(bundleContents, null, 4)))
});
fs.writeFileSync(outputFile, contents, 'utf8');
}
glob('**/bundle.json', {}, function (err, files) {
if (err) {
console.log(err);
return;
}
files.forEach(rebundle);
});