@ttsc/banner 0.7.2 → 0.8.0-dev.20260505

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![Guide Documents](https://img.shields.io/badge/Guide-Documents-forestgreen)](https://github.com/samchon/ttsc/tree/master/docs)
10
10
  [![Discord Badge](https://img.shields.io/badge/discord-samchon-d91965?style=flat&labelColor=5866f2&logo=discord&logoColor=white&link=https://discord.gg/E94XhzrUCZ)](https://discord.gg/E94XhzrUCZ)
11
11
 
12
- `@ttsc/banner` prepends a fixed comment to emitted JavaScript and declaration files.
12
+ `@ttsc/banner` adds a fixed `@packageDocumentation` JSDoc banner to JavaScript and declaration emit.
13
13
 
14
14
  ## Setup
15
15
 
@@ -27,7 +27,7 @@ Open your project's `tsconfig.json`, then add this entry under `compilerOptions.
27
27
  "plugins": [
28
28
  {
29
29
  "transform": "@ttsc/banner",
30
- "banner": "/*! @license MIT (c) 2026 Acme */"
30
+ "banner": "License MIT (c) 2026 Acme"
31
31
  }
32
32
  ]
33
33
  }
@@ -40,7 +40,7 @@ Run your normal `ttsc` command:
40
40
  npx ttsc
41
41
  ```
42
42
 
43
- The banner is written to emitted `.js`, `.mjs`, `.cjs`, `.d.ts`, `.d.mts`, and `.d.cts` files. Source maps and build-info files are left unchanged.
43
+ The plugin formats every banner line inside a compiler-owned JSDoc block and adds `@packageDocumentation`. The banner follows TypeScript's normal comment emit policy, so `removeComments: true` removes it.
44
44
 
45
45
  ## Notes
46
46
 
@@ -53,8 +53,8 @@ The banner is written to emitted `.js`, `.mjs`, `.cjs`, `.d.ts`, `.d.mts`, and `
53
53
  // Keep lint first.
54
54
  { "transform": "@ttsc/lint", "config": { "no-var": "error" } },
55
55
 
56
- // Output plugins run after emit, in order.
57
- { "transform": "@ttsc/banner", "banner": "/*! @license MIT */" },
56
+ // First-party utilities use their documented source/emit hook order.
57
+ { "transform": "@ttsc/banner", "banner": "License MIT" },
58
58
  { "transform": "@ttsc/paths" },
59
59
  { "transform": "@ttsc/strip", "calls": ["console.log"] }
60
60
  ]
package/go.mod CHANGED
@@ -1,3 +1,5 @@
1
1
  module github.com/samchon/ttsc/packages/banner
2
2
 
3
3
  go 1.26
4
+
5
+ require github.com/samchon/ttsc/packages/ttsc v0.0.0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ttsc/banner",
3
- "version": "0.7.2",
4
- "description": "First-party ttsc plugin that prepends a banner comment to emitted files.",
3
+ "version": "0.8.0-dev.20260505",
4
+ "description": "First-party ttsc plugin that adds package-documentation JSDoc banners during emit.",
5
5
  "main": "src/index.cjs",
6
6
  "exports": {
7
7
  ".": "./src/index.cjs",
package/plugin/banner.go CHANGED
@@ -1,134 +1,3 @@
1
1
  package main
2
2
 
3
- import (
4
- "encoding/json"
5
- "flag"
6
- "fmt"
7
- "os"
8
- "path/filepath"
9
- "strings"
10
- )
11
-
12
- type pluginEntry struct {
13
- Config map[string]any `json:"config"`
14
- Name string `json:"name"`
15
- Stage string `json:"stage"`
16
- }
17
-
18
- func RunOutput(args []string) int {
19
- fs := flag.NewFlagSet("output", flag.ContinueOnError)
20
- fs.SetOutput(os.Stderr)
21
- file := fs.String("file", "", "emitted file to transform")
22
- out := fs.String("out", "", "write transformed text to this file instead of updating --file")
23
- _ = fs.String("cwd", "", "project directory")
24
- _ = fs.String("outDir", "", "emit directory override")
25
- pluginsJSON := fs.String("plugins-json", "", "ttsc plugin manifest JSON")
26
- _ = fs.String("tsconfig", "tsconfig.json", "project tsconfig")
27
- if err := fs.Parse(args); err != nil {
28
- return 2
29
- }
30
- if *file == "" {
31
- fmt.Fprintln(os.Stderr, "@ttsc/banner: output requires --file")
32
- return 2
33
- }
34
- config, err := findConfig(*pluginsJSON)
35
- if err != nil {
36
- fmt.Fprintln(os.Stderr, err)
37
- return 2
38
- }
39
- text, err := os.ReadFile(*file)
40
- if err != nil {
41
- fmt.Fprintf(os.Stderr, "@ttsc/banner: read %s: %v\n", *file, err)
42
- return 2
43
- }
44
- patched, err := Apply(*file, string(text), config)
45
- if err != nil {
46
- fmt.Fprintln(os.Stderr, err)
47
- return 2
48
- }
49
- target := *file
50
- if *out != "" {
51
- target = *out
52
- }
53
- if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil {
54
- fmt.Fprintf(os.Stderr, "@ttsc/banner: mkdir: %v\n", err)
55
- return 2
56
- }
57
- if err := os.WriteFile(target, []byte(patched), 0o644); err != nil {
58
- fmt.Fprintf(os.Stderr, "@ttsc/banner: write %s: %v\n", target, err)
59
- return 2
60
- }
61
- return 0
62
- }
63
-
64
- func Apply(fileName string, text string, config map[string]any) (string, error) {
65
- if !isBannerableOutput(fileName) {
66
- return text, nil
67
- }
68
- banner, err := parseBanner(config)
69
- if err != nil {
70
- return "", err
71
- }
72
- if strings.HasPrefix(text, banner) {
73
- return text, nil
74
- }
75
- return banner + text, nil
76
- }
77
-
78
- func parseBanner(config map[string]any) (string, error) {
79
- raw, ok := config["banner"]
80
- if !ok {
81
- return "", fmt.Errorf("@ttsc/banner: \"banner\" must be a non-empty string")
82
- }
83
- text, ok := raw.(string)
84
- if !ok || strings.TrimSpace(text) == "" {
85
- return "", fmt.Errorf("@ttsc/banner: \"banner\" must be a non-empty string")
86
- }
87
- if !strings.HasSuffix(text, "\n") {
88
- text += "\n"
89
- }
90
- return text, nil
91
- }
92
-
93
- func findConfig(pluginsJSON string) (map[string]any, error) {
94
- if strings.TrimSpace(pluginsJSON) == "" {
95
- return nil, fmt.Errorf("@ttsc/banner: missing --plugins-json")
96
- }
97
- var entries []pluginEntry
98
- if err := json.Unmarshal([]byte(pluginsJSON), &entries); err != nil {
99
- return nil, fmt.Errorf("@ttsc/banner: invalid --plugins-json: %w", err)
100
- }
101
- for _, entry := range entries {
102
- if entry.Name == "@ttsc/banner" {
103
- if entry.Config == nil {
104
- return map[string]any{}, nil
105
- }
106
- return entry.Config, nil
107
- }
108
- }
109
- return nil, fmt.Errorf("@ttsc/banner: plugin entry not found")
110
- }
111
-
112
- func isBannerableOutput(fileName string) bool {
113
- lower := strings.ToLower(fileName)
114
- if strings.HasSuffix(lower, ".map") || strings.HasSuffix(lower, ".tsbuildinfo") {
115
- return false
116
- }
117
- return isJavaScriptOutput(fileName) || isDeclarationOutput(fileName)
118
- }
119
-
120
- func isJavaScriptOutput(fileName string) bool {
121
- switch strings.ToLower(filepath.Ext(fileName)) {
122
- case ".js", ".mjs", ".cjs":
123
- return true
124
- default:
125
- return false
126
- }
127
- }
128
-
129
- func isDeclarationOutput(fileName string) bool {
130
- lower := strings.ToLower(fileName)
131
- return strings.HasSuffix(lower, ".d.ts") ||
132
- strings.HasSuffix(lower, ".d.mts") ||
133
- strings.HasSuffix(lower, ".d.cts")
134
- }
3
+ // Banner transform logic lives in github.com/samchon/ttsc/packages/ttsc/utility.
package/plugin/main.go CHANGED
@@ -1,31 +1,36 @@
1
+ // Native sidecar entrypoint for `@ttsc/banner`.
1
2
  package main
2
3
 
3
4
  import (
4
- "fmt"
5
- "os"
5
+ "fmt"
6
+ "os"
7
+
8
+ "github.com/samchon/ttsc/packages/ttsc/utility"
6
9
  )
7
10
 
8
11
  const version = "0.0.1"
9
12
 
10
13
  func main() {
11
- os.Exit(run(os.Args[1:]))
14
+ os.Exit(run(os.Args[1:]))
12
15
  }
13
16
 
14
17
  func run(args []string) int {
15
- if len(args) == 0 {
16
- fmt.Fprintln(os.Stderr, "@ttsc/banner: command required (expected output|version)")
17
- return 2
18
- }
19
- switch args[0] {
20
- case "-v", "--version", "version":
21
- fmt.Fprintf(os.Stdout, "@ttsc/banner %s\n", version)
22
- return 0
23
- case "check":
24
- return 0
25
- case "output":
26
- return RunOutput(args[1:])
27
- default:
28
- fmt.Fprintf(os.Stderr, "@ttsc/banner: unknown command %q\n", args[0])
29
- return 2
30
- }
18
+ if len(args) == 0 {
19
+ fmt.Fprintln(os.Stderr, "@ttsc/banner: command required (expected build|transform|check|version)")
20
+ return 2
21
+ }
22
+ switch args[0] {
23
+ case "-v", "--version", "version":
24
+ fmt.Fprintf(os.Stdout, "@ttsc/banner %s\n", version)
25
+ return 0
26
+ case "build":
27
+ return utility.RunBuild(args[1:])
28
+ case "transform":
29
+ return utility.RunTransform(args[1:])
30
+ case "check":
31
+ return 0
32
+ default:
33
+ fmt.Fprintf(os.Stderr, "@ttsc/banner: unknown command %q\n", args[0])
34
+ return 2
35
+ }
31
36
  }
package/src/index.cjs CHANGED
@@ -7,6 +7,10 @@ module.exports = function createTtscBanner() {
7
7
  return {
8
8
  name: "@ttsc/banner",
9
9
  source: path.resolve(__dirname, "..", "plugin"),
10
- stage: "output",
10
+ stage: "transform",
11
+ hooks: {
12
+ source: true,
13
+ declaration: true,
14
+ },
11
15
  };
12
16
  };