create-absolutejs 0.3.1 → 0.3.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/commands/formatProject.d.ts +4 -2
- package/dist/commands/formatProject.js +21 -0
- package/dist/commands/installDependencies.js +19 -0
- package/dist/constants.js +4 -0
- package/dist/data.js +125 -0
- package/dist/generators/configurations/addConfigurationFiles.js +21 -0
- package/dist/generators/configurations/generateDrizzleConfig.js +11 -0
- package/dist/generators/configurations/generatePackageJson.js +74 -0
- package/dist/generators/configurations/generatePrettierrc.js +13 -0
- package/dist/generators/configurations/initializeRoot.js +26 -0
- package/dist/generators/db/scaffoldDatabase.js +16 -0
- package/dist/generators/html/scaffoldHTML.js +14 -0
- package/dist/generators/htmx/scaffoldHTMX.js +15 -0
- package/dist/generators/project/generateMarkupCSS.js +133 -0
- package/dist/generators/project/generateServer.js +159 -0
- package/dist/generators/project/scaffoldFrontends.js +71 -0
- package/dist/generators/react/scaffoldReact.js +14 -0
- package/dist/generators/svelte/scaffoldSvelte.js +13 -0
- package/dist/generators/vue/scaffoldVue.js +8 -0
- package/dist/index.js +23 -2464
- package/dist/messages.js +84 -0
- package/dist/prompt.js +84 -0
- package/dist/questions/authProvider.js +15 -0
- package/dist/questions/codeQualityTool.js +18 -0
- package/dist/questions/configurationType.js +15 -0
- package/dist/questions/databaseEngine.js +24 -0
- package/dist/questions/databaseHost.js +51 -0
- package/dist/questions/directoryConfiguration.js +77 -0
- package/dist/questions/frontendDirectoryConfigurations.js +29 -0
- package/dist/questions/frontends.js +16 -0
- package/dist/questions/htmlScriptingOption.js +10 -0
- package/dist/questions/initializeGitNow.js +10 -0
- package/dist/questions/installDependenciesNow.js +10 -0
- package/dist/questions/orm.js +16 -0
- package/dist/questions/plugins.js +13 -0
- package/dist/questions/projectName.js +11 -0
- package/dist/questions/useTailwind.js +8 -0
- package/dist/scaffold.js +70 -0
- package/dist/typeGuards.js +24 -0
- package/dist/types.js +1 -0
- package/dist/utils/abort.js +8 -0
- package/dist/utils/commandMaps.d.ts +3 -1
- package/dist/utils/commandMaps.js +18 -0
- package/dist/utils/getPackageVersion.js +12 -0
- package/dist/utils/parseCommandLineOptions.js +170 -0
- package/dist/utils/t3-utils.js +24 -0
- package/package.json +2 -2
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
2
|
+
import { UNFOUND_INDEX } from '../../constants';
|
|
3
|
+
import { absoluteAuthPlugin, defaultDependencies, defaultPlugins, scopedStatePlugin } from '../../data';
|
|
4
|
+
export const createServerFile = ({ tailwind, frontendDirectories, serverFilePath, authProvider, availablePlugins, buildDirectory, assetsDirectory, plugins }) => {
|
|
5
|
+
const htmlDirectory = frontendDirectories['html'];
|
|
6
|
+
const reactDirectory = frontendDirectories['react'];
|
|
7
|
+
const svelteDirectory = frontendDirectories['svelte'];
|
|
8
|
+
const vueDirectory = frontendDirectories['vue'];
|
|
9
|
+
const htmxDirectory = frontendDirectories['htmx'];
|
|
10
|
+
const requiresHtml = htmlDirectory !== undefined;
|
|
11
|
+
const requiresReact = reactDirectory !== undefined;
|
|
12
|
+
const requiresSvelte = svelteDirectory !== undefined;
|
|
13
|
+
const requiresVue = vueDirectory !== undefined;
|
|
14
|
+
const requiresHtmx = htmxDirectory !== undefined;
|
|
15
|
+
const nonFrameworkOnly = (requiresHtml || requiresHtmx) &&
|
|
16
|
+
!requiresReact &&
|
|
17
|
+
!requiresSvelte &&
|
|
18
|
+
!requiresVue;
|
|
19
|
+
const selectedCustomPlugins = availablePlugins.filter(({ value }) => plugins.indexOf(value) !== UNFOUND_INDEX);
|
|
20
|
+
const authenticationPlugins = authProvider === 'absoluteAuth' ? [absoluteAuthPlugin] : [];
|
|
21
|
+
const htmxPlugins = requiresHtmx ? [scopedStatePlugin] : [];
|
|
22
|
+
const allDependencies = [
|
|
23
|
+
...defaultDependencies,
|
|
24
|
+
...defaultPlugins,
|
|
25
|
+
...selectedCustomPlugins,
|
|
26
|
+
...authenticationPlugins,
|
|
27
|
+
...htmxPlugins
|
|
28
|
+
];
|
|
29
|
+
const uniqueDependencies = Array.from(new Map(allDependencies.map((dependency) => [dependency.value, dependency])).values()).sort((a, b) => a.value.localeCompare(b.value));
|
|
30
|
+
const importLines = uniqueDependencies.flatMap(({ value, imports }) => {
|
|
31
|
+
const filteredImports = nonFrameworkOnly && imports
|
|
32
|
+
? imports.filter(({ packageName }) => packageName !== 'asset')
|
|
33
|
+
: imports;
|
|
34
|
+
return filteredImports && filteredImports.length > 0
|
|
35
|
+
? [
|
|
36
|
+
`import { ${filteredImports
|
|
37
|
+
.map(({ packageName }) => packageName)
|
|
38
|
+
.join(', ')} } from '${value}';`
|
|
39
|
+
]
|
|
40
|
+
: [];
|
|
41
|
+
});
|
|
42
|
+
const absoluteImportIdx = importLines.findIndex((line) => line.includes("from '@absolutejs/absolute'"));
|
|
43
|
+
if (absoluteImportIdx !== UNFOUND_INDEX && importLines[absoluteImportIdx]) {
|
|
44
|
+
const existingItems = importLines[absoluteImportIdx]
|
|
45
|
+
.replace(/import\s*\{\s*|\}\s*from.*$/g, '')
|
|
46
|
+
.split(',')
|
|
47
|
+
.map((item) => item.trim())
|
|
48
|
+
.filter((value) => value.length > 0);
|
|
49
|
+
const additionalItems = [
|
|
50
|
+
requiresHtml &&
|
|
51
|
+
!existingItems.includes('handleHTMLPageRequest') &&
|
|
52
|
+
'handleHTMLPageRequest',
|
|
53
|
+
requiresReact &&
|
|
54
|
+
!existingItems.includes('handleReactPageRequest') &&
|
|
55
|
+
'handleReactPageRequest',
|
|
56
|
+
requiresSvelte &&
|
|
57
|
+
!existingItems.includes('handleSveltePageRequest') &&
|
|
58
|
+
'handleSveltePageRequest',
|
|
59
|
+
requiresVue &&
|
|
60
|
+
!existingItems.includes('handleVuePageRequest') &&
|
|
61
|
+
'handleVuePageRequest',
|
|
62
|
+
requiresVue &&
|
|
63
|
+
!existingItems.includes('generateHeadElement') &&
|
|
64
|
+
'generateHeadElement',
|
|
65
|
+
requiresHtmx &&
|
|
66
|
+
!existingItems.includes('handleHTMXPageRequest') &&
|
|
67
|
+
'handleHTMXPageRequest'
|
|
68
|
+
].filter((value) => typeof value === 'string');
|
|
69
|
+
importLines[absoluteImportIdx] = `import { ${[
|
|
70
|
+
...existingItems,
|
|
71
|
+
...additionalItems
|
|
72
|
+
].join(', ')} } from '@absolutejs/absolute';`;
|
|
73
|
+
}
|
|
74
|
+
if (reactDirectory !== undefined) {
|
|
75
|
+
const reactImportSource = reactDirectory === ''
|
|
76
|
+
? '../frontend/pages/ReactExample'
|
|
77
|
+
: `../frontend/${reactDirectory}/pages/ReactExample`;
|
|
78
|
+
importLines.push(`import { ReactExample } from '${reactImportSource}';`);
|
|
79
|
+
}
|
|
80
|
+
if (requiresSvelte) {
|
|
81
|
+
const svelteImportSource = svelteDirectory === ''
|
|
82
|
+
? '../frontend/pages/SvelteExample'
|
|
83
|
+
: `../frontend/${svelteDirectory}/pages/SvelteExample`;
|
|
84
|
+
importLines.push(`import SvelteExample from '${svelteImportSource}.svelte';`);
|
|
85
|
+
}
|
|
86
|
+
if (requiresVue) {
|
|
87
|
+
const vueImportSource = vueDirectory === ''
|
|
88
|
+
? '../frontend/pages/VueExample'
|
|
89
|
+
: `../frontend/${vueDirectory}/pages/VueExample`;
|
|
90
|
+
importLines.push(`import VueExample from '${vueImportSource}.vue';`);
|
|
91
|
+
}
|
|
92
|
+
const useStatements = uniqueDependencies
|
|
93
|
+
.flatMap(({ imports }) => imports ?? [])
|
|
94
|
+
.filter((entry) => entry.isPlugin)
|
|
95
|
+
.map((entry) => {
|
|
96
|
+
if (entry.config === undefined)
|
|
97
|
+
return `.use(${entry.packageName})`;
|
|
98
|
+
if (entry.config === null)
|
|
99
|
+
return `.use(${entry.packageName}())`;
|
|
100
|
+
return `.use(${entry.packageName}(${JSON.stringify(entry.config)}))`;
|
|
101
|
+
});
|
|
102
|
+
const manifestOptions = [
|
|
103
|
+
`assetsDirectory: '${assetsDirectory}'`,
|
|
104
|
+
`buildDirectory: '${buildDirectory}'`,
|
|
105
|
+
...Object.entries(frontendDirectories).map(([frameworkName, directory]) => `${frameworkName}Directory: './src/frontend/${directory}'`),
|
|
106
|
+
tailwind ? `tailwind: ${JSON.stringify(tailwind)}` : ''
|
|
107
|
+
].filter(Boolean);
|
|
108
|
+
const manifestDeclaration = `${nonFrameworkOnly ? '' : 'const manifest = '}await build({
|
|
109
|
+
${manifestOptions.join(',\n ')}
|
|
110
|
+
});`;
|
|
111
|
+
const routesData = Object.entries(frontendDirectories).reduce((acc, [frameworkName, directory], index) => {
|
|
112
|
+
let handler;
|
|
113
|
+
switch (frameworkName) {
|
|
114
|
+
case 'html':
|
|
115
|
+
handler = `handleHTMLPageRequest(\`${buildDirectory}${directory ? `/${directory}` : ''}/pages/HTMLExample.html\`)`;
|
|
116
|
+
break;
|
|
117
|
+
case 'react':
|
|
118
|
+
handler = `handleReactPageRequest(ReactExample, asset(manifest, 'ReactExampleIndex'), { initialCount: 0, cssPath: asset(manifest, 'ReactExampleCSS') })`;
|
|
119
|
+
break;
|
|
120
|
+
case 'svelte':
|
|
121
|
+
handler = `handleSveltePageRequest(SvelteExample, asset(manifest, 'SvelteExample'), asset(manifest, 'SvelteExampleIndex'), { initialCount: 0, cssPath: asset(manifest, 'SvelteExampleCSS') })`;
|
|
122
|
+
break;
|
|
123
|
+
case 'vue':
|
|
124
|
+
handler = `handleVuePageRequest(VueExample, asset(manifest, 'VueExample'), asset(manifest, 'VueExampleIndex'), generateHeadElement({ cssPath: asset(manifest, 'VueExampleCSS'), title: 'AbsoluteJS + Vue' }), { initialCount: 0 })`;
|
|
125
|
+
break;
|
|
126
|
+
case 'htmx':
|
|
127
|
+
handler = `handleHTMXPageRequest(\`${buildDirectory}${directory ? `/${directory}` : ''}/pages/HTMXExample.html\`)`;
|
|
128
|
+
if (index === 0) {
|
|
129
|
+
acc.indexRoute = `.get('/', () => ${handler})`;
|
|
130
|
+
}
|
|
131
|
+
acc.otherRoutes.push(`.post('/htmx/reset', ({ resetScopedStore }) => resetScopedStore())`, `.get('/htmx/count', ({ scopedStore }) => scopedStore.count)`, `.post('/htmx/increment', ({ scopedStore }) => ++scopedStore.count)`, `.get('htmx', () => ${handler})`);
|
|
132
|
+
return acc;
|
|
133
|
+
default:
|
|
134
|
+
return acc;
|
|
135
|
+
}
|
|
136
|
+
if (index === 0) {
|
|
137
|
+
acc.indexRoute = `.get('/', () => ${handler})`;
|
|
138
|
+
}
|
|
139
|
+
acc.otherRoutes.push(`.get('${frameworkName}', () => ${handler})`);
|
|
140
|
+
return acc;
|
|
141
|
+
}, { indexRoute: null, otherRoutes: [] });
|
|
142
|
+
const routes = [routesData.indexRoute ?? '', ...routesData.otherRoutes]
|
|
143
|
+
.filter(Boolean)
|
|
144
|
+
.join('\n ');
|
|
145
|
+
const useLines = useStatements.map((s) => ` ${s}`).join('\n');
|
|
146
|
+
const serverFileContent = `${importLines.join('\n')}
|
|
147
|
+
|
|
148
|
+
${manifestDeclaration}
|
|
149
|
+
|
|
150
|
+
new Elysia()
|
|
151
|
+
${useLines}
|
|
152
|
+
${routes}
|
|
153
|
+
.on('error', (err) => {
|
|
154
|
+
const { request } = err;
|
|
155
|
+
console.error(\`Server error on \${request.method} \${request.url}: \${err.message}\`);
|
|
156
|
+
});
|
|
157
|
+
`;
|
|
158
|
+
writeFileSync(serverFilePath, serverFileContent);
|
|
159
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { cpSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { scaffoldHTML } from '../html/scaffoldHTML';
|
|
4
|
+
import { scaffoldHTMX } from '../htmx/scaffoldHTMX';
|
|
5
|
+
import { scaffoldReact } from '../react/scaffoldReact';
|
|
6
|
+
import { scaffoldSvelte } from '../svelte/scaffoldSvelte';
|
|
7
|
+
import { scaffoldVue } from '../vue/scaffoldVue';
|
|
8
|
+
export const scaffoldFrontends = ({ frontendDirectory, templatesDirectory, projectAssetsDirectory, useHTMLScripts, frontendDirectories }) => {
|
|
9
|
+
const stylesTargetDirectory = join(frontendDirectory, 'styles');
|
|
10
|
+
cpSync(join(templatesDirectory, 'styles'), stylesTargetDirectory, {
|
|
11
|
+
recursive: true
|
|
12
|
+
});
|
|
13
|
+
const frontendEntries = Object.entries(frontendDirectories);
|
|
14
|
+
const isSingleFrontend = frontendEntries.length === 1;
|
|
15
|
+
const directoryMap = new Map();
|
|
16
|
+
for (const [frontendName, rawDirectory] of frontendEntries) {
|
|
17
|
+
const directory = rawDirectory?.trim() ?? (isSingleFrontend ? '' : frontendName);
|
|
18
|
+
if (directoryMap.has(directory)) {
|
|
19
|
+
throw new Error(`Frontend directory collision: "${directory}" is assigned to both "${directoryMap.get(directory)}" and "${frontendName}". Please pick unique directories.`);
|
|
20
|
+
}
|
|
21
|
+
directoryMap.set(directory, frontendName);
|
|
22
|
+
const targetDirectory = join(frontendDirectory, directory);
|
|
23
|
+
if (!isSingleFrontend)
|
|
24
|
+
mkdirSync(targetDirectory);
|
|
25
|
+
switch (frontendName) {
|
|
26
|
+
case 'react':
|
|
27
|
+
scaffoldReact({
|
|
28
|
+
isSingleFrontend,
|
|
29
|
+
projectAssetsDirectory,
|
|
30
|
+
targetDirectory,
|
|
31
|
+
templatesDirectory
|
|
32
|
+
});
|
|
33
|
+
break;
|
|
34
|
+
case 'svelte':
|
|
35
|
+
scaffoldSvelte({
|
|
36
|
+
isSingleFrontend,
|
|
37
|
+
projectAssetsDirectory,
|
|
38
|
+
targetDirectory,
|
|
39
|
+
templatesDirectory
|
|
40
|
+
});
|
|
41
|
+
break;
|
|
42
|
+
case 'vue':
|
|
43
|
+
scaffoldVue({
|
|
44
|
+
projectAssetsDirectory,
|
|
45
|
+
targetDirectory,
|
|
46
|
+
templatesDirectory
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
case 'angular':
|
|
50
|
+
console.warn('Angular is not yet supported. Refer to the documentation for more information.');
|
|
51
|
+
break;
|
|
52
|
+
case 'html':
|
|
53
|
+
scaffoldHTML({
|
|
54
|
+
isSingleFrontend,
|
|
55
|
+
projectAssetsDirectory,
|
|
56
|
+
targetDirectory,
|
|
57
|
+
templatesDirectory,
|
|
58
|
+
useHTMLScripts
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
case 'htmx':
|
|
62
|
+
scaffoldHTMX({
|
|
63
|
+
isSingleFrontend,
|
|
64
|
+
projectAssetsDirectory,
|
|
65
|
+
targetDirectory,
|
|
66
|
+
templatesDirectory
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { copyFileSync, cpSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { generateMarkupCSS } from '../project/generateMarkupCSS';
|
|
4
|
+
export const scaffoldReact = ({ isSingleFrontend, targetDirectory, templatesDirectory, projectAssetsDirectory }) => {
|
|
5
|
+
copyFileSync(join(templatesDirectory, 'assets', 'svg', 'react.svg'), join(projectAssetsDirectory, 'svg', 'react.svg'));
|
|
6
|
+
cpSync(join(templatesDirectory, 'react'), targetDirectory, {
|
|
7
|
+
recursive: true
|
|
8
|
+
});
|
|
9
|
+
const cssOutputDir = join(targetDirectory, 'styles');
|
|
10
|
+
mkdirSync(cssOutputDir, { recursive: true });
|
|
11
|
+
const cssOutputFile = join(cssOutputDir, 'react-example.css');
|
|
12
|
+
const reactCSS = generateMarkupCSS(isSingleFrontend);
|
|
13
|
+
writeFileSync(cssOutputFile, reactCSS, 'utf-8');
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { copyFileSync, cpSync, mkdirSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
export const scaffoldSvelte = ({ isSingleFrontend, targetDirectory, templatesDirectory, projectAssetsDirectory }) => {
|
|
4
|
+
copyFileSync(join(templatesDirectory, 'assets', 'svg', 'svelte-logo.svg'), join(projectAssetsDirectory, 'svg', 'svelte-logo.svg'));
|
|
5
|
+
cpSync(join(templatesDirectory, 'svelte'), targetDirectory, {
|
|
6
|
+
recursive: true
|
|
7
|
+
});
|
|
8
|
+
const cssOutputDirectory = join(targetDirectory, 'styles');
|
|
9
|
+
mkdirSync(cssOutputDirectory, { recursive: true });
|
|
10
|
+
const cssOutputFile = join(cssOutputDirectory, 'svelte-example.css');
|
|
11
|
+
const svelteCSS = `@import url('${isSingleFrontend ? '../' : '../../'}styles/reset.css');`;
|
|
12
|
+
writeFileSync(cssOutputFile, svelteCSS, 'utf-8');
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { cpSync, copyFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
export const scaffoldVue = ({ targetDirectory, templatesDirectory, projectAssetsDirectory }) => {
|
|
4
|
+
copyFileSync(join(templatesDirectory, 'assets', 'svg', 'vue-logo.svg'), join(projectAssetsDirectory, 'svg', 'vue-logo.svg'));
|
|
5
|
+
cpSync(join(templatesDirectory, 'vue'), targetDirectory, {
|
|
6
|
+
recursive: true
|
|
7
|
+
});
|
|
8
|
+
};
|