Skip to content

Commit 2bbfd78

Browse files
committed
CLI scripts
1 parent bcf8b0d commit 2bbfd78

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

bin.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env node
2+
3+
const args = process.argv.slice(2);
4+
const argv = require('minimist')(args);
5+
6+
var cmd = args[0];
7+
var name = args[1];
8+
var dist = argv.dist;
9+
10+
if(cmd == '--version' || cmd == '--v'){
11+
console.log('Show current version');
12+
}
13+
14+
if(cmd == 'init'){
15+
var newCmd = require('./cli/init.js');
16+
newCmd.init()
17+
}
18+
19+
if(cmd == 'make:theme'){
20+
if(name == undefined){
21+
console.log('Please specify a theme name. Ex: npx webpixels make:theme awesome');
22+
return;
23+
}
24+
25+
if(dist == undefined){
26+
console.log('Please specify the location of you Sass files. Ex: scss/');
27+
return;
28+
}
29+
30+
var newCmd = require('./cli/make.js');
31+
32+
newCmd.makeTheme(name, dist);
33+
34+
return;
35+
}

cli/init.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
init() {
3+
console.log('Scaffolding your styles');
4+
},
5+
}

cli/make.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const path = require('path');
2+
const fs = require('fs-extra');
3+
const replace = require('replace-in-file');
4+
5+
module.exports = {
6+
makeTheme(name = 'starter', dist = 'scss') {
7+
8+
const sourceFolder = 'stubs/theme-starter/';
9+
const destinationFolder = dist+'/themes/';
10+
const replaceString = 'THEME_STARTER';
11+
const themeName = name;
12+
13+
async function copyAndReplace() {
14+
try {
15+
// Copy the 'theme-starter' folder to 'dist'
16+
await fs.copy(sourceFolder+'theme', destinationFolder+themeName);
17+
await fs.copy(sourceFolder+'_theme.scss', destinationFolder+'_'+themeName+'.scss');
18+
19+
// Perform find and replace
20+
const options = {
21+
files: path.join(destinationFolder, '**', '*.*'), // Match all files
22+
from: new RegExp(replaceString, 'g'),
23+
to: themeName,
24+
};
25+
26+
const changes = await replace(options);
27+
console.log(`The ${name} theme has been created and stored in ${destinationFolder}`);
28+
} catch (error) {
29+
console.error('Error:', error);
30+
}
31+
}
32+
33+
copyAndReplace();
34+
}
35+
}

0 commit comments

Comments
 (0)