Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate theme #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions generateTheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const readline = require('readline');
const path = require('path');
const replaceInFiles = require('replace-in-file');

function generateTheme() {
//default values of the theme
let fullName = "DevriX Starter";
let shortName = "DX-Starter";
let textDomain = "dxstarter";
let packageName = "DevriX_Starter";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

let recursiveAsyncReadLine = function () {
//textdomain field recursive validation
rl.question('Please enter textDomain (dxstarter) ', function (textDomainInput) {
const pattern = /^[a-z]+$/
if (!textDomainInput.match(pattern)) {
console.log("Invalid textDomain! The textDomain should be only lower case letters")
recursiveAsyncReadLine();
} else {
//user input
rl.question("Please enter theme fullName (DevriX Starter) ", function (fullNameInput) {
rl.question("Please enter theme shortName (DX-Starter) ", function (shortNameInput) {
rl.question("Please enter packageName (DevriX_Starter) ", function (packageNameInput) {
if (fullNameInput !== "") {
fullName = fullNameInput
}
if (shortNameInput !== "") {
shortName = shortNameInput
}
if (textDomainInput !== "") {
textDomain = textDomainInput
}
if (packageNameInput !== "") {
packageName = packageNameInput
}
rl.close();
});
});
});
}
});
};

rl.on("close", function () {
//search and replace options
const options = {
//path to the folders
files: [
path.resolve('./*'),
path.resolve('./assets/dist/css/*'),
path.resolve('./assets/src/sass/base/*'),
path.resolve('./inc/*'),
path.resolve('./template-parts/*'),
path.resolve('./templates/*'),
],

//search expressions
from: [/DevriX Starter/g, /DX-Starter/g, /dxstarter/g, /DevriX_Starter/g],
to: [fullName, shortName, textDomain, packageName],

optionsForFiles: {
"ignore": [
"/node_modules/"
]
}

};

//calling the replace function
replaceInFiles(options).then(results => {
console.log("Remember to add author name and description");
console.log("Generated")
console.log("This script is doing search and replace. Be careful when running second time.")
}).catch(error => {
console.log("Errors occured:", error)
})
});
recursiveAsyncReadLine();
}
generateTheme()

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"gulp": "./node_modules/.bin/gulp",
"ziptheme": "bash zip.sh"
"ziptheme": "bash zip.sh",
"generate": "node ./generateTheme.js"
},
"author": "DevriX",
"license": "ISC",
Expand Down