Skip to content

Commit 8b0c20a

Browse files
committed
simplify
1 parent dafc2bf commit 8b0c20a

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

packages/create/scripts/build-templates.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import parser from 'gitignore-parser';
44
import prettier from 'prettier';
55
import { transform } from 'sucrase';
66
import glob from 'tiny-glob/sync.js';
7+
import { fileURLToPath } from 'node:url';
8+
9+
const pkgRoot = path.resolve(fileURLToPath(import.meta.url), '..', '..');
710

811
/** @param {string} content */
912
async function convert_typescript(content) {
@@ -46,10 +49,9 @@ function strip_jsdoc(content) {
4649
/**
4750
* @param {string} dist
4851
* @param {Set<string>} shared
49-
* @param {string} _cwd
5052
*/
51-
async function generate_templates(dist, shared, _cwd) {
52-
const templates = fs.readdirSync(path.resolve(_cwd, 'templates'));
53+
async function generate_templates(dist, shared) {
54+
const templates = fs.readdirSync(path.resolve(pkgRoot, 'templates'));
5355

5456
for (const template of templates) {
5557
if (template[0] === '.') continue;
@@ -58,7 +60,7 @@ async function generate_templates(dist, shared, _cwd) {
5860
const assets = path.join(dir, 'assets');
5961
mkdirp(assets);
6062

61-
const cwd = path.resolve(_cwd, 'templates', template);
63+
const cwd = path.resolve(pkgRoot, 'templates', template);
6264

6365
const gitignore_file = path.join(cwd, '.gitignore');
6466
if (!fs.existsSync(gitignore_file)) {
@@ -228,10 +230,9 @@ async function replace_async(string, regexp, replacer) {
228230

229231
/**
230232
* @param {string} dist
231-
* @param {string} _cwd
232233
*/
233-
async function generate_shared(dist, _cwd) {
234-
const cwd = path.resolve(_cwd, 'shared');
234+
async function generate_shared(dist) {
235+
const cwd = path.resolve(pkgRoot, 'shared');
235236

236237
/** @type {Set<string>} */
237238
const shared = new Set();
@@ -322,11 +323,10 @@ export function mkdirp(dir) {
322323

323324
/**
324325
* @param {string} dist
325-
* @param {string} cwd
326326
*/
327-
export async function buildTemplates(dist, cwd = process.cwd()) {
327+
export async function buildTemplates(dist) {
328328
mkdirp(dist);
329329

330-
const shared = await generate_shared(dist, cwd);
331-
await generate_templates(dist, shared, cwd);
330+
const shared = await generate_shared(dist);
331+
await generate_templates(dist, shared);
332332
}

rollup.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ function getConfig(project) {
4545
async buildEnd() {
4646
console.log('building templates');
4747
const start = performance.now();
48-
await buildTemplates(
49-
path.resolve('packages', 'core', 'dist'),
50-
path.resolve('packages', 'create')
51-
);
48+
await buildTemplates(path.resolve('packages', 'core', 'dist'));
5249
const end = performance.now();
5350
console.log(`finished building templates: ${Math.round(end - start)}ms`);
5451
}

0 commit comments

Comments
 (0)