ppackage 2.2.0 → 2.3.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/bin/askpass ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/node
2
+
3
+ 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;
8
+ if(!response)
9
+ process.exit(1);
10
+ process.stdout.write(response);
11
+
package/bin/ddev ADDED
@@ -0,0 +1 @@
1
+ cnyks ddev --ir://run=$*
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require('fs');
4
+ const path = require('path');
4
5
  const semver = require('semver');
5
6
  const {spawn} = require('child_process');
6
7
 
@@ -12,6 +13,15 @@ const Dockerfile = require('./lib/dockerfile');
12
13
  const {Parser, Composer} = require('yaml');
13
14
 
14
15
 
16
+
17
+ const GIT_FOLDER = ".git";
18
+ const NPM_PACKAGE_PATH = 'package.json';
19
+ const DOCKERIGNORE_PATH = ".dockerignore";
20
+ const NPMIGNORE_PATH = ".npmignore";
21
+ const GITIGNORE_PATH = ".gitignore";
22
+
23
+
24
+
15
25
  const laxParser = function(body) {
16
26
  const tokens = new Parser().parse(body);
17
27
  const docs = new Composer({merge : true, uniqueKeys : false}).compose(tokens);
@@ -64,8 +74,8 @@ class ppackage {
64
74
  this.meta = Dockerfile.parse(body);
65
75
  current_version = this.meta.labels[DOCKER_LABEL_VERSION];
66
76
  },
67
- commit : function(target_version) {
68
- modes.docker.meta.setLabel(DOCKER_LABEL_VERSION, target_version);
77
+ commit : function({target_version, files}) {
78
+ this.meta.setLabel(DOCKER_LABEL_VERSION, target_version);
69
79
  fs.writeFileSync(this.file, this.meta.toString());
70
80
  files.push(this.file);
71
81
  }
@@ -137,6 +147,67 @@ class ppackage {
137
147
  return target_version;
138
148
  }
139
149
 
150
+
151
+ async gitify() {
152
+
153
+ if(fs.existsSync(GIT_FOLDER))
154
+ throw `Cowardly aborting working with existing git project`;
155
+
156
+ await passthru("git", ["config", "--global", "core.askPass", path.join(__dirname, "bin/askpass")]);
157
+ let {repository_url} = await this._find_repo();
158
+
159
+ let cloneargs = ["clone", "--bare", repository_url, GIT_FOLDER];
160
+ await passthru("git", cloneargs);
161
+
162
+ await passthru("git", ["config", "--unset", "core.bare"]);
163
+ await passthru("git", ["reset", "HEAD", "--", "."]);
164
+
165
+ for(let line of [GITIGNORE_PATH, DOCKERIGNORE_PATH, NPMIGNORE_PATH])
166
+ await passthru("git", ["restore", line]).catch(()=>{});
167
+
168
+ let restore = [];
169
+ if(fs.existsSync(DOCKERIGNORE_PATH)) {
170
+ let ignore = fs.readFileSync(DOCKERIGNORE_PATH, 'utf8');
171
+ restore.push(...ignore.split("\n"));
172
+ }
173
+ if(fs.existsSync(NPMIGNORE_PATH)) {
174
+ let ignore = fs.readFileSync(NPMIGNORE_PATH, 'utf8');
175
+ restore.push(...ignore.split("\n"));
176
+ }
177
+ restore = restore.map(v => v.trim()).filter(v => v && v[0] != "#");
178
+
179
+ for(let line of restore)
180
+ await passthru("git", ["restore", line]).catch(()=>{});
181
+ }
182
+
183
+
184
+ // git config --global url."https://git.ivsdev.net/".insteadOf "git@git.ivsdev.net:"
185
+ // yet, this is broader
186
+
187
+ static _git_to_https(repository_url) {
188
+ const SSH_MASK = /^git@/;
189
+ if(!SSH_MASK.test(repository_url))
190
+ return repository_url;
191
+
192
+ return repository_url = repository_url
193
+ .replace(/:/g, "/")
194
+ .replace(SSH_MASK, "https://");
195
+ }
196
+
197
+ async _find_repo() {
198
+ let repository_url;
199
+
200
+ if(fs.existsSync(NPM_PACKAGE_PATH)) {
201
+ let body = JSON.parse(fs.readFileSync(NPM_PACKAGE_PATH));
202
+ if(body.repository && body.repository.type == "git")
203
+ repository_url = body.repository.url;
204
+ }
205
+
206
+ repository_url = ppackage._git_to_https(repository_url);
207
+ return {repository_url};
208
+ }
209
+
210
+
140
211
  }
141
212
 
142
213
 
package/package.json CHANGED
@@ -1,26 +1,34 @@
1
1
  {
2
2
  "name": "ppackage",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "ppackage": "./bin/ppackage"
7
+ "ppackage": "./bin/ppackage",
8
+ "ddev": "./bin/ddev",
9
+ "askpass": "./bin/askpass"
8
10
  },
9
11
  "dependencies": {
12
+ "cnyks": "^3.1.3",
10
13
  "mout": "^1.0.0",
11
14
  "nyks": "^6.1.8",
12
15
  "semver": "^5.3.0",
13
16
  "yaml": "^2.4.2"
14
17
  },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git@github.com:131/ppackage.git"
21
+ },
15
22
  "devDependencies": {
16
23
  "eslint": "^8.57.0",
17
- "eslint-plugin-ivs": "^4.0.0",
24
+ "eslint-plugin-ivs": "^4.0.1",
18
25
  "expect.js": "^0.3.1",
19
26
  "mocha": "^3.1.2",
20
27
  "nyc": "^15.0.1"
21
28
  },
22
29
  "scripts": {
23
- "eslint": "eslint ."
30
+ "eslint": "eslint .",
31
+ "mocha": "node node_modules/mocha/bin/_mocha -b"
24
32
  },
25
33
  "author": "",
26
34
  "license": "ISC"
package/.npmignore DELETED
@@ -1,7 +0,0 @@
1
- /npm-debug.log
2
- /node_modules
3
- /coverage
4
- /test
5
- /disc
6
- /.git*
7
-