test-bdk-cli 0.1.5 → 0.1.6
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/dist/commands/validate.js +53 -28
- package/dist/lib/package.js +19 -0
- package/package.json +2 -3
|
@@ -1,39 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
36
|
exports.registerValidate = registerValidate;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const package_1 = require("../lib/package");
|
|
40
|
+
const appPath_1 = require("../lib/appPath");
|
|
10
41
|
function registerValidate(program) {
|
|
11
42
|
program
|
|
12
|
-
.command('validate')
|
|
43
|
+
.command('validate [appDirectory]')
|
|
44
|
+
.alias('apps:validate')
|
|
13
45
|
.description('Validate app structure and manifest')
|
|
14
|
-
.action(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
46
|
+
.action(async (appDirectory = '.') => {
|
|
47
|
+
try {
|
|
48
|
+
(0, appPath_1.validateAppPath)(appDirectory);
|
|
49
|
+
const appPath = path.resolve(appDirectory);
|
|
50
|
+
// create package (not used by validatePkg here but kept for parity with zcli flow)
|
|
51
|
+
const dummyName = path.basename(appPath) || 'app';
|
|
52
|
+
const pkgPath = await (0, package_1.createAppPkg)(appPath, dummyName).catch(() => null);
|
|
53
|
+
await (0, package_1.validatePkg)(appPath);
|
|
54
|
+
console.log('No validation errors');
|
|
55
|
+
// clean up
|
|
56
|
+
if (pkgPath)
|
|
57
|
+
await fs.promises.rm(pkgPath, { force: true, recursive: true });
|
|
19
58
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!fs_1.default.existsSync(schemaPath)) {
|
|
23
|
-
console.error('Manifest schema not found (schemas/manifest.schema.json).');
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error(err && err.message ? err.message : err);
|
|
24
61
|
process.exit(2);
|
|
25
62
|
}
|
|
26
|
-
const schema = JSON.parse(fs_1.default.readFileSync(schemaPath, 'utf8'));
|
|
27
|
-
const ajv = new ajv_1.default();
|
|
28
|
-
const validate = ajv.compile(schema);
|
|
29
|
-
const valid = validate(manifest);
|
|
30
|
-
if (!valid) {
|
|
31
|
-
console.error('Validation errors:');
|
|
32
|
-
for (const e of (validate.errors || [])) {
|
|
33
|
-
console.error(` - ${e.instancePath || '/'}: ${e.message}`);
|
|
34
|
-
}
|
|
35
|
-
process.exit(2);
|
|
36
|
-
}
|
|
37
|
-
console.log('Manifest validation passed.');
|
|
38
63
|
});
|
|
39
64
|
}
|
package/dist/lib/package.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createAppPkg = createAppPkg;
|
|
7
|
+
exports.validatePkg = validatePkg;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const os_1 = __importDefault(require("os"));
|
|
@@ -22,3 +23,21 @@ async function createAppPkg(targetDir, appName) {
|
|
|
22
23
|
archive.finalize();
|
|
23
24
|
});
|
|
24
25
|
}
|
|
26
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
27
|
+
async function validatePkg(appPath) {
|
|
28
|
+
const manifestPath = path_1.default.join(appPath, 'manifest.json');
|
|
29
|
+
if (!fs_1.default.existsSync(manifestPath))
|
|
30
|
+
throw new Error(`manifest.json not found in ${appPath}`);
|
|
31
|
+
const schemaPath = path_1.default.join(__dirname, '../../schemas/manifest.schema.json');
|
|
32
|
+
if (!fs_1.default.existsSync(schemaPath))
|
|
33
|
+
throw new Error('Manifest schema not found');
|
|
34
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf8'));
|
|
35
|
+
const schema = JSON.parse(fs_1.default.readFileSync(schemaPath, 'utf8'));
|
|
36
|
+
const ajv = new ajv_1.default();
|
|
37
|
+
const validate = ajv.compile(schema);
|
|
38
|
+
const valid = validate(manifest);
|
|
39
|
+
if (!valid) {
|
|
40
|
+
const errs = (validate.errors || []).map((e) => `${(e === null || e === void 0 ? void 0 : e.instancePath) || '/'}: ${e === null || e === void 0 ? void 0 : e.message}`).join('\n');
|
|
41
|
+
throw new Error(`Validation errors:\n${errs}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-bdk-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "test CLI",
|
|
5
5
|
"author": "@raisulaslam",
|
|
6
6
|
"bin": {
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
"commander": "^10.0.0",
|
|
23
23
|
"form-data": "^4.0.0",
|
|
24
24
|
"inquirer": "^9.0.0",
|
|
25
|
-
"node-fetch": "^2.6.7"
|
|
26
|
-
"test-bdk-cli": "^0.1.3"
|
|
25
|
+
"node-fetch": "^2.6.7"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@types/archiver": "^7.0.0",
|