@stratify/cli 0.1.1 → 0.1.3

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/dist/new.js CHANGED
@@ -27,6 +27,16 @@ async function replaceFileContent(p, replacer) {
27
27
  const s = await fs.readFile(p, "utf8");
28
28
  await fs.writeFile(p, replacer(s), "utf8");
29
29
  }
30
+ async function finalizeGitignore(target) {
31
+ const src = join(target, "_gitignore");
32
+ const dest = join(target, ".gitignore");
33
+ try {
34
+ await fs.rename(src, dest);
35
+ }
36
+ catch {
37
+ // no _gitignore — ignore silently
38
+ }
39
+ }
30
40
  export async function runNew({ appName, templateDir }) {
31
41
  const target = resolve(process.cwd(), appName);
32
42
  if (await pathExists(target)) {
@@ -35,6 +45,7 @@ export async function runNew({ appName, templateDir }) {
35
45
  await copyDir(templateDir, target);
36
46
  const pkgPath = join(target, "package.json");
37
47
  await replaceFileContent(pkgPath, (s) => s.replace(/"name":\s*".+?"/, `"name": "${appName}"`));
48
+ await finalizeGitignore(target);
38
49
  console.log(`\nScaffolded "${appName}" successfully.
39
50
 
40
51
  Next steps:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stratify/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "stratify-cli": "./dist/bin.js"
@@ -0,0 +1,141 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ lerna-debug.log*
8
+
9
+ # Diagnostic reports (https://nodejs.org/api/report.html)
10
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11
+
12
+ # Runtime data
13
+ pids
14
+ *.pid
15
+ *.seed
16
+ *.pid.lock
17
+
18
+ # Directory for instrumented libs generated by jscoverage/JSCover
19
+ lib-cov
20
+
21
+ # Coverage directory used by tools like istanbul
22
+ coverage
23
+ *.lcov
24
+
25
+ # nyc test coverage
26
+ .nyc_output
27
+
28
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29
+ .grunt
30
+
31
+ # Bower dependency directory (https://bower.io/)
32
+ bower_components
33
+
34
+ # node-waf configuration
35
+ .lock-wscript
36
+
37
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
38
+ build/Release
39
+
40
+ # Dependency directories
41
+ node_modules/
42
+ jspm_packages/
43
+
44
+ # Snowpack dependency directory (https://snowpack.dev/)
45
+ web_modules/
46
+
47
+ # TypeScript cache
48
+ *.tsbuildinfo
49
+
50
+ # Optional npm cache directory
51
+ .npm
52
+
53
+ # Optional eslint cache
54
+ .eslintcache
55
+
56
+ # Optional stylelint cache
57
+ .stylelintcache
58
+
59
+ # Optional REPL history
60
+ .node_repl_history
61
+
62
+ # Output of 'npm pack'
63
+ *.tgz
64
+
65
+ # Yarn Integrity file
66
+ .yarn-integrity
67
+
68
+ # dotenv environment variable files
69
+ .env
70
+ .env.*
71
+ !.env.example
72
+
73
+ # parcel-bundler cache (https://parceljs.org/)
74
+ .cache
75
+ .parcel-cache
76
+
77
+ # Next.js build output
78
+ .next
79
+ out
80
+
81
+ # Nuxt.js build / generate output
82
+ .nuxt
83
+ dist
84
+ .output
85
+
86
+ # Gatsby files
87
+ .cache/
88
+ # Comment in the public line in if your project uses Gatsby and not Next.js
89
+ # https://nextjs.org/blog/next-9-1#public-directory-support
90
+ # public
91
+
92
+ # vuepress build output
93
+ .vuepress/dist
94
+
95
+ # vuepress v2.x temp and cache directory
96
+ .temp
97
+ .cache
98
+
99
+ # Sveltekit cache directory
100
+ .svelte-kit/
101
+
102
+ # vitepress build output
103
+ **/.vitepress/dist
104
+
105
+ # vitepress cache directory
106
+ **/.vitepress/cache
107
+
108
+ # Docusaurus cache and generated files
109
+ .docusaurus
110
+
111
+ # Serverless directories
112
+ .serverless/
113
+
114
+ # FuseBox cache
115
+ .fusebox/
116
+
117
+ # DynamoDB Local files
118
+ .dynamodb/
119
+
120
+ # Firebase cache directory
121
+ .firebase/
122
+
123
+ # TernJS port file
124
+ .tern-port
125
+
126
+ # Stores VSCode versions used for testing VSCode extensions
127
+ .vscode-test
128
+
129
+ # yarn v3
130
+ .pnp.*
131
+ .yarn/*
132
+ !.yarn/patches
133
+ !.yarn/plugins
134
+ !.yarn/releases
135
+ !.yarn/sdks
136
+ !.yarn/versions
137
+
138
+ # Vite files
139
+ vite.config.js.timestamp-*
140
+ vite.config.ts.timestamp-*
141
+ .vite/
@@ -4,8 +4,6 @@ import { createAdapter } from "@stratify/core";
4
4
  * Exposes Fastify version for the current instance context.
5
5
  */
6
6
  export const versionAdapter = createAdapter({
7
- name: "version",
8
- expose: ({ fastify }) => ({
9
- version: fastify.version
10
- })
7
+ name: "version", // optional, used by tree printer
8
+ expose: ({ fastify }) => fastify.version
11
9
  });
@@ -1,13 +1,15 @@
1
1
  import { createHooks } from "@stratify/core";
2
+ import { versionAdapter } from "../adapters/version.adapter";
2
3
 
3
4
  export const httpHooks = createHooks({
4
5
  type: "http",
5
- name: "http-core", // optional, used by tree printer
6
- build: async ({ builder }) => {
7
- // Example: add a simple security header for all responses
8
- builder.addHook("onRequest", async (_req, reply) => {
9
- reply.header("x-content-type-options", "nosniff");
6
+ name: "http-core",
7
+ adaps: { version: versionAdapter },
8
+ build: async ({ builder, adaps }) => {
9
+ // Adds headers to every request
10
+ builder.addHook("onSend", async (_req, reply, payload) => {
11
+ reply.header("x-fastify-version", adaps.version);
12
+ return payload;
10
13
  });
11
- // You can add more lifecycle hooks as needed.
12
- }
14
+ },
13
15
  });
@@ -0,0 +1,20 @@
1
+ import { describe, test } from "node:test";
2
+ import assert from "node:assert";
3
+ import { createApp } from "@stratify/core";
4
+ import { tasksModule } from "../src/tasks/tasks.module.js";
5
+
6
+ describe("http hooks", () => {
7
+ test("sets x-fastify-version header on all responses", async () => {
8
+ const app = await createApp({ root: tasksModule });
9
+
10
+ const res = await app.inject({ method: "GET", url: "/tasks" });
11
+ assert.strictEqual(res.statusCode, 200);
12
+
13
+ const versionHeader = res.headers["x-fastify-version"];
14
+ assert.ok(versionHeader, "x-fastify-version header should be set");
15
+
16
+ assert.strictEqual(versionHeader, app.version);
17
+
18
+ await app.close();
19
+ });
20
+ });