@stack-dev/cli 0.1.6 → 0.2.0
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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +14 -0
- package/dist/index.js +1105 -743
- package/dist/index.mjs +1103 -741
- package/package.json +5 -5
- package/src/index.ts +11 -10
- package/src/packages/cli-app/create-cli-app.ts +74 -0
- package/src/packages/cli-app/files/eslint-config-file-generator.ts +11 -0
- package/src/packages/cli-app/files/index-file-generator.ts +24 -0
- package/src/packages/cli-app/files/prettier-config-file-generator.ts +11 -0
- package/src/packages/cli-app/files/tsconfig-file-generator.ts +15 -0
- package/src/packages/cli-app/files/tsup-file-generator.ts +20 -0
- package/src/packages/cli-app/files/vitest-config-file-generator.ts +19 -0
- package/src/packages/cli-app/index.ts +1 -0
- package/src/packages/fastify-app/create-fastify-app.ts +79 -0
- package/src/packages/fastify-app/files/eslint-config-file-generator.ts +11 -0
- package/src/packages/fastify-app/files/index-file-generator.ts +144 -0
- package/src/packages/fastify-app/files/prettier-config-file-generator.ts +11 -0
- package/src/packages/fastify-app/files/tsconfig-file-generator.ts +15 -0
- package/src/packages/fastify-app/files/tsup-file-generator.ts +20 -0
- package/src/packages/fastify-app/files/vitest-config-file-generator.ts +19 -0
- package/src/packages/fastify-app/index.ts +1 -0
- package/src/packages/index.ts +3 -0
- package/src/packages/react-package/create-react-package.ts +1 -9
- package/src/packages/react-package/styled-components-react-package/create-styled-components-react-package.ts +1 -3
- package/src/packages/react-package/{css-react-package/create-css-react-package.ts → unstyled-react-package/create-unstyled-react-package.ts} +8 -7
- package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/button-file-generator.ts +2 -3
- package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/button-spec-file-generator.ts +0 -10
- package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/tsup-config-file-generator.ts +3 -6
- package/src/packages/vite-react-app/index.ts +1 -0
- package/src/utils/style-type.ts +1 -6
- package/src/packages/react-package/create-unstyled-react-package.ts +0 -3
- package/src/packages/react-package/css-react-package/files/button-css-module-file-generator.ts +0 -16
- /package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/eslint-config-file-generator.ts +0 -0
- /package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/index-file-generator.ts +0 -0
- /package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/prettier-config-file-generator.ts +0 -0
- /package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/tsconfig-file-generator.ts +0 -0
- /package/src/packages/react-package/{css-react-package → unstyled-react-package}/files/vitest-config-file-generator.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stack-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"bin": {
|
|
5
5
|
"stack": "./dist/index.js"
|
|
6
6
|
},
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"json5": "^2.2.3",
|
|
13
13
|
"lodash": "^4.17.21",
|
|
14
14
|
"yaml": "^2.8.0",
|
|
15
|
-
"@stack-dev/core": "0.1.
|
|
15
|
+
"@stack-dev/core": "0.1.2"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/lodash": "^4.17.20",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"prettier": "^3.6.2",
|
|
22
22
|
"prettier-plugin-organize-imports": "^4.2.0",
|
|
23
23
|
"tsup": "^7.3.0",
|
|
24
|
-
"@stack-dev/
|
|
25
|
-
"@stack-dev/
|
|
26
|
-
"@stack-dev/typescript-config": "0.1.
|
|
24
|
+
"@stack-dev/prettier-config": "0.1.2",
|
|
25
|
+
"@stack-dev/eslint-config": "0.1.2",
|
|
26
|
+
"@stack-dev/typescript-config": "0.1.2"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsup src/index.ts --dts --format esm,cjs",
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { prompt } from 'enquirer';
|
|
3
|
+
import { version } from '../package.json';
|
|
4
|
+
import { linkPackages } from './link-packages';
|
|
1
5
|
import {
|
|
6
|
+
createCliApp,
|
|
2
7
|
createConfigPackage,
|
|
8
|
+
createFastifyApp,
|
|
3
9
|
createLibraryPackage,
|
|
4
10
|
createReactPackage,
|
|
11
|
+
createViteReactApp,
|
|
5
12
|
} from './packages';
|
|
13
|
+
import { unlinkPackages } from './unlink-packages';
|
|
6
14
|
import {
|
|
7
15
|
comparePackages,
|
|
8
16
|
getAllPackages,
|
|
@@ -11,13 +19,6 @@ import {
|
|
|
11
19
|
} from './utils/package';
|
|
12
20
|
import { packageTypes, pickPackageType } from './utils/package-type';
|
|
13
21
|
import { pickStyleType, styleTypes } from './utils/style-type';
|
|
14
|
-
|
|
15
|
-
import { Command } from 'commander';
|
|
16
|
-
import { prompt } from 'enquirer';
|
|
17
|
-
import { version } from '../package.json';
|
|
18
|
-
import { linkPackages } from './link-packages';
|
|
19
|
-
import { createViteReactApp } from './packages/vite-react-app/create-vite-react-app';
|
|
20
|
-
import { unlinkPackages } from './unlink-packages';
|
|
21
22
|
import { getDirectoryPackageJson } from './utils/utils';
|
|
22
23
|
import { getNamespace } from './utils/workspace';
|
|
23
24
|
import { createWorkspace } from './workspace';
|
|
@@ -68,10 +69,10 @@ program
|
|
|
68
69
|
await createViteReactApp(name);
|
|
69
70
|
break;
|
|
70
71
|
case 'cli':
|
|
71
|
-
|
|
72
|
+
await createCliApp(name);
|
|
72
73
|
break;
|
|
73
74
|
case 'fastify':
|
|
74
|
-
|
|
75
|
+
await createFastifyApp(name);
|
|
75
76
|
break;
|
|
76
77
|
case 'next':
|
|
77
78
|
// await createNextPackage(name)
|
|
@@ -92,7 +93,7 @@ program
|
|
|
92
93
|
|
|
93
94
|
const development = options.dev ?? false;
|
|
94
95
|
|
|
95
|
-
if (!isValidPackageName(name)) {
|
|
96
|
+
if (!(await isValidPackageName(name))) {
|
|
96
97
|
throw new Error(`Package name "${name}" is not a valid option.`);
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { PackageJsonGenerator } from '../../file-generator';
|
|
3
|
+
import { Dependency, PackageJSON } from '../../package-json';
|
|
4
|
+
import { PackageGenerator } from '../../utils/package-generator';
|
|
5
|
+
import { getNamespace, getWorkspaceRoot } from '../../utils/workspace';
|
|
6
|
+
|
|
7
|
+
import { ESLINT_CONFIG_FILE_GENERATOR } from './files/eslint-config-file-generator';
|
|
8
|
+
import { INDEX_FILE_GENERATOR } from './files/index-file-generator';
|
|
9
|
+
import { PRETTIER_CONFIG_FILE_GENERATOR } from './files/prettier-config-file-generator';
|
|
10
|
+
import { TSCONFIG_FILE_GENERATOR } from './files/tsconfig-file-generator';
|
|
11
|
+
import { TSUP_FILE_GENERATOR } from './files/tsup-file-generator';
|
|
12
|
+
import { VITEST_CONFIG_FILE_GENERATOR } from './files/vitest-config-file-generator';
|
|
13
|
+
|
|
14
|
+
export async function createCliApp(name: string): Promise<void> {
|
|
15
|
+
const rootDir = await getWorkspaceRoot();
|
|
16
|
+
const directory = path.join(rootDir, 'apps', name);
|
|
17
|
+
|
|
18
|
+
const namespace = await getNamespace(rootDir);
|
|
19
|
+
const packageName = `${namespace}/${name}`;
|
|
20
|
+
|
|
21
|
+
console.log(`🚀 Creating CLI App: ${packageName}`);
|
|
22
|
+
|
|
23
|
+
const generator = new PackageGenerator(
|
|
24
|
+
directory,
|
|
25
|
+
makeAppPackageGenerator(packageName, namespace),
|
|
26
|
+
[
|
|
27
|
+
INDEX_FILE_GENERATOR,
|
|
28
|
+
TSCONFIG_FILE_GENERATOR,
|
|
29
|
+
TSUP_FILE_GENERATOR,
|
|
30
|
+
PRETTIER_CONFIG_FILE_GENERATOR,
|
|
31
|
+
ESLINT_CONFIG_FILE_GENERATOR,
|
|
32
|
+
VITEST_CONFIG_FILE_GENERATOR,
|
|
33
|
+
],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
await generator.generate();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makeAppPackageGenerator(packageName: string, namespace: string) {
|
|
40
|
+
const packageJsonModel = new PackageJSON({
|
|
41
|
+
name: packageName,
|
|
42
|
+
peerDependencies: [
|
|
43
|
+
new Dependency('typescript', '^5.9.3'),
|
|
44
|
+
new Dependency('@types/node', '^25.0.3'),
|
|
45
|
+
],
|
|
46
|
+
dependencies: [new Dependency('commander', '14.0.2')],
|
|
47
|
+
devDependencies: [
|
|
48
|
+
new Dependency(`${namespace}/eslint-config`, 'workspace:*'),
|
|
49
|
+
new Dependency(`${namespace}/prettier-config`, 'workspace:*'),
|
|
50
|
+
new Dependency(`${namespace}/typescript-config`, 'workspace:*'),
|
|
51
|
+
new Dependency('tsup', '^8.5.1'),
|
|
52
|
+
new Dependency('tsx', '^4.21.0'),
|
|
53
|
+
new Dependency('eslint', '^9.32.0'),
|
|
54
|
+
new Dependency('prettier', '^3.6.2'),
|
|
55
|
+
new Dependency('vitest', '^3.2.4'),
|
|
56
|
+
],
|
|
57
|
+
additionalData: {
|
|
58
|
+
version: '0.1.0',
|
|
59
|
+
private: true,
|
|
60
|
+
type: 'module',
|
|
61
|
+
scripts: {
|
|
62
|
+
dev: 'tsx watch src/index.ts',
|
|
63
|
+
build: 'tsup src/index.ts',
|
|
64
|
+
start: 'node dist/index.mjs',
|
|
65
|
+
lint: 'eslint .',
|
|
66
|
+
format: 'prettier . --write',
|
|
67
|
+
test: 'vitest run',
|
|
68
|
+
'test:watch': 'vitest',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return new PackageJsonGenerator(packageJsonModel, namespace);
|
|
74
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const ESLINT_CONFIG = `import base from '@stack-dev/eslint-config/base.mjs';
|
|
4
|
+
|
|
5
|
+
export default [...base, { ignores: ['**/dist/**'] }];
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const ESLINT_CONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
9
|
+
'eslint.config.mjs',
|
|
10
|
+
ESLINT_CONFIG,
|
|
11
|
+
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const INDEX = `import { Command } from "commander";;
|
|
4
|
+
|
|
5
|
+
const program = new Command();
|
|
6
|
+
|
|
7
|
+
program
|
|
8
|
+
.name('string-util')
|
|
9
|
+
.description('CLI to some JavaScript string utilities')
|
|
10
|
+
.version('0.8.0');
|
|
11
|
+
|
|
12
|
+
program.command('split')
|
|
13
|
+
.description('Split a string into substrings and display as an array')
|
|
14
|
+
.argument('<string>', 'string to split')
|
|
15
|
+
.option('--first', 'display just the first substring')
|
|
16
|
+
.option('-s, --separator <char>', 'separator character', ',')
|
|
17
|
+
.action((str, options) => {
|
|
18
|
+
const limit = options.first ? 1 : undefined;
|
|
19
|
+
console.log(str.split(options.separator, limit));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
program.parse();`;
|
|
23
|
+
|
|
24
|
+
export const INDEX_FILE_GENERATOR = new FileGeneratorImp('src/index.ts', INDEX);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const PRETTIER_CONFIG = `import base from '@stack-dev/prettier-config/base.mjs';
|
|
4
|
+
|
|
5
|
+
export default base;
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const PRETTIER_CONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
9
|
+
'prettier.config.mjs',
|
|
10
|
+
PRETTIER_CONFIG,
|
|
11
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const TSCONFIG = `{
|
|
4
|
+
"extends": "@stack-dev/typescript-config/tsconfig.base.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "dist"
|
|
7
|
+
},
|
|
8
|
+
"include": ["src"]
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const TSCONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
13
|
+
'tsconfig.json',
|
|
14
|
+
TSCONFIG,
|
|
15
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const TSUP = `import { defineConfig } from "tsup";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
entry: ["src/index.ts"],
|
|
7
|
+
format: ["esm"],
|
|
8
|
+
dts: false,
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
clean: true,
|
|
11
|
+
target: "esnext",
|
|
12
|
+
outExtension({ format }) {
|
|
13
|
+
return {
|
|
14
|
+
js: format === "esm" ? ".mjs" : ".js",
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export const TSUP_FILE_GENERATOR = new FileGeneratorImp('tsup.config.ts', TSUP);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const VITEST_CONFIG = `import { defineConfig } from 'vitest/config';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
test: {
|
|
7
|
+
globals: true,
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'v8',
|
|
10
|
+
},
|
|
11
|
+
environment: 'node',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
export const VITEST_CONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
17
|
+
'vitest.config.ts',
|
|
18
|
+
VITEST_CONFIG,
|
|
19
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-cli-app';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { PackageJsonGenerator } from '../../file-generator';
|
|
3
|
+
import { Dependency, PackageJSON } from '../../package-json';
|
|
4
|
+
import { PackageGenerator } from '../../utils/package-generator';
|
|
5
|
+
import { getNamespace, getWorkspaceRoot } from '../../utils/workspace';
|
|
6
|
+
|
|
7
|
+
import { ESLINT_CONFIG_FILE_GENERATOR } from './files/eslint-config-file-generator';
|
|
8
|
+
import { INDEX_FILE_GENERATOR } from './files/index-file-generator';
|
|
9
|
+
import { PRETTIER_CONFIG_FILE_GENERATOR } from './files/prettier-config-file-generator';
|
|
10
|
+
import { TSCONFIG_FILE_GENERATOR } from './files/tsconfig-file-generator';
|
|
11
|
+
import { TSUP_FILE_GENERATOR } from './files/tsup-file-generator';
|
|
12
|
+
import { VITEST_CONFIG_FILE_GENERATOR } from './files/vitest-config-file-generator';
|
|
13
|
+
|
|
14
|
+
export async function createFastifyApp(name: string): Promise<void> {
|
|
15
|
+
const rootDir = await getWorkspaceRoot();
|
|
16
|
+
const directory = path.join(rootDir, 'apps', name);
|
|
17
|
+
|
|
18
|
+
const namespace = await getNamespace(rootDir);
|
|
19
|
+
const packageName = `${namespace}/${name}`;
|
|
20
|
+
|
|
21
|
+
console.log(`🚀 Creating Fastify App: ${packageName}`);
|
|
22
|
+
|
|
23
|
+
const generator = new PackageGenerator(
|
|
24
|
+
directory,
|
|
25
|
+
makeAppPackageGenerator(packageName, namespace),
|
|
26
|
+
[
|
|
27
|
+
INDEX_FILE_GENERATOR,
|
|
28
|
+
TSCONFIG_FILE_GENERATOR,
|
|
29
|
+
TSUP_FILE_GENERATOR,
|
|
30
|
+
PRETTIER_CONFIG_FILE_GENERATOR,
|
|
31
|
+
ESLINT_CONFIG_FILE_GENERATOR,
|
|
32
|
+
VITEST_CONFIG_FILE_GENERATOR,
|
|
33
|
+
],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
await generator.generate();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makeAppPackageGenerator(packageName: string, namespace: string) {
|
|
40
|
+
const packageJsonModel = new PackageJSON({
|
|
41
|
+
name: packageName,
|
|
42
|
+
peerDependencies: [
|
|
43
|
+
new Dependency('typescript', '^5.9.3'),
|
|
44
|
+
new Dependency('@types/node', '^25.0.3'),
|
|
45
|
+
],
|
|
46
|
+
dependencies: [
|
|
47
|
+
new Dependency('fastify', '^5.6.2'),
|
|
48
|
+
new Dependency('@fastify/swagger', '^9.6.1'),
|
|
49
|
+
new Dependency('@fastify/swagger-ui', '^5.2.3'),
|
|
50
|
+
new Dependency('pino-pretty', '^13.1.3'),
|
|
51
|
+
],
|
|
52
|
+
devDependencies: [
|
|
53
|
+
new Dependency(`${namespace}/eslint-config`, 'workspace:*'),
|
|
54
|
+
new Dependency(`${namespace}/prettier-config`, 'workspace:*'),
|
|
55
|
+
new Dependency(`${namespace}/typescript-config`, 'workspace:*'),
|
|
56
|
+
new Dependency('tsup', '^8.5.1'),
|
|
57
|
+
new Dependency('tsx', '^4.21.0'),
|
|
58
|
+
new Dependency('eslint', '^9.32.0'),
|
|
59
|
+
new Dependency('prettier', '^3.6.2'),
|
|
60
|
+
new Dependency('vitest', '^3.2.4'),
|
|
61
|
+
],
|
|
62
|
+
additionalData: {
|
|
63
|
+
version: '0.1.0',
|
|
64
|
+
private: true,
|
|
65
|
+
type: 'module',
|
|
66
|
+
scripts: {
|
|
67
|
+
dev: 'tsx watch src/index.ts',
|
|
68
|
+
build: 'tsup src/index.ts',
|
|
69
|
+
start: 'node dist/index.mjs',
|
|
70
|
+
lint: 'eslint .',
|
|
71
|
+
format: 'prettier . --write',
|
|
72
|
+
test: 'vitest run',
|
|
73
|
+
'test:watch': 'vitest',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return new PackageJsonGenerator(packageJsonModel, namespace);
|
|
79
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const ESLINT_CONFIG = `import base from '@stack-dev/eslint-config/base.mjs';
|
|
4
|
+
|
|
5
|
+
export default [...base, { ignores: ['**/dist/**'] }];
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const ESLINT_CONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
9
|
+
'eslint.config.mjs',
|
|
10
|
+
ESLINT_CONFIG,
|
|
11
|
+
);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const INDEX = `import Fastify from "fastify";
|
|
4
|
+
import fastifySwagger from "@fastify/swagger";
|
|
5
|
+
import fastifySwaggerUI from "@fastify/swagger-ui";
|
|
6
|
+
|
|
7
|
+
const fastify = Fastify({
|
|
8
|
+
logger: {
|
|
9
|
+
transport: {
|
|
10
|
+
target: "pino-pretty",
|
|
11
|
+
},
|
|
12
|
+
serializers: {
|
|
13
|
+
res(reply) {
|
|
14
|
+
// The default
|
|
15
|
+
return {
|
|
16
|
+
statusCode: reply.statusCode,
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
req(request) {
|
|
20
|
+
return {
|
|
21
|
+
method: request.method,
|
|
22
|
+
url: request.url,
|
|
23
|
+
path: request.routeOptions.url,
|
|
24
|
+
parameters: request.params,
|
|
25
|
+
// Including headers in the log could violate privacy laws,
|
|
26
|
+
// e.g., GDPR. Use the "redact" option to remove sensitive
|
|
27
|
+
// fields. It could also leak authentication data in the logs.
|
|
28
|
+
headers: request.headers,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await registerSwagger();
|
|
36
|
+
|
|
37
|
+
registerRoutes();
|
|
38
|
+
|
|
39
|
+
function registerRoutes() {
|
|
40
|
+
fastify.get("/", async (request, reply) => {
|
|
41
|
+
return { hello: "world", docs: "/docs" };
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
fastify.get<{
|
|
45
|
+
Params: { a: string; b: string };
|
|
46
|
+
}>(
|
|
47
|
+
"/add/:a/:b",
|
|
48
|
+
{
|
|
49
|
+
schema: {
|
|
50
|
+
params: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
a: { type: "string" },
|
|
54
|
+
b: { type: "string" },
|
|
55
|
+
},
|
|
56
|
+
required: ["a", "b"],
|
|
57
|
+
},
|
|
58
|
+
response: {
|
|
59
|
+
200: {
|
|
60
|
+
type: "object",
|
|
61
|
+
properties: {
|
|
62
|
+
result: { type: "number" },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
async (request, reply) => {
|
|
69
|
+
// request.params.a should now be recognized as a string
|
|
70
|
+
const a = Number(request.params.a);
|
|
71
|
+
const b = Number(request.params.b);
|
|
72
|
+
|
|
73
|
+
return { result: a + b };
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function registerSwagger() {
|
|
79
|
+
await fastify.register(fastifySwagger, {
|
|
80
|
+
openapi: {
|
|
81
|
+
openapi: "3.0.0",
|
|
82
|
+
info: {
|
|
83
|
+
title: "Test swagger",
|
|
84
|
+
description: "Testing the Fastify swagger API",
|
|
85
|
+
version: "0.1.0",
|
|
86
|
+
},
|
|
87
|
+
servers: [
|
|
88
|
+
{
|
|
89
|
+
url: "http://localhost:3000",
|
|
90
|
+
description: "Development server",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
components: {
|
|
94
|
+
securitySchemes: {
|
|
95
|
+
apiKey: {
|
|
96
|
+
type: "apiKey",
|
|
97
|
+
name: "apiKey",
|
|
98
|
+
in: "header",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
externalDocs: {
|
|
103
|
+
url: "https://swagger.io",
|
|
104
|
+
description: "Find more info here",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await fastify.register(fastifySwaggerUI, {
|
|
110
|
+
routePrefix: "/docs",
|
|
111
|
+
uiConfig: {
|
|
112
|
+
docExpansion: "list",
|
|
113
|
+
deepLinking: false,
|
|
114
|
+
},
|
|
115
|
+
uiHooks: {
|
|
116
|
+
onRequest: function (request, reply, next) {
|
|
117
|
+
next();
|
|
118
|
+
},
|
|
119
|
+
preHandler: function (request, reply, next) {
|
|
120
|
+
next();
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
staticCSP: true,
|
|
124
|
+
transformStaticCSP: (header) => header,
|
|
125
|
+
transformSpecification: (swaggerObject, request, reply) => {
|
|
126
|
+
return swaggerObject;
|
|
127
|
+
},
|
|
128
|
+
transformSpecificationClone: true,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function start() {
|
|
133
|
+
try {
|
|
134
|
+
await fastify.listen({ port: 3000 });
|
|
135
|
+
} catch (err) {
|
|
136
|
+
fastify.log.error(err);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
start();
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
export const INDEX_FILE_GENERATOR = new FileGeneratorImp('src/index.ts', INDEX);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const PRETTIER_CONFIG = `import base from '@stack-dev/prettier-config/base.mjs';
|
|
4
|
+
|
|
5
|
+
export default base;
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const PRETTIER_CONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
9
|
+
'prettier.config.mjs',
|
|
10
|
+
PRETTIER_CONFIG,
|
|
11
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const TSCONFIG = `{
|
|
4
|
+
"extends": "@stack-dev/typescript-config/tsconfig.base.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "dist"
|
|
7
|
+
},
|
|
8
|
+
"include": ["src"]
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const TSCONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
13
|
+
'tsconfig.json',
|
|
14
|
+
TSCONFIG,
|
|
15
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const TSUP = `import { defineConfig } from "tsup";
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
entry: ["src/index.ts"],
|
|
7
|
+
format: ["esm"],
|
|
8
|
+
dts: false,
|
|
9
|
+
sourcemap: true,
|
|
10
|
+
clean: true,
|
|
11
|
+
target: "esnext",
|
|
12
|
+
outExtension({ format }) {
|
|
13
|
+
return {
|
|
14
|
+
js: format === "esm" ? ".mjs" : ".js",
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export const TSUP_FILE_GENERATOR = new FileGeneratorImp('tsup.config.ts', TSUP);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FileGeneratorImp } from '../../../file-generator/file-generator-imp';
|
|
2
|
+
|
|
3
|
+
const VITEST_CONFIG = `import { defineConfig } from 'vitest/config';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
test: {
|
|
7
|
+
globals: true,
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'v8',
|
|
10
|
+
},
|
|
11
|
+
environment: 'node',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
export const VITEST_CONFIG_FILE_GENERATOR = new FileGeneratorImp(
|
|
17
|
+
'vitest.config.ts',
|
|
18
|
+
VITEST_CONFIG,
|
|
19
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-fastify-app';
|
package/src/packages/index.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { StyleType } from '../../utils/style-type';
|
|
2
|
-
import { createTailwindReactPackage } from './create-tailwind-react-package';
|
|
3
|
-
import { createUnstyledReactPackage } from './create-unstyled-react-package';
|
|
4
|
-
import { createCssReactPackage } from './css-react-package/create-css-react-package';
|
|
5
2
|
import { createStyledComponentsReactPackage } from './styled-components-react-package/create-styled-components-react-package';
|
|
3
|
+
import { createUnstyledReactPackage } from './unstyled-react-package/create-unstyled-react-package';
|
|
6
4
|
|
|
7
5
|
export async function createReactPackage(
|
|
8
6
|
name: string,
|
|
9
7
|
style: StyleType,
|
|
10
8
|
): Promise<void> {
|
|
11
9
|
switch (style) {
|
|
12
|
-
case 'tailwind':
|
|
13
|
-
await createTailwindReactPackage(name);
|
|
14
|
-
break;
|
|
15
|
-
case 'css-modules':
|
|
16
|
-
await createCssReactPackage(name);
|
|
17
|
-
break;
|
|
18
10
|
case 'styled-components':
|
|
19
11
|
await createStyledComponentsReactPackage(name);
|
|
20
12
|
break;
|
|
@@ -21,9 +21,7 @@ export async function createStyledComponentsReactPackage(
|
|
|
21
21
|
const namespace = await getNamespace(rootDir);
|
|
22
22
|
const packageName = `${namespace}/${name}`;
|
|
23
23
|
|
|
24
|
-
console.log(
|
|
25
|
-
`✨ Creating Styled Components Modules React library: ${packageName}`,
|
|
26
|
-
);
|
|
24
|
+
console.log(`✨ Creating Styled Components React library: ${packageName}`);
|
|
27
25
|
|
|
28
26
|
const generator = new PackageGenerator(
|
|
29
27
|
directory,
|