ppackage 2.3.7 → 2.4.1

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.
Files changed (3) hide show
  1. package/bin/askpass +18 -4
  2. package/index.js +145 -72
  3. package/package.json +1 -1
package/bin/askpass CHANGED
@@ -1,11 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const url = require('url');
3
4
  let response, [,, what] = process.argv;
4
- if(/Username/.test(what))
5
- response = process.env.GIT_USER_LOGIN;
6
- if(/Password/.test(what))
7
- response = process.env.GIT_USER_PASSWORD;
5
+
6
+ const question = new RegExp("^(Username|Password) for '(https://.*?)':");
7
+
8
+ if(!question.test(what))
9
+ process.exit(1);
10
+
11
+
12
+ let [, field, repository_url] = question.exec(what);
13
+
14
+ let domain = url.parse(repository_url).hostname;
15
+ let DOMAIN = domain.toUpperCase().replace(/\./g, '_');
16
+
17
+ if(field == "Username")
18
+ response = process.env[`GIT_USER_${DOMAIN}_LOGIN`] || process.env.GIT_USER_LOGIN;
19
+ if(field == "Password")
20
+ response = process.env[`GIT_USER_${DOMAIN}_PASSWORD`] || process.env.GIT_USER_PASSWORD;
8
21
  if(!response)
9
22
  process.exit(1);
23
+
10
24
  process.stdout.write(response);
11
25
 
package/index.js CHANGED
@@ -9,6 +9,8 @@ const args = require('nyks/process/parseArgs')();
9
9
  const passthru = require('nyks/child_process/passthru');
10
10
  const wait = require('nyks/child_process/wait');
11
11
  const trim = require('mout/string/trim');
12
+ const set = require('mout/object/set');
13
+ const drain = require('nyks/stream/drain');
12
14
 
13
15
  const Dockerfile = require('./lib/dockerfile');
14
16
  const {git_to_https} = require('./lib/util');
@@ -23,6 +25,7 @@ const DOCKERIGNORE_PATH = ".dockerignore";
23
25
  const NPMIGNORE_PATH = ".npmignore";
24
26
  const NPMRC_PATH = ".npmrc"; //default ignored by npm
25
27
  const GITIGNORE_PATH = ".gitignore";
28
+ const COMPOSER_PATH = "composer.json";
26
29
 
27
30
 
28
31
 
@@ -33,83 +36,148 @@ const laxParser = function(body) {
33
36
  };
34
37
 
35
38
 
39
+
40
+ const DOCKER_LABEL_VERSION = "org.opencontainers.image.version";
41
+ const DOCKER_LABEL_REPOSITORY = "org.opencontainers.image.source";
42
+
43
+ const GITLAB_PATH_VERSION = ".version";
44
+ const GITLAB_PATH_REPOSITORY = ".repository";
45
+
46
+ let modes = {
47
+ gitlab : {
48
+ file : '.gitlab-ci.yml',
49
+ analyze : function() {
50
+ const body = fs.readFileSync(this.file, 'utf-8');
51
+ this.meta = laxParser(body);
52
+ let version = this.meta.get(GITLAB_PATH_VERSION);
53
+ let repository = this.meta.get(GITLAB_PATH_REPOSITORY);
54
+ return {version, repository};
55
+ },
56
+
57
+ commit : function({version, repository, files}) {
58
+ let opts = {lineWidth : 0};
59
+ if(version)
60
+ this.meta.set(GITLAB_PATH_VERSION, version);
61
+ if(repository)
62
+ this.meta.set(GITLAB_PATH_REPOSITORY, repository);
63
+
64
+ fs.writeFileSync(this.file, this.meta.toString(opts));
65
+ files.push(this.file);
66
+ }
67
+
68
+ },
69
+ composer : {
70
+ file : 'composer.json',
71
+ analyze : function() {
72
+ const body = fs.readFileSync(this.file, 'utf-8');
73
+ this.meta = JSON.parse(body);
74
+ let {version, extra : { repository : { url : repository} } = {repository : {}}} = this.meta;
75
+ return {version, repository};
76
+ },
77
+ commit : function({version, repository, files}) {
78
+ if(version)
79
+ this.meta.version = version;
80
+ if(repository)
81
+ set(this.meta, "extra.repository", {type : "git", url : repository});
82
+
83
+ fs.writeFileSync(this.file, JSON.stringify(this.meta, null, 2));
84
+ files.push(this.file);
85
+ }
86
+ },
87
+ docker : {
88
+ file : 'Dockerfile',
89
+ analyze : function () {
90
+ const body = fs.readFileSync(this.file, 'utf-8');
91
+ this.meta = Dockerfile.parse(body);
92
+ let {DOCKER_LABEL_VERSION : version, DOCKER_LABEL_REPOSITORY : repository} = this.meta.labels;
93
+ return {version, repository};
94
+ },
95
+ commit : function({version, repository, files}) {
96
+ if(version)
97
+ this.meta.setLabel(DOCKER_LABEL_VERSION, version);
98
+ if(repository)
99
+ this.meta.setLabel(DOCKER_LABEL_REPOSITORY, repository);
100
+ fs.writeFileSync(this.file, this.meta.toString());
101
+ files.push(this.file);
102
+ }
103
+ },
104
+
105
+ npm : {
106
+ file : 'package.json',
107
+ analyze : function () {
108
+ const body = fs.readFileSync(this.file, 'utf-8');
109
+ this.meta = JSON.parse(body);
110
+ let {version, repository : { url : repository} = {}} = this.meta;
111
+ return {version, repository};
112
+ },
113
+ commit : function({version, repository, files}) {
114
+ if(version)
115
+ this.meta.version = version;
116
+ if(repository)
117
+ this.meta.repository = {type : "git", url : repository};
118
+
119
+ fs.writeFileSync(this.file, JSON.stringify(this.meta, null, 2));
120
+ files.push(this.file);
121
+ }
122
+
123
+ }
124
+ };
125
+
126
+ for(let [mode_n, mode] of Object.entries(modes)) {
127
+ if(!fs.existsSync(mode.file))
128
+ delete modes[mode_n];
129
+ }
130
+
36
131
  class ppackage {
37
132
 
38
- async version(version = false, notag = false) {
39
- let current_version;
40
133
 
134
+ async repository(repository = false) {
41
135
 
42
- const DOCKER_LABEL_VERSION = "org.opencontainers.image.version";
43
- const GITLAB_PATH_VERSION = ".version";
44
-
45
- let modes = {
46
- gitlab : {
47
- file : '.gitlab-ci.yml',
48
- analyze : function() {
49
- const body = fs.readFileSync(this.file, 'utf-8');
50
- this.meta = laxParser(body);
51
- current_version = this.meta.get(GITLAB_PATH_VERSION);
52
- },
53
- commit : function({target_version, files}) {
54
- let opts = {lineWidth : 0};
55
- this.meta.set(GITLAB_PATH_VERSION, target_version);
56
- fs.writeFileSync(this.file, this.meta.toString(opts));
57
- files.push(this.file);
58
- }
59
-
60
- },
61
- composer : {
62
- file : 'composer.json',
63
- analyze : function() {
64
- const body = fs.readFileSync(this.file, 'utf-8');
65
- this.meta = JSON.parse(body);
66
- current_version = this.meta.version;
67
- },
68
- commit : function({target_version, files}) {
69
- this.meta.version = target_version;
70
- fs.writeFileSync(this.file, JSON.stringify(this.meta, null, 2));
71
- files.push(this.file);
72
- }
73
- },
74
- docker : {
75
- file : 'Dockerfile',
76
- analyze : function () {
77
- const body = fs.readFileSync(this.file, 'utf-8');
78
- this.meta = Dockerfile.parse(body);
79
- current_version = this.meta.labels[DOCKER_LABEL_VERSION];
80
- },
81
- commit : function({target_version, files}) {
82
- this.meta.setLabel(DOCKER_LABEL_VERSION, target_version);
83
- fs.writeFileSync(this.file, this.meta.toString());
84
- files.push(this.file);
85
- }
86
- },
87
-
88
- npm : {
89
- file : 'package.json',
90
- analyze : function () {
91
- const body = fs.readFileSync(this.file, 'utf-8');
92
- this.meta = JSON.parse(body);
93
- current_version = this.meta.version;
94
- },
95
- commit : function({target_version, files}) {
96
- this.meta.version = target_version;
97
- fs.writeFileSync(this.file, JSON.stringify(this.meta, null, 2));
98
- files.push(this.file);
99
- }
136
+ let current_repository;
100
137
 
101
- }
102
- };
138
+ try {
139
+ let child = spawn('git', ['config', '--get', 'remote.origin.url']);
140
+ current_repository = String(await drain(child.stdout)).trim();
141
+ } catch(err) {} //best effort
103
142
 
104
- // prepare modes
105
- for(let [mode_n, mode] of Object.entries(modes)) {
106
- if(!fs.existsSync(mode.file)) {
107
- delete modes[mode_n];
108
- continue;
109
- }
110
- mode.analyze.call(mode);
143
+
144
+ for(let [, mode] of Object.entries(modes)) {
145
+ let line = mode.analyze.call(mode);
146
+ if(line.repository) current_repository = line.repository;
111
147
  }
112
148
 
149
+ let target_repository = repository || args.args.shift() || current_repository;
150
+
151
+ if(!target_repository)
152
+ throw `Invalid repository url`;
153
+
154
+
155
+ let files = [];
156
+ for(let [, mode] of Object.entries(modes))
157
+ mode.commit.call(mode, {files, repository : target_repository});
158
+
159
+ await passthru('git', ['add', ...files]);
160
+ await passthru('git', ['commit', '-m', `Uniform repository declaration`]);
161
+
162
+ return target_repository;
163
+ }
164
+
165
+ async version(version = false, notag = false) {
166
+
167
+ let current_repository, inconsistant_repo = false;
168
+
169
+ let current_version;
170
+ for(let [, mode] of Object.entries(modes)) {
171
+ let line = mode.analyze.call(mode);
172
+ if(line.version) current_version = line.version;
173
+ if(!current_repository)
174
+ current_repository = line.repository;
175
+
176
+ inconsistant_repo |= line.repository != current_repository;
177
+ }
178
+
179
+ if(inconsistant_repo)
180
+ throw `Inconsitant repository detected, use ppackage repository first`;
113
181
 
114
182
 
115
183
  let target_version = version || args.args.shift();
@@ -118,7 +186,6 @@ class ppackage {
118
186
  if(dirty && !notag)
119
187
  throw "Working directory not clean, aborting";
120
188
 
121
-
122
189
  if(!current_version)
123
190
  current_version = "0.0.0";
124
191
 
@@ -136,10 +203,9 @@ class ppackage {
136
203
  }
137
204
  }
138
205
 
139
-
140
206
  let files = [];
141
207
  for(let [, mode] of Object.entries(modes))
142
- mode.commit.call(mode, {target_version, files});
208
+ mode.commit.call(mode, {version : target_version, files});
143
209
 
144
210
  await passthru('git', ['add', ...files]);
145
211
 
@@ -198,6 +264,13 @@ class ppackage {
198
264
  repository_url = body.repository.url;
199
265
  }
200
266
 
267
+ if(fs.existsSync(COMPOSER_PATH)) {
268
+ let body = JSON.parse(fs.readFileSync(COMPOSER_PATH));
269
+ if(body.extra && body.extra.repository && body.extra.repository.type == "git")
270
+ repository_url = body.extra.repository.url;
271
+ }
272
+
273
+
201
274
  repository_url = git_to_https(repository_url);
202
275
  return {repository_url};
203
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ppackage",
3
- "version": "2.3.7",
3
+ "version": "2.4.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {