@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
110 lines (104 loc) • 4.92 kB
JavaScript
;
var chunkEND3JFY3_cjs = require('./chunk-END3JFY3.cjs');
var chunk3ONWID2V_cjs = require('./chunk-3ONWID2V.cjs');
var types = require('@storm-software/config-tools/types');
var listFiles = require('@stryke/fs/list-files');
var joinPaths = require('@stryke/path/join-paths');
var resolve = require('@stryke/path/resolve');
var Handlebars2 = require('handlebars');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var Handlebars2__namespace = /*#__PURE__*/_interopNamespace(Handlebars2);
async function newApplication(context, hooks) {
context.log(types.LogLevelLabel.TRACE, `Adding a new Storm Stack application project.`);
const packagePath = await resolve.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.listFiles(joinPaths.joinPaths(packagePath, "files/application/**/*.hbs"));
for (const file of files) {
context.log(types.LogLevelLabel.TRACE, `Adding template file: ${file}`);
const template = Handlebars2__namespace.compile(file);
await chunkEND3JFY3_cjs.writeFile(context.log, joinPaths.joinPaths(context.options.projectRoot, file.replace(".hbs", "")), template(context));
}
await hooks.callHook("new:application", context).catch((error) => {
context.log(types.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
});
});
}
chunk3ONWID2V_cjs.__name(newApplication, "newApplication");
async function newLibrary(context, hooks) {
context.log(types.LogLevelLabel.TRACE, `Adding a new Storm Stack library project.`);
const packagePath = await resolve.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.listFiles(joinPaths.joinPaths(packagePath, "files/library/**/*.hbs"));
for (const file of files) {
context.log(types.LogLevelLabel.TRACE, `Adding template file: ${file}`);
const template = Handlebars.compile(file);
await chunkEND3JFY3_cjs.writeFile(context.log, joinPaths.joinPaths(context.options.projectRoot, file.replace(".hbs", "")), template(context));
}
await hooks.callHook("new:library", context).catch((error) => {
context.log(types.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
});
});
}
chunk3ONWID2V_cjs.__name(newLibrary, "newLibrary");
// src/commands/new/index.ts
async function _new(context, hooks) {
await hooks.callHook("new:begin", context).catch((error) => {
context.log(types.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 resolve.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.listFiles(joinPaths.joinPaths(packagePath, "files/common/**/*.hbs"));
for (const file of files) {
context.log(types.LogLevelLabel.TRACE, `Adding template file: ${file}`);
const template = Handlebars.compile(file);
await chunkEND3JFY3_cjs.writeFile(context.log, joinPaths.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(types.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
});
});
}
chunk3ONWID2V_cjs.__name(_new, "_new");
exports._new = _new;
//# sourceMappingURL=chunk-HWHNTZRT.cjs.map
//# sourceMappingURL=chunk-HWHNTZRT.cjs.map