@manuth/generator-wsc-package
Version:
A Generator for WoltLab Suite Core Packages.
269 lines • 11.2 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { ObjectCollectionEditor } from "@manuth/extended-yo-generator";
import { JSONCConverter, JSONCCreatorMapping, TSConfigFileMapping, TSProjectCodeWorkspaceFolder, TSProjectGeneralCategory, TSProjectPackageFileMapping, TSProjectSettingKey } from "@manuth/generator-ts-project";
import chalk from "chalk";
import path from "upath";
import yosay from "yosay";
import { WoltLabCodeWorkspaceFolder } from "../../Components/WoltLabCodeWorkspaceFolder.js";
import { WoltLabGenerator } from "../../WoltLabGenerator.js";
import { ACPTemplateComponent } from "./Components/ACPTemplateComponent.js";
import { BBCodeComponent } from "./Components/BBCodeComponent.js";
import { CronJobComponent } from "./Components/CronJobComponent.js";
import { EmojiComponent } from "./Components/EmojiComponent.js";
import { ErrorMessageComponent } from "./Components/ErrorMessageComponent.js";
import { EventListenerComponent } from "./Components/EventListenerComponent.js";
import { FileUploadComponent } from "./Components/FileUploadComponent.js";
import { GroupOptionComponent } from "./Components/GroupOptionComponent.js";
import { OptionComponent } from "./Components/OptionComponent.js";
import { PHPScriptComponent } from "./Components/PHPScriptComponent.js";
import { SQLScriptComponent } from "./Components/SQLScriptComponent.js";
import { TemplateComponent } from "./Components/TemplateComponent.js";
import { TemplateListenerComponent } from "./Components/TemplateListenerComponent.js";
import { ThemeInstructionComponent } from "./Components/ThemeInstructionComponent.js";
import { TranslationComponent } from "./Components/TranslationComponent.js";
import { UserOptionComponent } from "./Components/UserOptionComponent.js";
import { EntryPointFileMapping } from "./FileMappings/EntryPointFileMapping.js";
import { WoltLabNodePackageFileMapping } from "./FileMappings/WoltLabNodePackageFileMapping.js";
import { WoltLabPackageFileMapping } from "./FileMappings/WoltLabPackageFileMapping.js";
const { join, normalize } = path;
/**
* Provides the functionality to generate WoltLab-packages.
*
* @template TSettings
* The type of the generator-settings.
*
* @template TOptions
* The type of the generator-options.
*/
export class WoltLabPackageGenerator extends WoltLabGenerator {
/**
* @inheritdoc
*/
get TemplateRoot() {
return "package";
}
/**
* Gets all {@see InstructionComponent `InstructionComponent<TSettings, TOptions, TComponentOptions>`} provided by this generator.
*/
get InstructionComponents() {
return [
new FileUploadComponent(this),
new PHPScriptComponent(this),
new SQLScriptComponent(this),
new CronJobComponent(this),
new TranslationComponent(this),
new ErrorMessageComponent(this),
new OptionComponent(this),
new UserOptionComponent(this),
new GroupOptionComponent(this),
new EmojiComponent(this),
new BBCodeComponent(this),
new TemplateComponent(this),
new ACPTemplateComponent(this),
new ThemeInstructionComponent(this),
new EventListenerComponent(this),
new TemplateListenerComponent(this)
];
}
/**
* Gets a collection containing all {@see InstructionComponent `InstructionComponent<TSettings, TOptions, TComponentOptions>`} provided by this generator.
*/
get InstructionComponentCollection() {
return new ObjectCollectionEditor(this.InstructionComponents);
}
/**
* @inheritdoc
*/
get Components() {
let components = this.InstructionComponentCollection;
return {
Question: super.Components.Question,
Categories: [
...super.Components.Categories,
{
DisplayName: "Globalization",
Components: [
components.Get(TranslationComponent),
components.Get(ErrorMessageComponent)
]
},
{
DisplayName: "Options",
Components: [
components.Get(OptionComponent),
components.Get(UserOptionComponent),
components.Get(GroupOptionComponent)
]
},
{
DisplayName: "Customization",
Components: [
components.Get(EmojiComponent),
components.Get(BBCodeComponent),
components.Get(TemplateComponent),
components.Get(ACPTemplateComponent),
components.Get(ThemeInstructionComponent)
]
},
{
DisplayName: "Events",
Components: [
components.Get(EventListenerComponent),
components.Get(TemplateListenerComponent)
]
}
]
};
}
/**
* @inheritdoc
*/
get BaseComponents() {
let result = super.BaseComponents;
let components = this.InstructionComponentCollection;
result.Categories.Replace(TSProjectGeneralCategory, (category) => {
category.Components.ReplaceObject(TSProjectCodeWorkspaceFolder, (component) => {
return new WoltLabCodeWorkspaceFolder(this, component.Object);
});
category.Components.AddRange([
components.Get(FileUploadComponent),
components.Get(PHPScriptComponent),
components.Get(SQLScriptComponent),
components.Get(CronJobComponent)
]);
return category;
});
return result;
}
/**
* @inheritdoc
*/
get BaseFileMappings() {
let result = super.BaseFileMappings;
result.Remove((fileMapping) => fileMapping.Destination === this.destinationPath(this.SourceRoot, "tests", TSConfigFileMapping.FileName));
result.Remove((fileMapping) => fileMapping.Destination === this.destinationPath(".mocharc.jsonc"));
result.Replace(TSProjectPackageFileMapping, new WoltLabNodePackageFileMapping(this));
result.ReplaceObject((fileMapping) => fileMapping.Destination === this.destinationPath(TSConfigFileMapping.GetFileName("build")), (fileMapping) => {
return {
Source: fileMapping.Source,
Destination: fileMapping.Destination,
Processor: (target, generator) => __awaiter(this, void 0, void 0, function* () {
yield fileMapping.Processor();
let tsConfig = new JSONCConverter().Parse(generator.fs.read(target.Destination));
tsConfig.references = tsConfig.references.filter((reference) => {
return !normalize(reference.path).startsWith(join("src", "tests", "."));
});
return new JSONCCreatorMapping(generator, target.Destination, tsConfig).Processor();
})
};
});
result.ReplaceObject((fileMapping) => fileMapping.Destination === this.destinationPath(TSConfigFileMapping.GetFileName("app")), (fileMapping) => {
return {
Source: fileMapping.Source,
Destination: fileMapping.Destination,
Processor: (target, generator) => __awaiter(this, void 0, void 0, function* () {
yield fileMapping.Processor();
let tsConfig = new JSONCConverter().Parse(generator.fs.read(target.Destination));
delete tsConfig.compilerOptions.outDir;
delete tsConfig.exclude;
tsConfig.compilerOptions.noEmit = true;
return new JSONCCreatorMapping(generator, target.Destination, tsConfig).Processor();
})
};
});
return result;
}
/**
* Gets the file-mapping for the woltlab-package.
*/
get WoltLabPackageFileMapping() {
return new WoltLabPackageFileMapping(this);
}
/**
* Gets the file-mapping for the entry-point file.
*/
get EntryPointFileMapping() {
return new EntryPointFileMapping(this);
}
/**
* @inheritdoc
*/
get FileMappings() {
return [
...super.FileMappings,
this.WoltLabPackageFileMapping,
this.EntryPointFileMapping,
{
Source: "README.md",
Context: () => ({
Name: this.Settings[TSProjectSettingKey.DisplayName],
Description: this.Settings[TSProjectSettingKey.Description]
}),
Destination: "README.md"
},
{
Source: "wsc-package-quickstart.md",
Destination: "wsc-package-quickstart.md"
}
];
}
/**
* @inheritdoc
*/
prompting() {
this.log(yosay(`Welcome to the ${chalk.whiteBright("WoltLab Suite Core Package")} generator!`));
return super.prompting();
}
/**
* @inheritdoc
*/
writing() {
const _super = Object.create(null, {
writing: { get: () => super.writing }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.writing.call(this);
});
}
/**
* @inheritdoc
*/
install() {
const _super = Object.create(null, {
install: { get: () => super.install }
});
return __awaiter(this, void 0, void 0, function* () {
return _super.install.call(this);
});
}
/**
* @inheritdoc
*/
cleanup() {
return __awaiter(this, void 0, void 0, function* () {
return this.Base.cleanup();
});
}
/**
* @inheritdoc
*/
end() {
const _super = Object.create(null, {
end: { get: () => super.end }
});
return __awaiter(this, void 0, void 0, function* () {
yield _super.end.call(this);
this.log();
this.log("Open `wsc-package-quickstart.md` inside the new package for further instructions on how to build it.");
});
}
}
//# sourceMappingURL=WoltLabPackageGenerator.js.map