Addon build working
This commit is contained in:
parent
6fca9c704f
commit
60e590f75c
22 changed files with 141 additions and 475 deletions
|
|
@ -1,11 +1,67 @@
|
|||
import { createZPM } from "./lib";
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
|
||||
const packageFile = async (actualPath: string): Promise<any> => {
|
||||
console.log(`Packaging: ${actualPath}`);
|
||||
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);
|
||||
const permission = parseInt((fileStats.mode & 0o777).toString(8).slice(-3), 10);
|
||||
return {
|
||||
location: packagePath,
|
||||
permission,
|
||||
encode: "base64",
|
||||
content,
|
||||
};
|
||||
}
|
||||
|
||||
const packageFiles = async () => {
|
||||
const packagedFiles: any[] = [];
|
||||
const ignoredPatterns = [/\.gitkeep/, /Gemfile/, /Gemfile.lock/, /\.ruby-version/];
|
||||
|
||||
const processDir = async (dir: string) => {
|
||||
const entries = await fs.readdir(dir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const entryPath = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
await processDir(entryPath);
|
||||
} else if (entry.isFile()) {
|
||||
if (!ignoredPatterns.some((pattern) => pattern.test(entry.name))) {
|
||||
packagedFiles.push(await packageFile(entryPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await processDir("./src/");
|
||||
return packagedFiles;
|
||||
}
|
||||
|
||||
export const createZPM = async ({ name, displayName, version }: Record<string, string>) => {
|
||||
const files = await packageFiles();
|
||||
const skeleton = {
|
||||
name: displayName,
|
||||
version,
|
||||
vendor: "Center for Digital Resilience",
|
||||
license: "AGPL-v3+",
|
||||
url: `https://gitlab.com/digiresilience/link/link-stack/packages/${name}`,
|
||||
buildhost: os.hostname(),
|
||||
builddate: new Date().toISOString(),
|
||||
files
|
||||
}
|
||||
const pkg = JSON.stringify(skeleton, null, 2);
|
||||
await fs.writeFile(`../../docker/zammad/auto_install/${name}-v${version}.zpm`, pkg, 'utf-8');
|
||||
}
|
||||
|
||||
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 });
|
||||
const { name, displayName, version } = packageJSON;
|
||||
console.log(`Building ${displayName} v${version}`);
|
||||
await createZPM({ name, displayName, version });
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
1
packages/zammad-addon-common/dist/build.d.ts
vendored
1
packages/zammad-addon-common/dist/build.d.ts
vendored
|
|
@ -1 +0,0 @@
|
|||
export {};
|
||||
12
packages/zammad-addon-common/dist/build.js
vendored
12
packages/zammad-addon-common/dist/build.js
vendored
|
|
@ -1,12 +0,0 @@
|
|||
"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=
|
||||
2
packages/zammad-addon-common/dist/index.d.ts
vendored
2
packages/zammad-addon-common/dist/index.d.ts
vendored
|
|
@ -1,2 +0,0 @@
|
|||
export declare const createZPM: () => Promise<void>;
|
||||
export declare const createMigration: () => Promise<void>;
|
||||
116
packages/zammad-addon-common/dist/index.js
vendored
116
packages/zammad-addon-common/dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
packages/zammad-addon-common/dist/lib.d.ts
vendored
2
packages/zammad-addon-common/dist/lib.d.ts
vendored
|
|
@ -1,2 +0,0 @@
|
|||
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
113
packages/zammad-addon-common/dist/lib.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1 +0,0 @@
|
|||
export {};
|
||||
11
packages/zammad-addon-common/dist/migrate.js
vendored
11
packages/zammad-addon-common/dist/migrate.js
vendored
|
|
@ -1,11 +0,0 @@
|
|||
"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
|
|
@ -1,115 +0,0 @@
|
|||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
|
||||
const skeleton: Record<string, any> = {
|
||||
"name": "PackageName",
|
||||
"version": "0.1.0",
|
||||
"vendor": "Center for Digital Resilience",
|
||||
"license": "AGPL-v3+",
|
||||
"url": "https://gitlab.com/digiresilience/link/zammad-addon-package-name",
|
||||
"buildhost": "",
|
||||
"builddate": "",
|
||||
"change_log": [
|
||||
{
|
||||
"version": "0.0.1",
|
||||
"date": "2020-02-11",
|
||||
"log": "Some changes"
|
||||
}
|
||||
],
|
||||
"description": [
|
||||
{
|
||||
"language": "en",
|
||||
"text": "Change me"
|
||||
}
|
||||
],
|
||||
"files": []
|
||||
}
|
||||
|
||||
const packageFile = async (actualPath: string): Promise<any> => {
|
||||
console.log(`Packaging: ${actualPath}`);
|
||||
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);
|
||||
const permission = parseInt((fileStats.mode & 0o777).toString(8).slice(-3), 10);
|
||||
return {
|
||||
location: packagePath,
|
||||
permission,
|
||||
encode: "base64",
|
||||
content,
|
||||
};
|
||||
}
|
||||
|
||||
const packageFiles = async () => {
|
||||
const packagedFiles: any[] = [];
|
||||
const ignoredPatterns = [/\.gitkeep/];
|
||||
|
||||
const processDir = async (dir: string) => {
|
||||
const entries = await fs.readdir(dir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const entryPath = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
await processDir(entryPath);
|
||||
} else if (entry.isFile()) {
|
||||
if (!ignoredPatterns.some((pattern) => pattern.test(entry.name))) {
|
||||
packagedFiles.push(await packageFile(entryPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await processDir("./src/");
|
||||
return packagedFiles;
|
||||
}
|
||||
|
||||
const underscore = (str: string) => {
|
||||
return str
|
||||
.replace(/([a-z\d])([A-Z])/g, "$1_$2")
|
||||
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1_$2")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
const camelize = (str: string): string => {
|
||||
const camelizedStr = str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
||||
|
||||
return camelizedStr.charAt(0).toUpperCase() + camelizedStr.slice(1);
|
||||
}
|
||||
|
||||
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 pkg = JSON.stringify(skeleton, null, 2);
|
||||
await fs.writeFile(`../../docker/zammad/auto_install/${name}-v${version}.zpm`, pkg, 'utf-8');
|
||||
}
|
||||
|
||||
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: ");
|
||||
process.stdin.once("data", (data: string) => {
|
||||
resolve(data.trim());
|
||||
});
|
||||
});
|
||||
|
||||
const migrationBaseName = `${packageName}_${underscore(rawName)}`;
|
||||
const migrationName = camelize(migrationBaseName);
|
||||
const migrationTemplate = `class MIGRATION_NAME < ActiveRecord::Migration[5.2]
|
||||
def self.up
|
||||
# add your code here
|
||||
end
|
||||
|
||||
def self.down
|
||||
# add your code here
|
||||
end
|
||||
end`;
|
||||
const contents = migrationTemplate.replace("MIGRATION_NAME", migrationName);
|
||||
const time = new Date().toISOString().replace(/[-:.]/g, "").slice(0, 14);
|
||||
const migrationFileName = `${time}_${migrationBaseName}.rb`;
|
||||
const addonDir = path.join("src", "db", "addon", skeleton["name"]);
|
||||
await fs.mkdir(addonDir, { recursive: true });
|
||||
await fs.writeFile(path.join(addonDir, migrationFileName), contents);
|
||||
}
|
||||
|
||||
|
|
@ -1,10 +1,53 @@
|
|||
import { createMigration } from "./lib";
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
|
||||
const underscore = (str: string) => {
|
||||
return str
|
||||
.replace(/([a-z\d])([A-Z])/g, "$1_$2")
|
||||
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1_$2")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
const camelize = (str: string): string => {
|
||||
const camelizedStr = str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
||||
|
||||
return camelizedStr.charAt(0).toUpperCase() + camelizedStr.slice(1);
|
||||
}
|
||||
|
||||
export const createMigration = async ({ displayName }: Record<string, string>) => {
|
||||
const rawName: string = await new Promise((resolve) => {
|
||||
process.stdin.setEncoding("utf-8");
|
||||
process.stdout.write("Enter migration name: ");
|
||||
process.stdin.once("data", (data: string) => {
|
||||
resolve(data.trim());
|
||||
});
|
||||
});
|
||||
|
||||
const migrationBaseName = `${displayName}_${underscore(rawName)}`;
|
||||
const migrationName = camelize(migrationBaseName);
|
||||
const migrationTemplate = `class MIGRATION_NAME < ActiveRecord::Migration[5.2]
|
||||
def self.up
|
||||
# add your code here
|
||||
end
|
||||
|
||||
def self.down
|
||||
# add your code here
|
||||
end
|
||||
end`;
|
||||
const contents = migrationTemplate.replace("MIGRATION_NAME", migrationName);
|
||||
const time = new Date().toISOString().replace(/[-:.]/g, "").slice(0, 14);
|
||||
const migrationFileName = `${time}_${migrationBaseName}.rb`;
|
||||
const addonDir = path.join("src", "db", "addon", displayName);
|
||||
await fs.mkdir(addonDir, { recursive: true });
|
||||
await fs.writeFile(path.join(addonDir, migrationFileName), contents);
|
||||
}
|
||||
|
||||
const main = async () => {
|
||||
const packageJSON = JSON.parse(await fs.readFile("./package.json", "utf-8"));
|
||||
const { name, } = packageJSON;
|
||||
await createMigration({ packageName: name });
|
||||
const { displayName } = packageJSON;
|
||||
await createMigration({ displayName });
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@
|
|||
"zpm-build": "./dist/build.js",
|
||||
"zpm-migrate": "./dist/migrate.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
const { createZPM } = require("./dist/index.js");
|
||||
|
||||
console.log({ createZPM });
|
||||
15
packages/zammad-addon-hardening/package.json
Normal file
15
packages/zammad-addon-hardening/package.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "zammad-addon-hardening",
|
||||
"displayName": "Hardening",
|
||||
"version": "2.0.0",
|
||||
"description": "A Zammad addon that hardens a Zammad instance according to CDR's needs.",
|
||||
"scripts": {
|
||||
"build": "node ../../node_modules/zammad-addon-common/dist/build.js",
|
||||
"migrate": "node ../../node_modules/zammad-addon-common/dist/migrate.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"zammad-addon-common": "*"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
.PHONY: build prep clean fmt new-migration
|
||||
|
||||
build: prep
|
||||
@./package.py
|
||||
@find dist/ -iname "*szpm"
|
||||
|
||||
prep:
|
||||
@mkdir -p dist
|
||||
|
||||
clean: prep
|
||||
@rm -rf dist/*
|
||||
|
||||
fmt:
|
||||
rufo --simple-exit src
|
||||
|
||||
new-migration:
|
||||
@./new-migration.py
|
||||
|
||||
test:
|
||||
@echo There are no tests
|
||||
15
packages/zammad-addon-metamigo/package.json
Normal file
15
packages/zammad-addon-metamigo/package.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "zammad-addon-metamigo",
|
||||
"displayName": "Metamigo",
|
||||
"version": "2.0.0",
|
||||
"description": "An addon that adds metamigo channels to Zammad.",
|
||||
"scripts": {
|
||||
"build": "node ../../node_modules/zammad-addon-common/dist/build.js",
|
||||
"migrate": "node ../../node_modules/zammad-addon-common/dist/migrate.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"zammad-addon-common": "*"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
"name": "zammad-addon-pgp",
|
||||
"displayName": "PGP Support",
|
||||
"version": "2.0.0",
|
||||
"description": "Adds PGP integration into [Zammad](https://zammad.org) via [Sequoia](https://sequoia-pgp.org).",
|
||||
"scripts": {
|
||||
"build": "zpm-build",
|
||||
"migrate": "zpm-migrate"
|
||||
"build": "node ../../node_modules/zammad-addon-common/dist/build.js",
|
||||
"migrate": "node ../../node_modules/zammad-addon-common/dist/migrate.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"zammad-addon-common": "*"
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
class PGPSupport < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
# return if it's a new setup
|
||||
# return unless Setting.exists?(name: 'system_init_done')
|
||||
|
||||
Setting.create_if_not_exists(
|
||||
title: 'PGP integration',
|
||||
name: 'pgp_integration',
|
||||
area: 'Integration::Switch',
|
||||
description: 'Defines if PGP encryption is enabled or not.',
|
||||
options: {
|
||||
form: [
|
||||
{
|
||||
display: '',
|
||||
null: true,
|
||||
name: 'pgp_integration',
|
||||
tag: 'boolean',
|
||||
options: {
|
||||
true => 'yes',
|
||||
false => 'no'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
state: false,
|
||||
preferences: {
|
||||
prio: 1,
|
||||
authentication: true,
|
||||
permission: ['admin.integration']
|
||||
},
|
||||
frontend: true
|
||||
)
|
||||
Setting.create_if_not_exists(
|
||||
title: 'PGP config',
|
||||
name: 'pgp_config',
|
||||
area: 'Integration::PGP',
|
||||
description: 'Defines the PGP config.',
|
||||
options: {},
|
||||
state: {},
|
||||
preferences: {
|
||||
prio: 2,
|
||||
permission: ['admin.integration']
|
||||
},
|
||||
frontend: true
|
||||
)
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Defines postmaster filter.',
|
||||
name: '0016_postmaster_filter_smime',
|
||||
area: 'Postmaster::PreFilter',
|
||||
description: 'Defines postmaster filter to handle secure mailing.',
|
||||
options: {},
|
||||
state: 'Channel::Filter::SecureMailing',
|
||||
frontend: false
|
||||
)
|
||||
|
||||
create_table :pgp_keypairs do |t|
|
||||
t.string :fingerprint, limit: 250, null: false
|
||||
t.binary :public_key, limit: 10.megabytes, null: false
|
||||
t.binary :private_key, limit: 10.megabytes, null: true
|
||||
t.string :private_key_secret, limit: 500, null: true
|
||||
t.timestamps limit: 3, null: false
|
||||
end
|
||||
add_index :pgp_keypairs, [:fingerprint], unique: true
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue