Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/unigraph-packager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "unigraph-packager",
"version": "0.2.7-1",
"description": "Unigraph package builder.",
"main": "./unigraph-packager.js",
"bin": {
"unigraph-packager": "./unigraph-packager.js"
},
"dependencies": {
"yargs": "^17.0.1"
},
"devDependencies": {
"typescript": "^4.2.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/unigraph-dev/unigraph-dev.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/unigraph-dev/unigraph-dev/issues"
},
"homepage": "https://github.com/unigraph-dev/unigraph-dev#readme"
}
68 changes: 68 additions & 0 deletions packages/unigraph-packager/unigraph-packager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env node
// Minimal implementation of Unigraph packager - this is subject to change
// This is supposed to be run in a Node environment.
if (!(typeof process !== 'undefined' && process.release.name === 'node')) {
throw new Error("We're not running in node, exiting...");
}

const yargs = require('yargs/yargs');
const path = require('path');
const fs = require('fs');
const { hideBin } = require('yargs/helpers');

const { argv } = yargs(hideBin(process.argv));

const packageDirRoot = path.resolve(argv._[0] || '.');
const outDir = path.resolve(argv.o || '.');

let packageJson;

try {
packageJson = JSON.parse(fs.readFileSync(path.join(packageDirRoot, 'package.json')));
} catch (e) {
throw new Error("package.json malformatted or doesn't exist - check your input commands!");
}

function getFileContent(relative) {
const data = fs.readFileSync(path.join(packageDirRoot, relative));
return data.toString();
}

// End of environment setup

const headerContent = `// Unigraph package declaration
// This file is auto-generated by Unigraph packager.
`;

const schemasDecl = Array.isArray(packageJson.unigraph.schemas) ? packageJson.unigraph.schemas : [];
const executablesDecl = Array.isArray(packageJson.unigraph.executables) ? packageJson.unigraph.executables : [];
const entitiesDecl = Array.isArray(packageJson.unigraph.entities) ? packageJson.unigraph.entities : [];

// TODO: add custom views
const declObject = {
pkgManifest: {
name: packageJson.displayName,
package_name: packageJson.name,
version: packageJson.version,
description: packageJson.description,
},
pkgSchemas: Object.fromEntries(schemasDecl.map((el) => [el.id, JSON.parse(getFileContent(el.src))])),
pkgExecutables: Object.fromEntries(
executablesDecl.map((el) => [
el.id,
{
...el,
id: undefined,
src: getFileContent(el.src),
},
]),
),
pkgEntities: Object.fromEntries(entitiesDecl.map((el) => [el.id, JSON.parse(getFileContent(el.src))])),
};

const finalPackage = `${headerContent}\nconst pkg = ${JSON.stringify(declObject, null, 2)}\n\nexports.pkg = pkg;`;

// console.log(finalPackage)
fs.writeFileSync(path.join(outDir, `${packageJson.name}.pkg.js`), finalPackage);

console.log(`Successfully generated Unigraph package at ${path.join(outDir, `${packageJson.name}.pkg.js`)}`);
84 changes: 0 additions & 84 deletions scripts/unigraph-packager.js

This file was deleted.

1 change: 1 addition & 0 deletions scripts/unigraph-packager.js