@eik/cli 3.0.0-next.2 → 3.1.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/CHANGELOG.md +152 -9
- package/classes/alias.js +49 -22
- package/classes/index.js +47 -23
- package/classes/integrity.js +27 -16
- package/classes/login.js +21 -7
- package/classes/meta.js +20 -12
- package/classes/ping.js +20 -9
- package/classes/publish/map.js +33 -10
- package/classes/publish/package/index.js +54 -17
- package/classes/publish/package/tasks/check-bundle-sizes.js +7 -11
- package/classes/publish/package/tasks/check-if-already-published.js +8 -11
- package/classes/publish/package/tasks/cleanup.js +7 -9
- package/classes/publish/package/tasks/create-temp-directory.js +5 -9
- package/classes/publish/package/tasks/create-zip-file.js +6 -11
- package/classes/publish/package/tasks/dry-run.js +4 -8
- package/classes/publish/package/tasks/save-metafile.js +5 -7
- package/classes/publish/package/tasks/task.js +3 -5
- package/classes/publish/package/tasks/upload-files.js +16 -17
- package/classes/publish/package/tasks/validate-input.js +4 -8
- package/classes/version.js +38 -21
- package/commands/alias.js +51 -71
- package/commands/index.js +27 -0
- package/commands/init.js +69 -52
- package/commands/integrity.js +15 -32
- package/commands/login.js +23 -35
- package/commands/map-alias.js +95 -0
- package/commands/map.js +90 -0
- package/commands/meta.js +12 -29
- package/commands/npm-alias.js +90 -0
- package/commands/package-alias.js +102 -0
- package/commands/ping.js +11 -21
- package/commands/publish.js +82 -138
- package/commands/version.js +16 -33
- package/formatters/alias.js +8 -14
- package/formatters/artifact.js +8 -8
- package/formatters/file.js +3 -10
- package/formatters/index.js +5 -5
- package/formatters/version.js +5 -12
- package/index.js +53 -12
- package/package.json +49 -52
- package/readme.md +16 -4
- package/types/classes/alias.d.ts +60 -0
- package/types/classes/index.d.ts +37 -0
- package/types/classes/integrity.d.ts +35 -0
- package/types/classes/login.d.ts +25 -0
- package/types/classes/meta.d.ts +28 -0
- package/types/classes/ping.d.ts +23 -0
- package/types/classes/publish/map.d.ts +51 -0
- package/types/classes/publish/package/index.d.ts +94 -0
- package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +4 -0
- package/types/classes/publish/package/tasks/check-if-already-published.d.ts +4 -0
- package/types/classes/publish/package/tasks/cleanup.d.ts +4 -0
- package/types/classes/publish/package/tasks/create-temp-directory.d.ts +4 -0
- package/types/classes/publish/package/tasks/create-zip-file.d.ts +4 -0
- package/types/classes/publish/package/tasks/dry-run.d.ts +7 -0
- package/types/classes/publish/package/tasks/save-metafile.d.ts +4 -0
- package/types/classes/publish/package/tasks/task.d.ts +8 -0
- package/types/classes/publish/package/tasks/upload-files.d.ts +4 -0
- package/types/classes/publish/package/tasks/validate-input.d.ts +4 -0
- package/types/classes/version.d.ts +43 -0
- package/types/utils/hash/compare.d.ts +2 -0
- package/types/utils/hash/file.d.ts +2 -0
- package/types/utils/hash/files.d.ts +2 -0
- package/types/utils/hash/index.d.ts +9 -0
- package/types/utils/http/index.d.ts +12 -0
- package/types/utils/http/integrity.d.ts +2 -0
- package/types/utils/http/latest-version.d.ts +2 -0
- package/types/utils/http/request.d.ts +33 -0
- package/types/utils/http/versions.d.ts +5 -0
- package/types/utils/index.d.ts +6 -0
- package/types/utils/json/index.d.ts +9 -0
- package/types/utils/json/read.d.ts +5 -0
- package/types/utils/json/write-eik.d.ts +5 -0
- package/types/utils/json/write.d.ts +5 -0
- package/types/utils/logger.d.ts +33 -0
- package/types/utils/type-title.d.ts +2 -0
- package/utils/hash/compare.js +1 -3
- package/utils/hash/file.js +3 -5
- package/utils/hash/files.js +4 -6
- package/utils/hash/index.js +4 -4
- package/utils/http/index.js +6 -5
- package/utils/http/integrity.js +2 -5
- package/utils/http/latest-version.js +2 -5
- package/utils/http/request.js +25 -19
- package/utils/http/versions.js +2 -5
- package/utils/index.js +5 -4
- package/utils/json/index.js +4 -4
- package/utils/json/read.js +5 -7
- package/utils/json/write-eik.js +4 -6
- package/utils/json/write.js +4 -6
- package/utils/logger.js +2 -5
- package/utils/type-title.js +1 -1
- package/utils/get-cwd.js +0 -14
- package/utils/type-slug.js +0 -4
package/classes/publish/map.js
CHANGED
@@ -1,13 +1,33 @@
|
|
1
|
-
|
1
|
+
import assert from 'assert';
|
2
|
+
import abslog from 'abslog';
|
3
|
+
import { join, parse, isAbsolute } from 'path';
|
4
|
+
import { existsSync } from 'fs';
|
5
|
+
import { schemas } from '@eik/common';
|
6
|
+
import { request } from '../../utils/http/index.js';
|
2
7
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
/**
|
9
|
+
* @typedef {object} PublishMapOptions
|
10
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
11
|
+
* @property {string} server
|
12
|
+
* @property {string} [cwd]
|
13
|
+
* @property {string} token
|
14
|
+
* @property {string} file
|
15
|
+
* @property {string} name
|
16
|
+
* @property {string} version
|
17
|
+
*/
|
9
18
|
|
10
|
-
|
19
|
+
/**
|
20
|
+
* @typedef {object} PublishMapResult
|
21
|
+
* @property {string} server
|
22
|
+
* @property {string} name
|
23
|
+
* @property {string} version
|
24
|
+
* @property {string} type
|
25
|
+
*/
|
26
|
+
|
27
|
+
export default class PublishMap {
|
28
|
+
/**
|
29
|
+
* @param {PublishMapOptions} options
|
30
|
+
*/
|
11
31
|
constructor({
|
12
32
|
logger,
|
13
33
|
cwd = process.cwd(),
|
@@ -16,7 +36,7 @@ module.exports = class PublishMap {
|
|
16
36
|
file,
|
17
37
|
name,
|
18
38
|
version,
|
19
|
-
}
|
39
|
+
}) {
|
20
40
|
this.log = abslog(logger);
|
21
41
|
this.cwd = cwd;
|
22
42
|
this.server = server;
|
@@ -26,6 +46,9 @@ module.exports = class PublishMap {
|
|
26
46
|
this.file = file;
|
27
47
|
}
|
28
48
|
|
49
|
+
/**
|
50
|
+
* @returns {Promise<PublishMapResult>}
|
51
|
+
*/
|
29
52
|
async run() {
|
30
53
|
this.log.debug('Running import map publish command');
|
31
54
|
|
@@ -93,4 +116,4 @@ module.exports = class PublishMap {
|
|
93
116
|
}
|
94
117
|
}
|
95
118
|
}
|
96
|
-
}
|
119
|
+
}
|
@@ -1,20 +1,52 @@
|
|
1
|
-
|
1
|
+
import abslog from 'abslog';
|
2
|
+
import { join, isAbsolute } from 'path';
|
3
|
+
import { EikConfig } from '@eik/common';
|
4
|
+
import { typeSlug } from '../../../utils/index.js';
|
5
|
+
import ValidateInput from './tasks/validate-input.js';
|
6
|
+
import CreateTempDirectory from './tasks/create-temp-directory.js';
|
7
|
+
import CreateZipFile from './tasks/create-zip-file.js';
|
8
|
+
import CheckBundleSizes from './tasks/check-bundle-sizes.js';
|
9
|
+
import DryRun from './tasks/dry-run.js';
|
10
|
+
import CheckIfAlreadyPublished from './tasks/check-if-already-published.js';
|
11
|
+
import UploadFiles from './tasks/upload-files.js';
|
12
|
+
import SaveMetafile from './tasks/save-metafile.js';
|
13
|
+
import Cleanup from './tasks/cleanup.js';
|
2
14
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
/**
|
16
|
+
* @typedef {object} PublishOptions
|
17
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
18
|
+
* @property {string} [cwd]
|
19
|
+
* @property {string} token
|
20
|
+
* @property {boolean} [dryRun=false]
|
21
|
+
* @property {string} server
|
22
|
+
* @property {"package" | "map" | "npm" | "image"} [type="package"]
|
23
|
+
* @property {string} name
|
24
|
+
* @property {string} [version="1.0.0"]
|
25
|
+
* @property {string[]} [map]
|
26
|
+
* @property {string} [out="./.eik"]
|
27
|
+
* @property {Record<string, string>} files
|
28
|
+
*/
|
16
29
|
|
17
|
-
|
30
|
+
/**
|
31
|
+
* @typedef {object} PublishResult
|
32
|
+
* @property {string} type
|
33
|
+
* @property {string} server
|
34
|
+
* @property {string} name
|
35
|
+
* @property {unknown} level
|
36
|
+
* @property {boolean} dryRun
|
37
|
+
* @property {string} integrity
|
38
|
+
* @property {unknown} created
|
39
|
+
* @property {unknown} author
|
40
|
+
* @property {string} org
|
41
|
+
* @property {string} version
|
42
|
+
* @property {unknown} response
|
43
|
+
* @property {Array<{ pathname: string; type: string; }>} files
|
44
|
+
*/
|
45
|
+
|
46
|
+
export default class Publish {
|
47
|
+
/**
|
48
|
+
* @param {PublishOptions} options
|
49
|
+
*/
|
18
50
|
constructor({
|
19
51
|
logger,
|
20
52
|
cwd = process.cwd(),
|
@@ -27,7 +59,7 @@ module.exports = class Publish {
|
|
27
59
|
map = [],
|
28
60
|
out = './.eik',
|
29
61
|
files = {},
|
30
|
-
}
|
62
|
+
}) {
|
31
63
|
const config = new EikConfig(
|
32
64
|
{
|
33
65
|
server,
|
@@ -84,6 +116,9 @@ module.exports = class Publish {
|
|
84
116
|
});
|
85
117
|
}
|
86
118
|
|
119
|
+
/**
|
120
|
+
* @returns {Promise<PublishResult>}
|
121
|
+
*/
|
87
122
|
async run() {
|
88
123
|
this.log.debug(`Running package command against server`);
|
89
124
|
this.log.debug(` ==> package name: ${this.config.name}`);
|
@@ -102,6 +137,7 @@ module.exports = class Publish {
|
|
102
137
|
type: typeSlug(this.config.type),
|
103
138
|
server: this.config.server,
|
104
139
|
name: this.config.name,
|
140
|
+
// @ts-expect-error Not sure where this.level originated
|
105
141
|
level: this.level,
|
106
142
|
dryRun: this.dryRun,
|
107
143
|
integrity: '',
|
@@ -122,6 +158,7 @@ module.exports = class Publish {
|
|
122
158
|
type: typeSlug(this.config.type),
|
123
159
|
server: this.config.server,
|
124
160
|
name: this.config.name,
|
161
|
+
// @ts-expect-error Not sure where this.level originated
|
125
162
|
level: this.level,
|
126
163
|
dryRun: this.dryRun,
|
127
164
|
created: null,
|
@@ -131,4 +168,4 @@ module.exports = class Publish {
|
|
131
168
|
...response,
|
132
169
|
};
|
133
170
|
}
|
134
|
-
}
|
171
|
+
}
|
@@ -1,13 +1,9 @@
|
|
1
|
-
|
1
|
+
import bytes from 'bytes';
|
2
|
+
import fs from 'fs';
|
3
|
+
import { gzipSizeSync } from 'gzip-size';
|
4
|
+
import Task from './task.js';
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
const bytes = require('bytes');
|
6
|
-
const fs = require('fs');
|
7
|
-
const gzipSize = require('gzip-size');
|
8
|
-
const Task = require('./task');
|
9
|
-
|
10
|
-
module.exports = class CheckBundleSizes extends Task {
|
6
|
+
export default class CheckBundleSizes extends Task {
|
11
7
|
async process() {
|
12
8
|
this.log.debug('Checking bundle file sizes');
|
13
9
|
try {
|
@@ -17,7 +13,7 @@ module.exports = class CheckBundleSizes extends Task {
|
|
17
13
|
` ==> entrypoint size (${
|
18
14
|
mapping.source.destination
|
19
15
|
} => ${file}): ${bytes(
|
20
|
-
|
16
|
+
gzipSizeSync(fs.readFileSync(file, 'utf8')),
|
21
17
|
)}`,
|
22
18
|
);
|
23
19
|
}
|
@@ -25,4 +21,4 @@ module.exports = class CheckBundleSizes extends Task {
|
|
25
21
|
throw new Error(`Failed to check bundle sizes: ${err.message}`);
|
26
22
|
}
|
27
23
|
}
|
28
|
-
}
|
24
|
+
}
|
@@ -1,14 +1,10 @@
|
|
1
|
-
|
1
|
+
import { join } from 'path';
|
2
|
+
import { integrity, versions } from '../../../../utils/http/index.js';
|
3
|
+
import hash from '../../../../utils/hash/index.js';
|
4
|
+
import { typeSlug } from '../../../../utils/index.js';
|
5
|
+
import Task from './task.js';
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
const { join } = require('path');
|
6
|
-
const { typeSlug } = require('@eik/common-utils');
|
7
|
-
const { integrity, versions } = require('../../../../utils/http');
|
8
|
-
const hash = require('../../../../utils/hash');
|
9
|
-
const Task = require('./task');
|
10
|
-
|
11
|
-
module.exports = class CheckIfAlreadyPublished extends Task {
|
7
|
+
export default class CheckIfAlreadyPublished extends Task {
|
12
8
|
async process() {
|
13
9
|
const { log, path } = this;
|
14
10
|
const { server, name, version, files, type } = this.config;
|
@@ -69,6 +65,7 @@ module.exports = class CheckIfAlreadyPublished extends Task {
|
|
69
65
|
);
|
70
66
|
}
|
71
67
|
|
68
|
+
// @ts-expect-error
|
72
69
|
const versionMap = new Map(pkgVersions);
|
73
70
|
for (const v of versionMap.values()) {
|
74
71
|
const same = hash.compare(v.integrity, localHash);
|
@@ -84,4 +81,4 @@ module.exports = class CheckIfAlreadyPublished extends Task {
|
|
84
81
|
|
85
82
|
return localHash;
|
86
83
|
}
|
87
|
-
}
|
84
|
+
}
|
@@ -1,11 +1,9 @@
|
|
1
|
-
|
1
|
+
import { join } from 'path';
|
2
|
+
import fs from 'fs';
|
3
|
+
import { rimrafSync } from 'rimraf';
|
4
|
+
import Task from './task.js';
|
2
5
|
|
3
|
-
|
4
|
-
const fs = require('fs');
|
5
|
-
const rimraf = require('rimraf');
|
6
|
-
const Task = require('./task');
|
7
|
-
|
8
|
-
module.exports = class Cleanup extends Task {
|
6
|
+
export default class Cleanup extends Task {
|
9
7
|
async process() {
|
10
8
|
const { log, path } = this;
|
11
9
|
log.debug('Cleaning up');
|
@@ -13,7 +11,7 @@ module.exports = class Cleanup extends Task {
|
|
13
11
|
if (fs.existsSync(path)) {
|
14
12
|
fs.readdirSync(path)
|
15
13
|
.filter((file) => file !== 'integrity.json')
|
16
|
-
.forEach((file) =>
|
14
|
+
.forEach((file) => rimrafSync(join(path, file)));
|
17
15
|
}
|
18
16
|
}
|
19
|
-
}
|
17
|
+
}
|
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
const mkdir = require('make-dir');
|
6
|
-
const Task = require('./task');
|
1
|
+
import { makeDirectorySync } from 'make-dir';
|
2
|
+
import Task from './task.js';
|
7
3
|
|
8
4
|
class IOError extends Error {
|
9
5
|
constructor(message, err) {
|
@@ -13,7 +9,7 @@ class IOError extends Error {
|
|
13
9
|
}
|
14
10
|
}
|
15
11
|
|
16
|
-
|
12
|
+
export default class CreateTempDir extends Task {
|
17
13
|
async process() {
|
18
14
|
const { log, path } = this;
|
19
15
|
|
@@ -21,9 +17,9 @@ module.exports = class CreateTempDir extends Task {
|
|
21
17
|
log.debug(` ==> ${path}`);
|
22
18
|
|
23
19
|
try {
|
24
|
-
|
20
|
+
makeDirectorySync(path);
|
25
21
|
} catch (err) {
|
26
22
|
throw new IOError('Unable to create temp dir', err);
|
27
23
|
}
|
28
24
|
}
|
29
|
-
}
|
25
|
+
}
|
@@ -1,16 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const fs = require('fs');
|
7
|
-
const { join, resolve, basename, dirname } = require('path');
|
8
|
-
const tar = require('tar');
|
9
|
-
const Task = require('./task');
|
1
|
+
import fs from 'fs';
|
2
|
+
import { join, resolve, basename, dirname } from 'path';
|
3
|
+
import * as tar from 'tar';
|
4
|
+
import Task from './task.js';
|
10
5
|
|
11
6
|
const { copyFileSync, writeFileSync } = fs;
|
12
7
|
|
13
|
-
|
8
|
+
export default class CreateZipFile extends Task {
|
14
9
|
async process() {
|
15
10
|
const { log, path } = this;
|
16
11
|
const { name, map, server, out, files } = this.config;
|
@@ -80,4 +75,4 @@ module.exports = class CreateZipFile extends Task {
|
|
80
75
|
throw new Error(`Unable to create zip file: ${err.message}`);
|
81
76
|
}
|
82
77
|
}
|
83
|
-
}
|
78
|
+
}
|
@@ -1,11 +1,7 @@
|
|
1
|
-
|
1
|
+
import { join } from 'path';
|
2
|
+
import Task from './task.js';
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
const { join } = require('path');
|
6
|
-
const Task = require('./task');
|
7
|
-
|
8
|
-
module.exports = class DryRun extends Task {
|
4
|
+
export default class DryRun extends Task {
|
9
5
|
async process(zipFile) {
|
10
6
|
const { path } = this;
|
11
7
|
|
@@ -23,4 +19,4 @@ module.exports = class DryRun extends Task {
|
|
23
19
|
|
24
20
|
return files;
|
25
21
|
}
|
26
|
-
}
|
22
|
+
}
|
@@ -1,10 +1,8 @@
|
|
1
|
-
|
1
|
+
import { join } from 'path';
|
2
|
+
import json from '../../../../utils/json/index.js';
|
3
|
+
import Task from './task.js';
|
2
4
|
|
3
|
-
|
4
|
-
const json = require('../../../../utils/json');
|
5
|
-
const Task = require('./task');
|
6
|
-
|
7
|
-
module.exports = class SaveMetaFile extends Task {
|
5
|
+
export default class SaveMetaFile extends Task {
|
8
6
|
async process(response) {
|
9
7
|
const { log, cwd } = this;
|
10
8
|
const { out } = this.config;
|
@@ -19,4 +17,4 @@ module.exports = class SaveMetaFile extends Task {
|
|
19
17
|
);
|
20
18
|
}
|
21
19
|
}
|
22
|
-
}
|
20
|
+
}
|
@@ -1,12 +1,10 @@
|
|
1
|
-
|
1
|
+
import abslog from 'abslog';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
module.exports = class Task {
|
3
|
+
export default class Task {
|
6
4
|
constructor(options) {
|
7
5
|
this.cwd = options.cwd;
|
8
6
|
this.log = abslog(options.logger);
|
9
7
|
this.path = options.path;
|
10
8
|
this.config = options.config;
|
11
9
|
}
|
12
|
-
}
|
10
|
+
}
|
@@ -1,13 +1,9 @@
|
|
1
|
-
|
1
|
+
import { join } from 'path';
|
2
|
+
import { request } from '../../../../utils/http/index.js';
|
3
|
+
import { typeSlug } from '../../../../utils/index.js';
|
4
|
+
import Task from './task.js';
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
const { join } = require('path');
|
6
|
-
const { typeSlug } = require('@eik/common-utils');
|
7
|
-
const { request } = require('../../../../utils/http');
|
8
|
-
const Task = require('./task');
|
9
|
-
|
10
|
-
module.exports = class UploadFiles extends Task {
|
6
|
+
export default class UploadFiles extends Task {
|
11
7
|
async process(zipFile) {
|
12
8
|
const { log } = this;
|
13
9
|
const { server, name, version, type, token } = this.config;
|
@@ -30,33 +26,36 @@ module.exports = class UploadFiles extends Task {
|
|
30
26
|
return message;
|
31
27
|
} catch (err) {
|
32
28
|
log.error('Unable to upload zip file to server');
|
33
|
-
|
34
29
|
switch (err.statusCode) {
|
35
30
|
case 400:
|
36
31
|
throw new Error(
|
37
|
-
|
32
|
+
`${err.statusCode}: Client attempted to send an invalid URL parameter`,
|
38
33
|
);
|
39
34
|
case 401:
|
40
|
-
throw new Error(
|
35
|
+
throw new Error(
|
36
|
+
`${err.statusCode}: Client unauthorized with server`,
|
37
|
+
);
|
41
38
|
case 404:
|
42
|
-
throw new Error(
|
39
|
+
throw new Error(
|
40
|
+
`${err.statusCode}: Client could not find server route`,
|
41
|
+
);
|
43
42
|
case 409:
|
44
43
|
throw new Error(
|
45
44
|
`Package with name "${name}" and version "${version}" already exists on server`,
|
46
45
|
);
|
47
46
|
case 415:
|
48
47
|
throw new Error(
|
49
|
-
|
48
|
+
`${err.statusCode}: Client attempted to send an unsupported file format to server`,
|
50
49
|
);
|
51
50
|
case 502:
|
52
51
|
throw new Error(
|
53
|
-
|
52
|
+
`${err.statusCode}: Server was unable to write file to storage, ${err.message}`,
|
54
53
|
);
|
55
54
|
default:
|
56
55
|
throw new Error(
|
57
|
-
|
56
|
+
`${err.statusCode}: Server failed, ${err.message}`,
|
58
57
|
);
|
59
58
|
}
|
60
59
|
}
|
61
60
|
}
|
62
|
-
}
|
61
|
+
}
|
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
const { parse } = require('path');
|
6
|
-
const Task = require('./task');
|
1
|
+
import { parse } from 'path';
|
2
|
+
import Task from './task.js';
|
7
3
|
|
8
4
|
class ValidationError extends Error {
|
9
5
|
constructor(message, err) {
|
@@ -15,7 +11,7 @@ class ValidationError extends Error {
|
|
15
11
|
}
|
16
12
|
}
|
17
13
|
|
18
|
-
|
14
|
+
export default class ValidateInput extends Task {
|
19
15
|
process() {
|
20
16
|
const { log } = this;
|
21
17
|
const { cwd, dryRun } = this.config;
|
@@ -34,4 +30,4 @@ module.exports = class ValidateInput extends Task {
|
|
34
30
|
throw new ValidationError('Parameter "dryRun" is not valid');
|
35
31
|
}
|
36
32
|
}
|
37
|
-
}
|
33
|
+
}
|
package/classes/version.js
CHANGED
@@ -1,21 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
import { copyFileSync, writeFileSync } from 'fs';
|
2
|
+
import { join, isAbsolute, parse } from 'path';
|
3
|
+
import abslog from 'abslog';
|
4
|
+
import semver from 'semver';
|
5
|
+
import { makeDirectorySync } from 'make-dir';
|
6
|
+
import { schemas, EikConfig } from '@eik/common';
|
7
|
+
import { integrity } from '../utils/http/index.js';
|
8
|
+
import hash from '../utils/hash/index.js';
|
9
|
+
import { typeSlug } from '../utils/index.js';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @typedef {object} VersionOptions
|
13
|
+
* @property {import('abslog').AbstractLoggerOptions} [logger]
|
14
|
+
* @property {string} server
|
15
|
+
* @property {"package" | "npm" | "map"} [type="package"]
|
16
|
+
* @property {string} name
|
17
|
+
* @property {string} version
|
18
|
+
* @property {import("semver").ReleaseType} [level="patch"]
|
19
|
+
* @property {string} cwd
|
20
|
+
* @property {string[]} [map]
|
21
|
+
* @property {string} [out="./.eik"]
|
22
|
+
* @property {string | Record<string, string>} files
|
23
|
+
*/
|
24
|
+
|
25
|
+
export default class Version {
|
26
|
+
/**
|
27
|
+
* @param {VersionOptions} options
|
28
|
+
*/
|
19
29
|
constructor({
|
20
30
|
logger,
|
21
31
|
server,
|
@@ -27,7 +37,7 @@ module.exports = class Version {
|
|
27
37
|
map = [],
|
28
38
|
out = './.eik',
|
29
39
|
files,
|
30
|
-
}
|
40
|
+
}) {
|
31
41
|
const config = new EikConfig(
|
32
42
|
{
|
33
43
|
server,
|
@@ -48,6 +58,10 @@ module.exports = class Version {
|
|
48
58
|
this.level = level;
|
49
59
|
}
|
50
60
|
|
61
|
+
/**
|
62
|
+
* Similar to `npm version`, but updates `eik.json`
|
63
|
+
* @returns {Promise<string | null>} The new version number, or null if the versioning failed
|
64
|
+
*/
|
51
65
|
async run() {
|
52
66
|
const { name, server, type, version, cwd, out, files, map } =
|
53
67
|
this.config;
|
@@ -62,6 +76,7 @@ module.exports = class Version {
|
|
62
76
|
|
63
77
|
log.debug(` ==> level: ${level}`);
|
64
78
|
if (!['major', 'minor', 'patch'].includes(level)) {
|
79
|
+
// @ts-expect-error
|
65
80
|
throw new schemas.ValidationError(
|
66
81
|
'Parameter "version" is not valid',
|
67
82
|
);
|
@@ -69,11 +84,13 @@ module.exports = class Version {
|
|
69
84
|
|
70
85
|
log.debug(` ==> files: ${JSON.stringify(files)}`);
|
71
86
|
if (!files) {
|
87
|
+
// @ts-expect-error
|
72
88
|
throw new schemas.ValidationError('Parameter "files" is not valid');
|
73
89
|
}
|
74
90
|
|
75
91
|
log.debug(` ==> map: ${JSON.stringify(map)}`);
|
76
92
|
if (!Array.isArray(map)) {
|
93
|
+
// @ts-expect-error
|
77
94
|
throw new schemas.ValidationError('Parameter "map" is not valid');
|
78
95
|
}
|
79
96
|
|
@@ -106,7 +123,7 @@ module.exports = class Version {
|
|
106
123
|
|
107
124
|
let localHash;
|
108
125
|
try {
|
109
|
-
|
126
|
+
makeDirectorySync(path);
|
110
127
|
const eikPathDest = join(path, './eik.json');
|
111
128
|
const eikJSON = {
|
112
129
|
name,
|
@@ -160,4 +177,4 @@ module.exports = class Version {
|
|
160
177
|
log.debug(` ==> ${newVersion}`);
|
161
178
|
return newVersion;
|
162
179
|
}
|
163
|
-
}
|
180
|
+
}
|