Skip to content

Commit

Permalink
feat(sample): config company
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Sep 21, 2024
1 parent ae8aa3d commit 0263798
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Config example:
"extensions": ["js", "ts", "..."],
"ignore": ["dist"],
"title": "示例软件名称",
"version": "v1.0"
"version": "v1.0",
"company": "Cyberdyne Systems Corporation"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sample",
"version": "0.4.19",
"version": "0.4.20",
"description": "Generate code sample files",
"license": "MIT",
"author": {
Expand Down
3 changes: 3 additions & 0 deletions packages/sample/src/lib/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function mergeConfig(group = [{}]) {
{
title = '示例软件名称',
version = 'v1.0',
company = '',
cwd = '.',
pattern = ['**/*'],
patterns = pattern,
Expand All @@ -45,6 +46,7 @@ export function mergeConfig(group = [{}]) {
) => {
checkString(title, `group[${index}].title`);
checkString(version, `group[${index}].version`);
checkString(company, `group[${index}].company`);
checkString(cwd, `group[${index}].cwd`);
checkArray(patterns, `group[${index}].patterns`);
checkArray(prologue, `group[${index}].prologue`);
Expand All @@ -55,6 +57,7 @@ export function mergeConfig(group = [{}]) {
return {
title,
version,
company,
cwd: resolve(process.cwd(), cwd),
patterns,
epilogue,
Expand Down
9 changes: 4 additions & 5 deletions packages/sample/src/lib/sample.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import { scaner } from './scaner.mjs';
import { logger } from './utils.mjs';

export async function action() {
const configs = await readConfig('sample', logger).then(({ group }) =>
mergeConfig(group),
);
const configs = await readConfig('sample', logger) //
.then(({ group }) => mergeConfig(group));

logger.info(configs);

for (const config of configs) {
const files = await scaner(config);
const code = await picker(files, config);

const { title, version } = config;
const { title, version, company } = config;

await pdf(code, { title, version });
await pdf(code, { title, version, company });
logger.task('Generated');
}
}
8 changes: 8 additions & 0 deletions packages/sample/src/lib/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
h3 {
margin-top: 100pt;
}
h4 {
margin-top: 200pt;
}
pre {
display: block;
}
Expand Down Expand Up @@ -57,6 +60,7 @@
<h1></h1>
<h2></h2>
<h3>源代码</h3>
<h4></h4>
</header>
<pre></pre>
</body>
Expand All @@ -71,6 +75,10 @@

header.querySelector('h2').textContent = result.version;

if (result.company) {
header.querySelector('h4').textContent = result.company;
}

document.title = [result.title, result.version].join(' ');

const pre = document.body.querySelector('pre');
Expand Down

0 comments on commit 0263798

Please sign in to comment.