Skip to content

Commit fa19d1a

Browse files
committed
Add generate polygon command
1 parent 56060d0 commit fa19d1a

3 files changed

Lines changed: 39 additions & 18 deletions

File tree

bin/index.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { pkg, config, configPath } from '../src/static.js';
77
import { parse } from '../src/parse.js';
88
import { preview } from '../src/preview/index.js';
99
import { render } from '../src/render.js';
10-
import { generateSVG } from '../src/generate-svg.js';
10+
import { generateSVG, generateShape } from '../src/generate.js';
1111

1212
import { Command } from 'commander';
1313

@@ -70,7 +70,7 @@ function handlePreview(source, options) {
7070
}
7171
}
7272

73-
function handleGenerate(source) {
73+
function handleGenerateSVG(source) {
7474
let { content, error } = read(source);
7575
if (error) {
7676
console.log(error.message);
@@ -85,6 +85,16 @@ function handleGenerate(source) {
8585
}
8686
}
8787

88+
function handleGenerateShape(source) {
89+
let { content, error } = read(source);
90+
if (error) {
91+
console.log(error.message);
92+
process.exit(1);
93+
} else {
94+
console.log(generateShape(content));
95+
}
96+
}
97+
8898
function handleSetBrowser(executablePath) {
8999
config.browserPath = executablePath;
90100
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
@@ -121,24 +131,13 @@ program.command('preview')
121131
handlePreview(source, options);
122132
});
123133

124-
program.command('generate')
125-
.description('generate code using CSS Doodle generators')
126-
.action((_, cmd) => {
127-
cmd.help();
128-
})
129-
.command('svg <source>')
130-
.action((source, options, command) => {
131-
handleGenerate(source);
132-
});
133-
134134
program.command('parse')
135135
.description('print the parsed tokens, helped to debug on development')
136136
.argument('<source>', 'source file to parse')
137137
.action((source) => {
138138
handleParse(source);
139139
});
140140

141-
142141
program.command('config')
143142
.description('display/set the configuration')
144143
.action(() => {
@@ -153,6 +152,24 @@ program.command('config')
153152
}
154153
});
155154

155+
const commandGenerate = program.command('generate')
156+
.description('generate code using CSS Doodle generators')
157+
.action((_, cmd) => {
158+
cmd.help();
159+
});
160+
161+
commandGenerate.command('svg <source>')
162+
.description('generate SVG code using svg() function')
163+
.action((source) => {
164+
handleGenerateSVG(source);
165+
})
166+
167+
commandGenerate.command('polygon <source>')
168+
.description('generate CSS polygon() using shape() function')
169+
.action((source) => {
170+
handleGenerateShape(source);
171+
});
172+
156173
if (process.argv.length <= 2) {
157174
program.help();
158175
} else {

src/generate-svg.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/generate.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { svg, shape } from 'css-doodle/generator';
2+
3+
export function generateSVG(...args) {
4+
return svg(...args);
5+
}
6+
7+
export function generateShape(...args) {
8+
return shape(...args);
9+
}

0 commit comments

Comments
 (0)