@mochabug/adaptkit 0.11.0 → 0.11.2
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/assets/tsconf.json +2 -1
- package/bin/index.js +62 -15
- package/bin/publish.d.ts.map +1 -1
- package/package.json +4 -2
package/assets/tsconf.json
CHANGED
package/bin/index.js
CHANGED
|
@@ -19,7 +19,9 @@ import pkceChallenge from 'pkce-challenge';
|
|
|
19
19
|
import { ChannelCredentials } from '@grpc/grpc-js';
|
|
20
20
|
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
21
21
|
import fg from 'fast-glob';
|
|
22
|
+
import { PassThrough } from 'stream';
|
|
22
23
|
import sharp from 'sharp';
|
|
24
|
+
import archiver from 'archiver';
|
|
23
25
|
import updateNotifier from 'update-notifier';
|
|
24
26
|
|
|
25
27
|
// @generated by protobuf-ts 2.9.4 with parameter client_generic,force_server_none
|
|
@@ -1540,11 +1542,61 @@ function isPathSafe(filePath) {
|
|
|
1540
1542
|
const absoluteFilePath = path.resolve(filePath);
|
|
1541
1543
|
return absoluteFilePath.startsWith(currentWorkingDir);
|
|
1542
1544
|
}
|
|
1545
|
+
function folderExists(folderPath) {
|
|
1546
|
+
try {
|
|
1547
|
+
const absolutePath = path.resolve(folderPath);
|
|
1548
|
+
if (fs.existsSync(absolutePath)) {
|
|
1549
|
+
const stats = fs.statSync(absolutePath);
|
|
1550
|
+
return stats.isDirectory();
|
|
1551
|
+
}
|
|
1552
|
+
else {
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
catch (err) {
|
|
1557
|
+
console.error('Error checking if folder exists:', err);
|
|
1558
|
+
return false;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
function createArchive(folder) {
|
|
1562
|
+
return new Promise((resolve, reject) => {
|
|
1563
|
+
if (!folderExists(folder)) {
|
|
1564
|
+
reject(`The folder ${folder} does not exist`);
|
|
1565
|
+
}
|
|
1566
|
+
const archive = archiver('tar', {
|
|
1567
|
+
gzip: true, // Use gzip compression
|
|
1568
|
+
zlib: { level: 9 } // Sets the compression level.
|
|
1569
|
+
});
|
|
1570
|
+
archive.on('error', (err) => {
|
|
1571
|
+
reject(err);
|
|
1572
|
+
});
|
|
1573
|
+
const buffers = [];
|
|
1574
|
+
const bufferStream = new PassThrough();
|
|
1575
|
+
bufferStream.on('data', (data) => buffers.push(data));
|
|
1576
|
+
bufferStream.on('end', () => {
|
|
1577
|
+
const res = Buffer.concat(buffers);
|
|
1578
|
+
console.log(`${folder} have been compressed successfully into a buffer.`);
|
|
1579
|
+
resolve(res); // Resolve the promise with the final buffer
|
|
1580
|
+
});
|
|
1581
|
+
archive.pipe(bufferStream);
|
|
1582
|
+
fg(path.join(folder, '**', '*'))
|
|
1583
|
+
.then((paths) => {
|
|
1584
|
+
for (let filepath of paths) {
|
|
1585
|
+
if (fs.statSync(filepath).isFile()) {
|
|
1586
|
+
const relativePath = path.relative(folder, filepath);
|
|
1587
|
+
archive.file(filepath, { name: relativePath });
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
archive.finalize();
|
|
1591
|
+
})
|
|
1592
|
+
.catch((err) => reject(err));
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1543
1595
|
async function sendPlugin(manifest, client, metadata) {
|
|
1544
1596
|
console.log('Sending the plugin to the server');
|
|
1545
1597
|
const stream = client.uploadPlugin({ meta: metadata });
|
|
1546
1598
|
const lookup = {};
|
|
1547
|
-
async function send(filePath, imgOpts) {
|
|
1599
|
+
async function send(filePath, imgOpts, fileContent) {
|
|
1548
1600
|
if (!filePath || lookup[filePath]) {
|
|
1549
1601
|
return;
|
|
1550
1602
|
}
|
|
@@ -1552,7 +1604,7 @@ async function sendPlugin(manifest, client, metadata) {
|
|
|
1552
1604
|
throw new Error(`The file path is not safe: ${filePath}. It must be contained inside the manifest folder. Invalid manifest`);
|
|
1553
1605
|
}
|
|
1554
1606
|
if (!fs.existsSync(filePath)) {
|
|
1555
|
-
throw new Error(`The
|
|
1607
|
+
throw new Error(`The path does not exists: ${filePath}. Invalid manifest`);
|
|
1556
1608
|
}
|
|
1557
1609
|
// If image file, we need to compress it
|
|
1558
1610
|
let buffer;
|
|
@@ -1560,6 +1612,9 @@ async function sendPlugin(manifest, client, metadata) {
|
|
|
1560
1612
|
buffer = await resize(filePath, imgOpts[0], imgOpts[1]);
|
|
1561
1613
|
console.log(`Compressed: ${filePath} to ${imgOpts[0]}x${imgOpts[1]} size`);
|
|
1562
1614
|
}
|
|
1615
|
+
else if (fileContent) {
|
|
1616
|
+
buffer = fileContent;
|
|
1617
|
+
}
|
|
1563
1618
|
else {
|
|
1564
1619
|
buffer = fs.readFileSync(filePath);
|
|
1565
1620
|
}
|
|
@@ -1593,21 +1648,13 @@ async function sendPlugin(manifest, client, metadata) {
|
|
|
1593
1648
|
await send(manifest.logo, [80, 80]);
|
|
1594
1649
|
// Send everything inside the asset directory as assets
|
|
1595
1650
|
if (manifest.assets && fs.existsSync(manifest.assets)) {
|
|
1596
|
-
const
|
|
1597
|
-
|
|
1598
|
-
if (fs.statSync(filepath).isFile()) {
|
|
1599
|
-
await send(filepath);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1651
|
+
const assets = await createArchive(manifest.assets);
|
|
1652
|
+
await send(manifest.assets, undefined, assets);
|
|
1602
1653
|
}
|
|
1603
1654
|
// Send everything inside the cdn directory as cdn files
|
|
1604
1655
|
if (manifest.cdn && fs.existsSync(manifest.cdn)) {
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
if (fs.statSync(filepath).isFile()) {
|
|
1608
|
-
await send(filepath);
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1656
|
+
const cdn = await createArchive(manifest.cdn);
|
|
1657
|
+
await send(manifest.cdn, undefined, cdn);
|
|
1611
1658
|
}
|
|
1612
1659
|
// Send everything related to the vertices. Logos, schemas and configs
|
|
1613
1660
|
for (let vertex of manifest.vertices) {
|
|
@@ -1815,7 +1862,7 @@ async function handleEmulate(host, cmd) {
|
|
|
1815
1862
|
}
|
|
1816
1863
|
async function main() {
|
|
1817
1864
|
const notifier = updateNotifier({
|
|
1818
|
-
pkg: JSON.parse('{"name":"@mochabug/adaptkit","version":"0.11.
|
|
1865
|
+
pkg: JSON.parse('{"name":"@mochabug/adaptkit","version":"0.11.2"}')
|
|
1819
1866
|
});
|
|
1820
1867
|
notifier.notify({ isGlobal: true, defer: false });
|
|
1821
1868
|
program
|
package/bin/publish.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,QAAQ,EAET,MAAM,kDAAkD,CAAC;AAiM1D,wBAAsB,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,iBAkB7D;AAED,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,iBA0BlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mochabug/adaptkit",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "A cmd to create, emulate and publish Mochabug Adapt plugins",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@rollup/plugin-replace": "^5.0.7",
|
|
48
48
|
"@rollup/plugin-terser": "^0.4.4",
|
|
49
49
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
50
|
+
"@types/archiver": "^6.0.2",
|
|
50
51
|
"@types/express": "^4.17.21",
|
|
51
52
|
"@types/figlet": "^1.5.8",
|
|
52
53
|
"@types/jest": "^29.5.12",
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"@protobuf-ts/grpc-transport": "^2.9.4",
|
|
67
68
|
"@protobuf-ts/runtime": "^2.9.4",
|
|
68
69
|
"@protobuf-ts/runtime-rpc": "^2.9.4",
|
|
70
|
+
"archiver": "^7.0.1",
|
|
69
71
|
"chalk": "^5.3.0",
|
|
70
72
|
"commander": "^12.1.0",
|
|
71
73
|
"express": "^4.19.2",
|
|
@@ -79,4 +81,4 @@
|
|
|
79
81
|
"sharp": "^0.33.5",
|
|
80
82
|
"update-notifier": "^7.3.0"
|
|
81
83
|
}
|
|
82
|
-
}
|
|
84
|
+
}
|