Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

depsync

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depsync - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

.travis.yml

658

lib/depsync.js

@@ -1,26 +0,632 @@

//////////////////////////////////////////////////////////////////////////////////////
//
// The MIT License (MIT)
//
// Copyright (c) 2017-present, Dom Chen
// All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in the
// Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////////////
console.log("it works!");
var Utils;
(function (Utils) {
var fs = require("fs");
var path = require("path");
var directorySeparator = "/";
function getRootLength(path) {
if (path.charAt(0) == "/") {
if (path.charAt(1) != "/")
return 1;
var p1 = path.indexOf("/", 2);
if (p1 < 0)
return 2;
var p2 = path.indexOf("/", p1 + 1);
if (p2 < 0)
return p1 + 1;
return p2 + 1;
}
if (path.charAt(1) == ":") {
if (path.charAt(2) == "/")
return 3;
return 2;
}
if (path.lastIndexOf("file:///", 0) === 0) {
return "file:///".length;
}
var idx = path.indexOf("://");
if (idx !== -1) {
return idx + "://".length;
}
return 0;
}
function joinPath(path1, path2) {
if (!(path1 && path1.length))
return path2;
if (!(path2 && path2.length))
return path1;
path1 = path1.split("\\").join(directorySeparator);
path2 = path2.split("\\").join(directorySeparator);
if (getRootLength(path2) !== 0)
return path2;
if (path1.charAt(path1.length - 1) === directorySeparator)
return path1 + path2;
return path1 + directorySeparator + path2;
}
Utils.joinPath = joinPath;
function createDirectory(filePath, mode) {
if (mode === undefined) {
mode = 511 & (~process.umask());
}
filePath = path.resolve(filePath);
try {
fs.mkdirSync(filePath, mode);
}
catch (err0) {
switch (err0.code) {
case 'ENOENT':
createDirectory(path.dirname(filePath), mode);
createDirectory(filePath, mode);
break;
default:
var stat = void 0;
try {
stat = fs.statSync(filePath);
}
catch (err1) {
throw err0;
}
if (!stat.isDirectory()) {
throw err0;
}
break;
}
}
}
Utils.createDirectory = createDirectory;
function deleteDirectory(path) {
var files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function (file) {
var curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
deleteDirectory(curPath);
}
else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
function deletePath(path) {
try {
if (fs.lstatSync(path).isDirectory()) {
deleteDirectory(path);
}
else {
fs.unlinkSync(path);
}
}
catch (e) {
}
}
Utils.deletePath = deletePath;
function writeFileTo(filePath, content, overwrite, mode) {
if (fs.existsSync(filePath)) {
if (!overwrite) {
return false;
}
var stat = fs.statSync(filePath);
if (stat.isDirectory()) {
return false;
}
}
var folder = path.dirname(filePath);
if (!fs.existsSync(folder)) {
createDirectory(folder);
}
var fd;
try {
fd = fs.openSync(filePath, 'w', 438);
}
catch (e) {
fs.chmodSync(filePath, 438);
fd = fs.openSync(filePath, 'w', 438);
}
if (fd) {
if (typeof content == "string") {
fs.writeSync(fd, content, 0, 'utf8');
}
else {
fs.writeSync(fd, content, 0, content.length, 0);
}
fs.closeSync(fd);
}
fs.chmodSync(filePath, mode || 438);
return true;
}
Utils.writeFileTo = writeFileTo;
})(Utils || (Utils = {}));
var __reflect = (this && this.__reflect) || function (p, c, t) {
p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var Config = (function () {
function Config(configFileName, platform) {
var data;
try {
var fs = require("fs");
var jsonText = fs.readFileSync(configFileName, "utf-8");
data = JSON.parse(jsonText);
}
catch (e) {
console.log("The DEPS config file is not a JSON file: " + configFileName);
process.exit(1);
}
var path = require("path");
var projectPath = path.dirname(configFileName);
this.parse(data, projectPath, platform);
}
Config.findConfigFile = function (searchPath) {
var fs = require("fs");
var path = require("path");
while (true) {
var fileName = Utils.joinPath(searchPath, "DEPS");
if (fs.existsSync(fileName)) {
return fileName;
}
var parentPath = path.dirname(searchPath);
if (parentPath === searchPath) {
break;
}
searchPath = parentPath;
}
return "";
};
Config.prototype.parse = function (data, projectPath, platform) {
var path = require("path");
var files = data.files;
var downloads = [];
if (files.common) {
for (var _i = 0, _a = files.common; _i < _a.length; _i++) {
var item = _a[_i];
downloads.push(item);
}
}
if (files[platform]) {
for (var _b = 0, _c = files[platform]; _b < _c.length; _b++) {
var item = _c[_b];
downloads.push(item);
}
}
for (var _d = 0, downloads_1 = downloads; _d < downloads_1.length; _d++) {
var item = downloads_1[_d];
item.url = this.formatString(item.url, data.vars);
item.dir = this.formatString(item.dir, data.vars);
item.dir = path.join(projectPath, item.dir);
var unzip = item.unzip;
if (typeof unzip == "string") {
unzip = this.formatString(unzip, data.vars);
item.unzip = (unzip == "true");
}
else if (typeof unzip != "boolean") {
item.unzip = false;
}
}
this.downloads = downloads;
};
Config.prototype.formatString = function (text, vars) {
var index = text.indexOf("${");
while (index != -1) {
var prefix = text.substring(0, index);
text = text.substring(index);
index = text.indexOf("}");
if (index == -1) {
text = prefix + text;
break;
}
var key = text.substring(2, index);
text = text.substring(index + 1);
var value = vars[key] ? vars[key] : "${" + key + "}";
text = prefix + value + text;
index = text.indexOf("${");
}
return text;
};
return Config;
}());
__reflect(Config.prototype, "Config");
var Cache;
(function (Cache) {
var fs = require('fs');
var path = require("path");
var downloads;
var projectPath;
var cacheConfigFile;
function readCache(configFileName) {
projectPath = path.dirname(configFileName);
cacheConfigFile = path.join(projectPath, "DEPS.cache");
var data;
try {
var jsonText = fs.readFileSync(cacheConfigFile, "utf-8");
data = JSON.parse(jsonText);
downloads = data.downloads;
}
catch (e) {
downloads = [];
}
}
Cache.readCache = readCache;
function isDownloaded(targetItem) {
var cachedItem;
for (var _i = 0, downloads_2 = downloads; _i < downloads_2.length; _i++) {
var item = downloads_2[_i];
if (item.url == targetItem.url) {
cachedItem = item;
break;
}
}
if (!cachedItem || cachedItem.unzip != targetItem.unzip || cachedItem.dir != path.relative(projectPath, targetItem.dir)) {
return false;
}
if (cachedItem.multipart && targetItem.multipart) {
if (cachedItem.multipart.length != targetItem.multipart.length) {
return false;
}
var index = 0;
for (var _a = 0, _b = cachedItem.multipart; _a < _b.length; _a++) {
var part = _b[_a];
if (part != targetItem.multipart[index]) {
return false;
}
index++;
}
return true;
}
return (!cachedItem.multipart && !targetItem.multipart);
}
Cache.isDownloaded = isDownloaded;
function finishDownload(targetItem) {
var index = 0;
for (var _i = 0, downloads_3 = downloads; _i < downloads_3.length; _i++) {
var item = downloads_3[_i];
if (item.url == targetItem.url) {
downloads.splice(index, 1);
break;
}
index++;
}
var cachedItem = { "url": targetItem.url, "dir": path.relative(projectPath, targetItem.dir) };
if (targetItem.unzip) {
cachedItem.unzip = true;
}
if (targetItem.multipart) {
cachedItem.multipart = targetItem.multipart.concat();
}
downloads.push(cachedItem);
}
Cache.finishDownload = finishDownload;
function checkIgnoreFile(configFile) {
if (fs.existsSync(configFile)) {
try {
var configText = fs.readFileSync(configFile, "utf-8");
if (configText.indexOf("DEPS.cache") == -1) {
configText = configText.trim() + "\nDEPS.cache\n";
Utils.writeFileTo(configFile, configText, true);
}
}
catch (e) {
}
}
}
function save() {
var data = { "downloads": downloads };
Utils.writeFileTo(cacheConfigFile, JSON.stringify(data, null, " "), true);
checkIgnoreFile(path.resolve(projectPath, ".gitignore"));
checkIgnoreFile(path.resolve(projectPath, ".npmignore"));
}
Cache.save = save;
})(Cache || (Cache = {}));
var CommandLine;
(function (CommandLine) {
var os = require("os");
CommandLine.optionDeclarations = [
{
name: "help",
shortName: "h",
type: "boolean",
description: "Print help message."
},
{
name: "project",
shortName: "p",
type: "string",
description: "Synchronize the project in the given directory.."
},
{
name: "version",
shortName: "v",
type: "boolean",
description: "Print depsync’s version."
}
];
var optionNameMapCache;
function getOptionNameMap() {
if (optionNameMapCache) {
return optionNameMapCache;
}
var optionNameMap = {};
var shortOptionNames = {};
CommandLine.optionDeclarations.forEach(function (option) {
optionNameMap[option.name.toLowerCase()] = option;
if (option.shortName) {
shortOptionNames[option.shortName] = option.name;
}
});
optionNameMapCache = { optionNameMap: optionNameMap, shortOptionNames: shortOptionNames };
return optionNameMapCache;
}
function parse(args) {
var options = {};
options.errors = [];
var _a = getOptionNameMap(), optionNameMap = _a.optionNameMap, shortOptionNames = _a.shortOptionNames;
var i = 0;
while (i < args.length) {
var s = args[i];
i++;
if (s.charAt(0) == "-") {
s = s.slice(s.charAt(1) == "-" ? 2 : 1).toLowerCase();
if (s in shortOptionNames) {
s = shortOptionNames[s];
}
if (s in optionNameMap) {
var opt = optionNameMap[s];
if (!args[i] && opt.type !== "boolean") {
options.errors.push("Option '" + opt.name + "' expects an argument.");
}
switch (opt.type) {
case "number":
options[opt.name] = parseInt(args[i]);
i++;
break;
case "boolean":
options[opt.name] = true;
break;
case "string":
options[opt.name] = args[i] || "";
i++;
break;
}
}
else {
options.errors.push("Unknown option '" + s + "'.");
}
}
else {
options.platform = s;
}
}
if (!options.platform) {
var p = os.platform();
if (p == "darwin") {
options.platform = "mac";
}
else if (p == "win32") {
options.platform = "win";
}
}
return options;
}
CommandLine.parse = parse;
})(CommandLine || (CommandLine = {}));
var Loader;
(function (Loader) {
var fs = require('fs');
var http = require('follow-redirects').http;
var https = require('follow-redirects').https;
var path = require("path");
var readLine = require("readline");
var AdmZip = require('adm-zip');
var ProgressBar = require("progress");
function downloadFiles(list, callback) {
if (list.length == 0) {
callback && callback();
return;
}
var item = list.shift();
if (Cache.isDownloaded(item)) {
downloadFiles(list, callback);
return;
}
var fileName = item.url.split("?")[0];
var filePath = path.join(item.dir, path.basename(fileName));
Utils.deletePath(filePath);
if (item.multipart) {
var urls = [];
for (var _i = 0, _a = item.multipart; _i < _a.length; _i++) {
var tail = _a[_i];
urls.push(item.url + tail);
}
loadMultiParts(urls, filePath, onFinish);
}
else {
loadSingleFile(item.url, filePath, onFinish);
}
function onFinish(error) {
if (error) {
console.log(error.message);
Cache.save();
return;
}
var filePaths = [];
if (item.unzip) {
try {
unzipFile(filePath, item.dir);
}
catch (e) {
console.log("Cannot unzip file: " + filePath);
process.exit(1);
}
}
else {
filePaths.push(filePath);
}
Cache.finishDownload(item);
downloadFiles(list, callback);
}
}
Loader.downloadFiles = downloadFiles;
function unzipFile(filePath, dir) {
console.log("unzip... " + filePath);
var zip = new AdmZip(filePath);
for (var _i = 0, _a = zip.getEntries(); _i < _a.length; _i++) {
var entry = _a[_i];
var entryName = entry.entryName.toString();
if (entryName.substr(0, 8) == "__MACOSX" || entryName.substr(entryName.length - 9, 9) == ".DS_Store") {
continue;
}
var targetPath = path.resolve(dir, entryName);
if (entry.isDirectory) {
Utils.deletePath(targetPath);
Utils.createDirectory(targetPath);
continue;
}
var content = entry.getData();
if (!content) {
console.log("Cannot unzip file:" + filePath);
break;
}
Utils.writeFileTo(targetPath, content, true);
}
Utils.deletePath(filePath);
readLine.moveCursor(process.stderr, 0, -1);
readLine.clearScreenDown(process.stderr);
}
function loadMultiParts(urls, filePath, callback) {
if (urls.length == 0) {
callback && callback();
return;
}
var url = urls.shift();
loadSingleFile(url, filePath, function (error) {
if (error) {
callback && callback(error);
return;
}
loadMultiParts(urls, filePath, callback);
}, { flags: 'a' });
}
function loadSingleFile(url, filePath, callback, options) {
console.log("download... " + url);
var httpClient = url.slice(0, 5) === 'https' ? https : http;
try {
Utils.createDirectory(path.dirname(filePath));
}
catch (e) {
console.log("Cannot create directory: " + path.dirname(filePath));
process.exit(1);
}
var file = fs.createWriteStream(filePath, options);
var outputError;
file.on("close", function () {
callback && callback(outputError);
});
var request = httpClient.get(url, function (response) {
var length = parseInt(response.headers['content-length'], 10);
var bar = new ProgressBar(':bar [ :percent | :current/:total | :etas ] ', {
complete: '█',
incomplete: '░',
width: 80,
total: length
});
response.on('data', function (chunk) {
file.write(chunk);
bar.tick(chunk.length);
});
response.on('end', function () {
file.end();
readLine.moveCursor(process.stderr, 0, -1);
readLine.clearScreenDown(process.stderr);
});
response.on('error', function (error) {
file.close();
outputError = error;
readLine.moveCursor(process.stderr, 0, -1);
readLine.clearScreenDown(process.stderr);
});
});
}
})(Loader || (Loader = {}));
function createMap() {
var map = Object.create(null);
map["__"] = undefined;
delete map["__"];
return map;
}
var Program;
(function (Program) {
var fs = require("fs");
var path = require("path");
var CHARSET = "utf-8";
var VERSION = "1.0.0";
function run(args) {
var commandOptions = CommandLine.parse(args);
if (commandOptions.errors.length > 0) {
console.log(commandOptions.errors.join("\n") + "\n");
process.exit(1);
}
if (commandOptions.version) {
printVersion();
return;
}
if (commandOptions.help) {
printVersion();
printHelp();
return;
}
var configFileName = "";
if (commandOptions.project) {
if (!commandOptions.project || fs.existsSync(commandOptions.project)) {
configFileName = Utils.joinPath(commandOptions.project, "DEPS");
}
else {
configFileName = commandOptions.project;
}
if (!fs.existsSync(configFileName)) {
console.log("Cannot find a DEPS file at the specified directory: " + commandOptions.project + "\n");
process.exit(1);
}
}
else {
var searchPath = process.cwd();
configFileName = Config.findConfigFile(searchPath);
if (!configFileName) {
printVersion();
printHelp();
return;
}
}
var config = new Config(configFileName, commandOptions.platform);
Cache.readCache(configFileName);
Loader.downloadFiles(config.downloads, function () {
Cache.save();
});
}
Program.run = run;
function printVersion() {
console.log("Version " + VERSION + "\n");
}
function printHelp() {
var newLine = "\n";
var output = "";
output += "Syntax: depsync [platform] [options]" + newLine + newLine;
output += "Examples: depsync --version" + newLine;
output += "Examples: depsync mac" + newLine;
output += "Examples: depsync mac --project /usr/local/test/" + newLine + newLine;
output += "Options:" + newLine;
CommandLine.optionDeclarations.forEach(function (option) {
var name = "";
if (option.shortName) {
name += "-" + option.shortName + ", ";
}
name += "--" + option.name;
name += makePadding(25 - name.length);
output += name + option.description + newLine;
});
console.log(output);
}
function makePadding(paddingLength) {
return Array(paddingLength + 1).join(" ");
}
})(Program || (Program = {}));
Program.run(process.argv.slice(2));
{
"name": "depsync",
"version": "0.0.2",
"version": "1.0.0",
"author": "Dom Chen",

@@ -26,4 +26,10 @@ "homepage": "http://www.idom.me/",

"dependencies": {
"adm-zip": "latest",
"follow-redirects": "latest",
"progress": "latest"
},
"devDependencies": {
"@types/node": "^7.0.12",
"@types/progress": "^1.1.28"
}
}

@@ -1,2 +0,86 @@

# depsync
Automatically synchronize the dependencies of a project by the DEPS configuration file.
<p align="left">
<a href="https://travis-ci.org/domchen/depsync"><img src="https://img.shields.io/travis/domchen/depsync/master.svg" alt="Build Status"></a>
<a href="https://www.npmjs.com/package/depsync"><img src="https://img.shields.io/npm/v/depsync.svg" alt="Version"></a>
<a href="https://github.com/domchen/depsync/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/depsync.svg" alt="License"></a>
<a href="https://github.com/Microsoft/Typescript"><img src="https://img.shields.io/badge/code-TypeScript-blue.svg" alt="TypeScript"></a>
</p>
# Introduction
Depsync is a command line tool for automatically synchronizing the dependencies of a project by the DEPS configuration file.
# Installation
`npm install depsync -g`
## Usage
Run the following command in the directory with a DEPS file:
```
depsync [platform]
```
For example, if you want to synchronize the mac platform, run:
```
depsync mac
```
If you don't pass any platform parameter, it will automatically choose the host platform as the target platform. So that the result of running `depsync` in macOS is the same as running `depsync mac`.
The available platform names are defined in the DEPS file, you can also define any other platform names as you want, such as `ios`, `android`, `linux`... but only the `mac` and `win` can be automatically chosen.
Here is an example of DEPS file:
```
{
"vars": {
"SKIA_ROOT": "https://raw.githubusercontent.com/domchen/libskia/release",
"V8_ROOT": "https://raw.githubusercontent.com/domchen/libv8/release"
},
"files": {
"common": [
{
"url": "${SKIA_ROOT}/m58/include.zip",
"dir": "third_party/skia",
"unzip": true
},
{
"url": "${V8_ROOT}/5.7.492/include.zip",
"dir": "third_party/v8",
"unzip": "true"
}
],
"mac": [
{
"url": "${SKIA_ROOT}/m58/darwin-x64.zip",
"dir": "third_party/skia",
"unzip": true
},
{
"url": "${V8_ROOT}/5.7.492/darwin-x64.zip",
"multipart": [
".001",
".002",
".003"
],
"dir": "third_party/v8",
"unzip": true
}
],
"win": [
{
"url": "${SKIA_ROOT}/m58/win-ia32.zip",
"dir": "third_party/skia",
"unzip": true
},
{
"url": "${V8_ROOT}/5.7.492/win-ia32.zip",
"dir": "third_party/v8",
"unzip": true
}
]
}
}
```
.idea/depsync.iml

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc