-
Notifications
You must be signed in to change notification settings - Fork 6
/
todo.js
74 lines (59 loc) · 1.65 KB
/
todo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var parse = require('spdx-expression-parse');
var equal = require('deep-equal');
require('spdx-license-ids').forEach(function (id) {
equal(parse(id), {license: id})
});
var correct = require('spdx-correct');
correct('mit');
var valid = require('validate-npm-package-license');
var PJV=require('package-json-validator').PJV;
PJV.validate(data, spec, options);
var pj = "./package.json";
// Takes the JavaScript object and writes it to the package.json file.
var packagejsonTransform = function(next) {
var fs = require("fs-extra");
var packagesrc = require("./src/package.js");
fs.writeJSONFile(pj, packagesrc, function(err){
if (err) {
next(err);
}
else {
next(null);
}
});
};
// validate the packagejson file.
var packagejsonValidate = function(next) {
var PJV = require('package-json-validator').PJV;
var packagejson = require(pj);
var validation = PJV.validate(JSON.stringify(packagejson), "npm", {
warnings: true,
recommendations: true,
});
if (validation.warnings || validation.recommendations) {
next(validation);
}
else {
next();
}
};
var main = function() {
var async = require("async");
async.series([
packagejsonTransform,
packagejsonValidate,
], function(err) {
if (err) {
console.error("Sorry, there was an error or warning:", "\n", err);
}
else {
console.log("package.json written successfully.");
}
});
};
if (require.main === module) {
main();
}
else {
console.error("This module will not do anything if you require() it.");
}