or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli-commands.mdconfiguration.mdindex.mdproject-utilities.md

project-utilities.mddocs/

0

# Project Utilities

1

2

Bunli provides utility functions for project introspection and automated file discovery, helping developers avoid manual configuration where possible.

3

4

## Capabilities

5

6

### Entry Point Discovery

7

8

Automatically detects common CLI entry point files in projects, eliminating the need for manual entry point configuration in most cases.

9

10

```typescript { .api }

11

/**

12

* Auto-detects entry point files for CLI projects

13

* @param cwd - Current working directory to search (defaults to process.cwd())

14

* @returns Promise resolving to detected entry file path or undefined if none found

15

*/

16

function findEntry(cwd?: string): Promise<string | undefined>;

17

```

18

19

**Entry Point Search Order:**

20

21

The function searches for entry files in the following priority order:

22

23

1. `src/cli.ts`

24

2. `src/index.ts`

25

3. `src/main.ts`

26

4. `cli.ts`

27

5. `index.ts`

28

6. `main.ts`

29

7. `src/cli.js`

30

8. `src/index.js`

31

9. `src/main.js`

32

10. `cli.js`

33

11. `index.js`

34

12. `main.js`

35

13. First entry from `package.json` bin field

36

37

**Usage Example:**

38

39

```typescript

40

import { findEntry } from 'bunli';

41

42

// Find entry point in current directory

43

const entry = await findEntry();

44

if (entry) {

45

console.log(`Detected entry point: ${entry}`);

46

} else {

47

console.log('No entry point found, please specify manually');

48

}

49

50

// Find entry point in specific directory

51

const projectEntry = await findEntry('/path/to/project');

52

53

// Use in build scripts or programmatic usage

54

import { defineConfig, findEntry } from 'bunli';

55

56

const entry = await findEntry();

57

58

export default defineConfig({

59

build: {

60

entry: entry || 'src/index.ts', // fallback if not found

61

outdir: 'dist'

62

}

63

});

64

```

65

66

**Package.json Integration:**

67

68

The utility also checks the `bin` field in `package.json` for executable entries:

69

70

```json

71

{

72

"bin": {

73

"my-cli": "./dist/cli.js"

74

}

75

}

76

```

77

78

Or for single binaries:

79

80

```json

81

{

82

"bin": "./dist/cli.js"

83

}

84

```

85

86

**Error Handling:**

87

88

The function gracefully handles missing files and invalid package.json files, returning `undefined` when no suitable entry point is found rather than throwing errors.

89

90

### Version Information

91

92

Access to the current bunli version for programmatic use.

93

94

```typescript { .api }

95

/**

96

* Current bunli version string (currently "0.1.0")

97

*/

98

const version: string;

99

```

100

101

**Usage Example:**

102

103

```typescript

104

import { version } from 'bunli';

105

106

console.log(`Using Bunli v${version}`); // "Using Bunli v0.1.0"

107

```