@@ -4,6 +4,9 @@ import parser from 'gitignore-parser';
4
4
import prettier from 'prettier' ;
5
5
import { transform } from 'sucrase' ;
6
6
import glob from 'tiny-glob/sync.js' ;
7
+ import { fileURLToPath } from 'node:url' ;
8
+
9
+ const pkgRoot = path . resolve ( fileURLToPath ( import . meta. url ) , '..' , '..' ) ;
7
10
8
11
/** @param {string } content */
9
12
async function convert_typescript ( content ) {
@@ -46,10 +49,9 @@ function strip_jsdoc(content) {
46
49
/**
47
50
* @param {string } dist
48
51
* @param {Set<string> } shared
49
- * @param {string } _cwd
50
52
*/
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' ) ) ;
53
55
54
56
for ( const template of templates ) {
55
57
if ( template [ 0 ] === '.' ) continue ;
@@ -58,7 +60,7 @@ async function generate_templates(dist, shared, _cwd) {
58
60
const assets = path . join ( dir , 'assets' ) ;
59
61
mkdirp ( assets ) ;
60
62
61
- const cwd = path . resolve ( _cwd , 'templates' , template ) ;
63
+ const cwd = path . resolve ( pkgRoot , 'templates' , template ) ;
62
64
63
65
const gitignore_file = path . join ( cwd , '.gitignore' ) ;
64
66
if ( ! fs . existsSync ( gitignore_file ) ) {
@@ -228,10 +230,9 @@ async function replace_async(string, regexp, replacer) {
228
230
229
231
/**
230
232
* @param {string } dist
231
- * @param {string } _cwd
232
233
*/
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' ) ;
235
236
236
237
/** @type {Set<string> } */
237
238
const shared = new Set ( ) ;
@@ -322,11 +323,10 @@ export function mkdirp(dir) {
322
323
323
324
/**
324
325
* @param {string } dist
325
- * @param {string } cwd
326
326
*/
327
- export async function buildTemplates ( dist , cwd = process . cwd ( ) ) {
327
+ export async function buildTemplates ( dist ) {
328
328
mkdirp ( dist ) ;
329
329
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 ) ;
332
332
}
0 commit comments