@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
95 lines (89 loc) • 4.19 kB
JavaScript
import { writeFile } from './chunk-WEZ7ASIP.js';
import { init_esm_shims, __name } from './chunk-QH7NXH7H.js';
import { LogLevelLabel } from '@storm-software/config-tools/types';
import { listFiles } from '@stryke/fs/list-files';
import { resolvePackage } from '@stryke/fs/resolve';
import { joinPaths } from '@stryke/path/join-paths';
import * as Handlebars2 from 'handlebars';
// src/commands/new/index.ts
init_esm_shims();
// src/commands/new/application/index.ts
init_esm_shims();
async function newApplication(context, hooks) {
context.log(LogLevelLabel.TRACE, `Adding a new Storm Stack application project.`);
const packagePath = await resolvePackage("@storm-stack/core");
if (!packagePath) {
throw new Error("Could not resolve the Storm Stack core package. Please ensure it is installed.");
}
const files = await listFiles(joinPaths(packagePath, "files/application/**/*.hbs"));
for (const file of files) {
context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
const template = Handlebars2.compile(file);
await writeFile(context.log, joinPaths(context.options.projectRoot, file.replace(".hbs", "")), template(context));
}
await hooks.callHook("new:application", context).catch((error) => {
context.log(LogLevelLabel.ERROR, `An error occured while creating a new Storm Stack application project: ${error.message}
${error.stack ?? ""}`);
throw new Error("An error occured while creating a new Storm Stack application project", {
cause: error
});
});
}
__name(newApplication, "newApplication");
// src/commands/new/library/index.ts
init_esm_shims();
async function newLibrary(context, hooks) {
context.log(LogLevelLabel.TRACE, `Adding a new Storm Stack library project.`);
const packagePath = await resolvePackage("@storm-stack/core");
if (!packagePath) {
throw new Error("Could not resolve the Storm Stack core package. Please ensure it is installed.");
}
const files = await listFiles(joinPaths(packagePath, "files/library/**/*.hbs"));
for (const file of files) {
context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
const template = Handlebars.compile(file);
await writeFile(context.log, joinPaths(context.options.projectRoot, file.replace(".hbs", "")), template(context));
}
await hooks.callHook("new:library", context).catch((error) => {
context.log(LogLevelLabel.ERROR, `An error occured while creating a new Storm Stack library project: ${error.message}
${error.stack ?? ""}`);
throw new Error("An error occured while creating a new Storm Stack library project", {
cause: error
});
});
}
__name(newLibrary, "newLibrary");
// src/commands/new/index.ts
async function _new(context, hooks) {
await hooks.callHook("new:begin", context).catch((error) => {
context.log(LogLevelLabel.ERROR, `An error occured while starting the new process to add a Storm Stack project: ${error.message}
${error.stack ?? ""}`);
throw new Error("An error occured while starting the new process to add a Storm Stack project", {
cause: error
});
});
const packagePath = await resolvePackage("@storm-stack/core");
if (!packagePath) {
throw new Error("Could not resolve the Storm Stack core package. Please ensure it is installed.");
}
const files = await listFiles(joinPaths(packagePath, "files/common/**/*.hbs"));
for (const file of files) {
context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
const template = Handlebars.compile(file);
await writeFile(context.log, joinPaths(context.options.projectRoot, file.replace(".hbs", "")), template(context));
}
if (context.options.projectType === "application") {
await newApplication(context, hooks);
} else {
await newLibrary(context, hooks);
}
await hooks.callHook("new:complete", context).catch((error) => {
context.log(LogLevelLabel.ERROR, `An error occured while finishing the new process to add a Storm Stack project: ${error.message}
${error.stack ?? ""}`);
throw new Error("An error occured while finishing the new process to add a Storm Stack project", {
cause: error
});
});
}
__name(_new, "_new");
export { _new };