Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Makestuff is a tiny tool that allows you to create and execute your own simple scaffolding rules for project. You can automatically create boring boilerplate stuff in your project.
You have an old AngularJS project and you need to create components, modules, routing configs etc, so you need to write a lot of boilerplate code for each file.
Let's try to automate the component generation process!
npm i -g makestuff
makesuff.config.js
with the following content:module.exports = {
commands: [
{
// name of your CLI command
name: "ng-component",
description: "Generates an AngularJS component",
// create a directory for your component
createDirectory: true,
// You can define your own CLI options.
// You can use this options in your rules to create files conditionally
options: {
name: "-s, --styles",
description: "create an empty styles file",
},
// description of output files
output: [
{
templatePath: "./templates/component.ejs",
name: `component.js`
},
{
// you can specify only file name, in this case Makestuff will create the empty file for you
// this is only a small subset of all features, see the detailed description below
name: "_styles.scss",
// use the option created above to create files conditionally
when: (data) => data.command.optionEnabled("styles")
}
]
}
]
};
templates
templates/component.ejs
with the following content:const template = `<b>Hello, world!</b>`;
const dependencies = [];
class <%=name.pascalCase%>Component {
constructor() {
}
$onInit() {
}
$onChanges() {
}
$onDestroy() {
}
}
<%=name.pascalCase%>Component.$inject = dependencies;
<%=name.pascalCase%>Component.controller = <%=name.pascalCase%>Component;
<%=name.pascalCase%>Component.template = template;
export <%=name.pascalCase%>Component;
makestuff ng-component /path/to/your/project/MyFirstTest
if you want to generate only component with template, or type makestuff ng-component /path/to/your/project/MyFirstTest --styles
if you want to generate component with the additional scss file/path/to/your/project/MyFirstTest
and check the result! Open the component.js
and you'll see somenting like this:const template = `<b>Hello, world!</b>`;
const dependencies = [];
class MyFirstTestComponent {
constructor() {
}
$onInit() {
}
$onChanges() {
}
$onDestroy() {
}
}
MyFirstTestComponent.$inject = dependencies;
MyFirstTestComponent.controller = MyFirstTestComponent;
MyFirstTestComponent.template = template;
TBD
// projectRoot/makestuff.js
const componentGenerator = {
name: "component", // name for your command
description: "Generate the component", // description for CLI help
namingConvention: "PascalCase", // by default
createDirectory: true, // by default. Tells the engine to create the folder, name based on naming convention
// Create some extra variables for the command. They will be exposed to the templates inside the object called `custom`
templateVars: function(input, predefinedVars) {
// predefinedVars contains a lot of thigns like name in the different cases etc.
return {
myOwnVar: 123
};
},
// You can define your own CLI options.
// You can use this options in your rules to create files conditionally
options: {
name: "-s, --styles",
description: "create an empty styles file",
},
// Tells the generator where to put the result files
output: [
{
templatePath: "./templates/component.ejs",
// yes, you can use function to generate names.
// In this case you will have access to predefinedVars (fist parameter)
name: data => `${data.dashedName}.component.ts`
},
{
template: "some file content",
name: data => `${data.dashedName}.ts`
},
{
name: data => `${data.dashedName}.html` // just create emplty file
},
{
// you can specify only file name, in this case Makestuff will create the empty file for you
name: "_styles.scss",
when: (data) => data.command.optionEnabled("styles")
}
],
}
module.exports = {
commands: [
componentGenerator
]
};
FAQs
Tiny scaffolding tool for your project
We found that makestuff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.