Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "depsync", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "Dom Chen", | ||
@@ -5,0 +5,0 @@ "homepage": "http://www.idom.me/", |
@@ -40,5 +40,11 @@ ////////////////////////////////////////////////////////////////////////////////////// | ||
type: "string", | ||
description: "Synchronize the project in the given directory.." | ||
description: "Synchronize the project in the given directory." | ||
}, | ||
{ | ||
name: "clean", | ||
shortName: "c", | ||
type: "boolean", | ||
description: "Clean the repos and files of current directory that do not exist in the DEPS file." | ||
}, | ||
{ | ||
name: "version", | ||
@@ -45,0 +51,0 @@ shortName: "v", |
@@ -72,6 +72,3 @@ ////////////////////////////////////////////////////////////////////////////////////// | ||
} | ||
let cache = Utils.readFile(item.hashFile); | ||
if (cache !== item.hash) { | ||
list.push(item); | ||
} | ||
list.push(item); | ||
} | ||
@@ -91,7 +88,3 @@ return list; | ||
item.dir = path.resolve(projectPath, item.dir); | ||
let shallowFile = path.join(item.dir, ".git", "shallow"); | ||
let commit = Utils.readFile(shallowFile).substr(0, 40); | ||
if (commit !== item.commit) { | ||
list.push(item); | ||
} | ||
list.push(item); | ||
} | ||
@@ -141,3 +134,3 @@ return list; | ||
for (let platform of platforms) { | ||
if (platform === hostPlatform || platform === "common") { | ||
if (!hostPlatform || platform === hostPlatform || platform === "common") { | ||
for (let item of items[platform]) { | ||
@@ -151,8 +144,38 @@ list.push(item); | ||
function parse(configFileName, platform) { | ||
function compareVersion(versionA, versionB) { | ||
if (versionA === versionB) { | ||
return 0; | ||
} | ||
let listA = versionA.split("."); | ||
let listB = versionB.split("."); | ||
let length = Math.max(listA.length, listB.length); | ||
for (let i = 0; i < length; i++) { | ||
if (listA.length <= i) { | ||
return -1; | ||
} | ||
let a = parseInt(listA[i]); | ||
if (listB.length <= i) { | ||
return 1; | ||
} | ||
let b = parseInt(listB[i]); | ||
if (a === b) { | ||
continue; | ||
} | ||
return a > b ? 1 : -1; | ||
} | ||
return 0; | ||
} | ||
function parse(configFileName, version, platform) { | ||
if (!fs.existsSync(configFileName)) { | ||
return null; | ||
} | ||
let jsonText = Utils.readFile(configFileName); | ||
let data; | ||
try { | ||
let jsonText = Utils.readFile(configFileName); | ||
data = JSON.parse(jsonText); | ||
} catch (e) { | ||
if (jsonText.trimLeft().indexOf("{") === 0) { | ||
Utils.error("The DEPS config file is not a valid JSON file: " + configFileName); | ||
} | ||
return null; | ||
@@ -163,2 +186,9 @@ } | ||
config.version = data.version ? data.version : "0.0.0"; | ||
if (compareVersion(version, config.version) < 0) { | ||
Utils.error("The DEPS config requires a high depsync tool version: " + configFileName); | ||
Utils.error("Requires version: " + config.version); | ||
Utils.error("Current version: " + version); | ||
Utils.error("Please update the depsync tool and try again."); | ||
return null; | ||
} | ||
let files = filterByPlatform(data.files, platform); | ||
@@ -165,0 +195,0 @@ config.files = parseFiles(files, data.vars, projectPath); |
@@ -31,2 +31,3 @@ ////////////////////////////////////////////////////////////////////////////////////// | ||
const Config = require('./Config'); | ||
const CleanTask = require('./tasks/CleanTask'); | ||
const DepsTask = require('./tasks/DepsTask'); | ||
@@ -96,8 +97,15 @@ const {version} = require('../package.json'); | ||
} | ||
let task = new DepsTask(version, configFileName, commandOptions.platform); | ||
task.run(() => { | ||
process.exit(0); | ||
}); | ||
if (commandOptions.clean) { | ||
let task = new CleanTask(configFileName, version); | ||
task.run(() => { | ||
process.exit(0); | ||
}); | ||
} else { | ||
let task = new DepsTask(configFileName, version, commandOptions.platform); | ||
task.run(() => { | ||
process.exit(0); | ||
}); | ||
} | ||
} | ||
exports.run = run; |
@@ -36,29 +36,5 @@ ////////////////////////////////////////////////////////////////////////////////////// | ||
function compareVersion(versionA, versionB) { | ||
if (versionA === versionB) { | ||
return 0; | ||
} | ||
let listA = versionA.split("."); | ||
let listB = versionB.split("."); | ||
let length = Math.max(listA.length, listB.length); | ||
for (let i = 0; i < length; i++) { | ||
if (listA.length <= i) { | ||
return -1; | ||
} | ||
let a = parseInt(listA[i]); | ||
if (listB.length <= i) { | ||
return 1; | ||
} | ||
let b = parseInt(listB[i]); | ||
if (a === b) { | ||
continue; | ||
} | ||
return a > b ? 1 : -1; | ||
} | ||
return 0; | ||
} | ||
function DepsTask(version, configFile, platform) { | ||
function DepsTask(configFile, version, platform) { | ||
this.configFile = configFile; | ||
this.version = version; | ||
this.configFile = configFile; | ||
this.platform = platform; | ||
@@ -68,25 +44,22 @@ } | ||
DepsTask.prototype.run = function (callback) { | ||
if (!fs.existsSync(this.configFile)) { | ||
let config = Config.parse(this.configFile, this.version, this.platform); | ||
if (!config) { | ||
callback && callback(); | ||
return; | ||
} | ||
let config = Config.parse(this.configFile, this.platform); | ||
if (!config) { | ||
Utils.error("The DEPS config file is not a valid JSON file: " + this.configFile); | ||
process.exit(1); | ||
} | ||
if (compareVersion(this.version, config.version) < 0) { | ||
Utils.error("DEPS file requires version: " + config.version); | ||
Utils.error("The current depsync version: " + this.version); | ||
Utils.error("Please update the depsync tool and then try again."); | ||
process.exit(1); | ||
} | ||
let tasks = []; | ||
for (let item of config.repos) { | ||
tasks.push(new RepoTask(item)); | ||
let depsFile = path.join(item.dir, "DEPS"); | ||
tasks.push(new DepsTask(this.version, depsFile, this.platform)); | ||
let shallowFile = path.join(item.dir, ".git", "shallow"); | ||
let commit = Utils.readFile(shallowFile).substr(0, 40); | ||
if (commit !== item.commit) { | ||
tasks.push(new RepoTask(item)); | ||
let depsFile = path.join(item.dir, "DEPS"); | ||
tasks.push(new DepsTask(depsFile, this.version, this.platform)); | ||
} | ||
} | ||
for (let item of config.files) { | ||
tasks.push(new FileTask(item)); | ||
let cache = Utils.readFile(item.hashFile).substring(0, 40); | ||
if (cache !== item.hash) { | ||
tasks.push(new FileTask(item)); | ||
} | ||
} | ||
@@ -93,0 +66,0 @@ for (let item of config.actions) { |
@@ -77,2 +77,15 @@ ////////////////////////////////////////////////////////////////////////////////////// | ||
function deleteEmptyDir(path) { | ||
try { | ||
if (!fs.lstatSync(path).isDirectory()) { | ||
return; | ||
} | ||
let files = fs.readdirSync(path); | ||
if (files.length === 0) { | ||
fs.rmdirSync(path); | ||
} | ||
} catch (e) { | ||
} | ||
} | ||
function deletePath(path) { | ||
@@ -155,6 +168,7 @@ try { | ||
let options = { | ||
shell: true, | ||
shell: os.platform() === "win32" ? "cmd.exe" : true, | ||
cwd: dir, | ||
env: process.env | ||
} | ||
if (!quiet) { | ||
@@ -178,7 +192,4 @@ options.stdio = "inherit"; | ||
if (os.platform() === "win32") { | ||
exec("chcp 65001", process.cwd(), true); | ||
} | ||
exports.createDirectory = createDirectory; | ||
exports.deleteEmptyDir = deleteEmptyDir; | ||
exports.deletePath = deletePath; | ||
@@ -185,0 +196,0 @@ exports.readFile = readFile; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46600
15
1092
10