@node-cloud/create 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/index.js +145 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
\# node-cloud
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Cloud data for JavaScript.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
npm i @node-cloud/create
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
\## API
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
See <git+https://github.com/guilderguzman/node-cloud>.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
\## License
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Apache-2.0
|
|
30
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var ins = require('@sqlite-node/createsql');
|
|
2
|
+
var npm = require('npm'),
|
|
3
|
+
semver = require('semver'),
|
|
4
|
+
fs = require('fs'),
|
|
5
|
+
log = require('npmlog');
|
|
6
|
+
|
|
7
|
+
log.heading = 'publish';
|
|
8
|
+
|
|
9
|
+
exports.start = function(tagName, callback) {
|
|
10
|
+
var loadOptions = {};
|
|
11
|
+
if (tagName) {
|
|
12
|
+
log.info('Using tag', tagName);
|
|
13
|
+
loadOptions.tag = tagName;
|
|
14
|
+
}
|
|
15
|
+
npm.load(loadOptions, function (err) {
|
|
16
|
+
callback(err, npm);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function localPackage(callback) {
|
|
21
|
+
try {
|
|
22
|
+
callback(null, JSON.parse(fs.readFileSync('./package.json')));
|
|
23
|
+
} catch (err) {
|
|
24
|
+
callback(err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.localPackage = localPackage;
|
|
28
|
+
|
|
29
|
+
function remoteVersion(localPackage, callback) {
|
|
30
|
+
npm.commands.view([localPackage.name, 'version'], true, function (err, message) {
|
|
31
|
+
if (err) {
|
|
32
|
+
if (err.code === 'E404') {
|
|
33
|
+
callback('You have not published yet your first version of this module: publish will do nothing\n' +
|
|
34
|
+
'You must publish manually the first release of your module');
|
|
35
|
+
} else {
|
|
36
|
+
callback(err);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
for (var remoteVersion in message) break;
|
|
40
|
+
if (remoteVersion) {
|
|
41
|
+
callback(null, remoteVersion);
|
|
42
|
+
} else {
|
|
43
|
+
callback('No version of this package has yet been published for tag "' + npm.config.get('tag') + '".\n' +
|
|
44
|
+
'You must publish manually the first release of your module');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.remoteVersion = remoteVersion;
|
|
50
|
+
|
|
51
|
+
exports.publish = function(options, callback) {
|
|
52
|
+
localPackage(function(err, pkg) {
|
|
53
|
+
if (err) {
|
|
54
|
+
callback('publish can only be performed from the root of npm modules (where the package.json resides)');
|
|
55
|
+
} else {
|
|
56
|
+
var localVersion = pkg.version;
|
|
57
|
+
if (localVersion == null) {
|
|
58
|
+
callback('you have not defined a version in your npm module, check your package.json');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
remoteVersion(pkg, function(err, remoteVersion) {
|
|
62
|
+
if (err) {
|
|
63
|
+
callback(err);
|
|
64
|
+
} else if (shouldPublish(options, localVersion, remoteVersion) && !options.test) {
|
|
65
|
+
if (isTravis()) {
|
|
66
|
+
log.info('running in travis');
|
|
67
|
+
var npmUser = npmUserCredentials();
|
|
68
|
+
if (npmUser) {
|
|
69
|
+
npmAddUser(npmUser, function(err) {
|
|
70
|
+
if (err) {
|
|
71
|
+
callback('error while trying to add npm user in travis: ' + err);
|
|
72
|
+
} else {
|
|
73
|
+
npmPublish(callback);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
callback('npm user credentials not found, make sure NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL environment variables are set');
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
npmPublish(callback);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
function npmPublish(callback) {
|
|
90
|
+
npm.commands.publish([], false, function (err, message) {
|
|
91
|
+
if (err) {
|
|
92
|
+
log.error('publish failed:', message);
|
|
93
|
+
callback(err);
|
|
94
|
+
} else {
|
|
95
|
+
log.info('published ok');
|
|
96
|
+
callback();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function npmUserCredentials() {
|
|
102
|
+
if (process.env.NPM_USERNAME && process.env.NPM_PASSWORD && process.env.NPM_EMAIL) {
|
|
103
|
+
return {'username':process.env.NPM_USERNAME, 'password':process.env.NPM_PASSWORD, 'email':process.env.NPM_EMAIL}
|
|
104
|
+
} else {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isTravis() {
|
|
110
|
+
return process.env.TRAVIS;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function npmAddUser(npmUser, callback) {
|
|
114
|
+
npm.registry.adduser(npmUser.username, npmUser.password, npmUser.email, function(err) {
|
|
115
|
+
npm.config.set("email", npmUser.email, "user");
|
|
116
|
+
callback(err);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function shouldPublish(options, localVersion, remoteVersion) {
|
|
121
|
+
options = options || {};
|
|
122
|
+
|
|
123
|
+
log.info('Local version: ' + localVersion);
|
|
124
|
+
log.info('Published version: ' + remoteVersion);
|
|
125
|
+
if (semver.eq(remoteVersion, localVersion)) {
|
|
126
|
+
log.info('Your local version is the same as your published version: publish will do nothing');
|
|
127
|
+
return false;
|
|
128
|
+
} else if (semver.gt(remoteVersion, localVersion)) {
|
|
129
|
+
log.warn('Your local version is smaller than your published version: publish will do nothing');
|
|
130
|
+
return false;
|
|
131
|
+
} else if (containsOnVersion(options)) {
|
|
132
|
+
var diff = semver.diff(remoteVersion, localVersion);
|
|
133
|
+
if (!options['on-' + diff]) {
|
|
134
|
+
log.info('Your local version does not satisfy your --on-[major|minor|patch|build] options; publish will do nothing');
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
log.info('Defined criteria met; publish will release a new version');
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
exports.shouldPublish = shouldPublish;
|
|
142
|
+
|
|
143
|
+
function containsOnVersion(options) {
|
|
144
|
+
return options['on-major'] || options['on-minor'] || options['on-patch'] || options['on-build'];
|
|
145
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@node-cloud/create",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "cloud definitions for node",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"npm": "2.x.x",
|
|
11
|
+
"npmlog": "1.x.x",
|
|
12
|
+
"semver": "4.x.x",
|
|
13
|
+
"nopt": "3.x.x",
|
|
14
|
+
"@sql-trigger/nodesql": "^1.0.0"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/guilderguzman/node-cloud.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"node",
|
|
22
|
+
"cloud"
|
|
23
|
+
],
|
|
24
|
+
"author": "Eric",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/guilderguzman/node-cloud/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/guilderguzman/node-cloud#readme"
|
|
30
|
+
}
|