Zammad addon common updates

This commit is contained in:
Darren Clarke 2023-05-09 12:26:23 +00:00
parent e4450c37ee
commit 6fca9c704f
16 changed files with 192 additions and 107 deletions

View file

@ -0,0 +1,11 @@
import { createZPM } from "./lib";
import { promises as fs } from "fs";
const main = async () => {
const packageJSON = JSON.parse(await fs.readFile("./package.json", "utf-8"));
const { name, version } = packageJSON;
console.log(`Building ${name} v${version}`);
await createZPM({ name, version });
}
main();

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lib_1 = require("./lib");
const fs_1 = require("fs");
const main = async () => {
const packageJSON = JSON.parse(await fs_1.promises.readFile("./package.json", "utf-8"));
const { name, version } = packageJSON;
console.log(`Building ${name} v${version}`);
await (0, lib_1.createZPM)({ name, version });
};
main();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9idWlsZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLCtCQUFrQztBQUNsQywyQkFBb0M7QUFFcEMsTUFBTSxJQUFJLEdBQUcsS0FBSyxJQUFJLEVBQUU7SUFDdEIsTUFBTSxXQUFXLEdBQUcsSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLGFBQUUsQ0FBQyxRQUFRLENBQUMsZ0JBQWdCLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQztJQUM3RSxNQUFNLEVBQUUsSUFBSSxFQUFFLE9BQU8sRUFBRSxHQUFHLFdBQVcsQ0FBQztJQUN0QyxPQUFPLENBQUMsR0FBRyxDQUFDLFlBQVksSUFBSSxLQUFLLE9BQU8sRUFBRSxDQUFDLENBQUM7SUFDNUMsTUFBTSxJQUFBLGVBQVMsRUFBQyxFQUFFLElBQUksRUFBRSxPQUFPLEVBQUUsQ0FBQyxDQUFDO0FBQ3JDLENBQUMsQ0FBQTtBQUVELElBQUksRUFBRSxDQUFDIn0=

View file

@ -0,0 +1,2 @@
export declare const createZPM: ({ name, version }: Record<string, string>) => Promise<void>;
export declare const createMigration: ({ packageName }: Record<string, string>) => Promise<void>;

113
packages/zammad-addon-common/dist/lib.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
export {};

View file

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lib_1 = require("./lib");
const fs_1 = require("fs");
const main = async () => {
const packageJSON = JSON.parse(await fs_1.promises.readFile("./package.json", "utf-8"));
const { name, } = packageJSON;
await (0, lib_1.createMigration)({ packageName: name });
};
main();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlncmF0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL21pZ3JhdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwrQkFBd0M7QUFDeEMsMkJBQW9DO0FBRXBDLE1BQU0sSUFBSSxHQUFHLEtBQUssSUFBSSxFQUFFO0lBQ3RCLE1BQU0sV0FBVyxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUMsTUFBTSxhQUFFLENBQUMsUUFBUSxDQUFDLGdCQUFnQixFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUM7SUFDN0UsTUFBTSxFQUFFLElBQUksR0FBRyxHQUFHLFdBQVcsQ0FBQztJQUM5QixNQUFNLElBQUEscUJBQWUsRUFBQyxFQUFFLFdBQVcsRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDO0FBQy9DLENBQUMsQ0FBQTtBQUVELElBQUksRUFBRSxDQUFDIn0=

File diff suppressed because one or more lines are too long

View file

@ -28,7 +28,7 @@ const skeleton: Record<string, any> = {
const packageFile = async (actualPath: string): Promise<any> => {
console.log(`Packaging: ${actualPath}`);
const packagePath = actualPath.slice(6);
const packagePath = actualPath.slice(4);
const data = await fs.readFile(actualPath, "utf-8");
const content = Buffer.from(data, "utf-8").toString("base64");
const fileStats = await fs.stat(actualPath);
@ -76,19 +76,16 @@ const camelize = (str: string): string => {
return camelizedStr.charAt(0).toUpperCase() + camelizedStr.slice(1);
}
export const createZPM = async () => {
export const createZPM = async ({ name, version }: Record<string, string>) => {
const files = await packageFiles();
skeleton.files = files;
skeleton.builddate = new Date().toISOString();
skeleton.buildhost = os.hostname();
const name = skeleton.name.toLowerCase();
const version = skeleton.version;
const pkg = JSON.stringify(skeleton, null, 2);
await fs.writeFile(`dist/${name}-v${version}.zpm`, pkg, 'utf-8');
await fs.writeFile(`../../docker/zammad/auto_install/${name}-v${version}.zpm`, pkg, 'utf-8');
}
export const createMigration = async () => {
const name = skeleton["name"].toLowerCase();
export const createMigration = async ({ packageName}: Record<string, string>) => {
const rawName: string = await new Promise((resolve) => {
process.stdin.setEncoding("utf-8");
process.stdout.write("Enter migration name: ");
@ -96,7 +93,8 @@ export const createMigration = async () => {
resolve(data.trim());
});
});
const migrationBaseName = `${name}_${underscore(rawName)}`;
const migrationBaseName = `${packageName}_${underscore(rawName)}`;
const migrationName = camelize(migrationBaseName);
const migrationTemplate = `class MIGRATION_NAME < ActiveRecord::Migration[5.2]
def self.up

View file

@ -0,0 +1,10 @@
import { createMigration } from "./lib";
import { promises as fs } from "fs";
const main = async () => {
const packageJSON = JSON.parse(await fs.readFile("./package.json", "utf-8"));
const { name, } = packageJSON;
await createMigration({ packageName: name });
}
main();

View file

@ -2,7 +2,13 @@
"name": "zammad-addon-common",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"zpm-build": "./dist/build.js",
"zpm-migrate": "./dist/migrate.js"
},
"dependencies": {
"ts-node": "^10.9.1"
},
"scripts": {
"build": "tsc"
},