@@ -4,6 +4,9 @@ import parser from 'gitignore-parser';
44import prettier from 'prettier' ;
55import { transform } from 'sucrase' ;
66import 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 */
912async 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}
0 commit comments