create-absolutejs 0.3.0 → 0.3.2
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.js +19 -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 +69 -0
- package/dist/typeGuards.js +24 -0
- package/dist/types.js +1 -0
- package/dist/utils/abort.js +8 -0
- package/dist/utils/commandMaps.js +12 -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,170 @@
|
|
|
1
|
+
import { argv, exit } from 'node:process';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { DEFAULT_ARG_LENGTH } from '../constants';
|
|
4
|
+
import { availableAuthProviders, availableCodeQualityTools, availableDatabaseEngines, availableDatabaseHosts, availableDirectoryConfigurations, availableORMs, availableFrontends } from '../data';
|
|
5
|
+
import { isAuthProvider, isCodeQualityTool, isDatabaseEngine, isDatabaseHost, isDirectoryConfig, isFrontend, isORM } from '../typeGuards';
|
|
6
|
+
export const parseCommandLineOptions = () => {
|
|
7
|
+
const { values, positionals } = parseArgs({
|
|
8
|
+
allowNegative: true,
|
|
9
|
+
allowPositionals: true,
|
|
10
|
+
args: argv.slice(DEFAULT_ARG_LENGTH),
|
|
11
|
+
options: {
|
|
12
|
+
angular: { type: 'string' },
|
|
13
|
+
assets: { type: 'string' },
|
|
14
|
+
auth: { type: 'string' },
|
|
15
|
+
build: { type: 'string' },
|
|
16
|
+
database: { type: 'string' },
|
|
17
|
+
debug: { default: false, short: 'd', type: 'boolean' },
|
|
18
|
+
directory: { type: 'string' },
|
|
19
|
+
engine: { type: 'string' },
|
|
20
|
+
frontend: { multiple: true, type: 'string' },
|
|
21
|
+
git: { type: 'boolean' },
|
|
22
|
+
help: { default: false, short: 'h', type: 'boolean' },
|
|
23
|
+
host: { type: 'string' },
|
|
24
|
+
html: { type: 'string' },
|
|
25
|
+
'html-script': { type: 'boolean' },
|
|
26
|
+
htmx: { type: 'string' },
|
|
27
|
+
lts: { default: false, type: 'boolean' },
|
|
28
|
+
npm: { type: 'boolean' },
|
|
29
|
+
orm: { type: 'string' },
|
|
30
|
+
plugin: { multiple: true, type: 'string' },
|
|
31
|
+
quality: { type: 'string' },
|
|
32
|
+
react: { type: 'string' },
|
|
33
|
+
skip: { type: 'boolean' },
|
|
34
|
+
svelte: { type: 'string' },
|
|
35
|
+
tailwind: { type: 'boolean' },
|
|
36
|
+
'tailwind-input': { type: 'string' },
|
|
37
|
+
'tailwind-output': { type: 'string' },
|
|
38
|
+
vue: { type: 'string' }
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const errors = [];
|
|
42
|
+
const projectName = (positionals[0] ?? values.skip) ? 'absolutejs-project' : undefined;
|
|
43
|
+
let authProvider;
|
|
44
|
+
if (values.auth !== undefined && !isAuthProvider(values.auth)) {
|
|
45
|
+
errors.push(`Invalid auth provider: "${values.auth}". Expected: [ ${availableAuthProviders.join(', ')} ]`);
|
|
46
|
+
}
|
|
47
|
+
else if (values.auth !== undefined) {
|
|
48
|
+
authProvider = values.auth;
|
|
49
|
+
}
|
|
50
|
+
else if (values.skip) {
|
|
51
|
+
authProvider = 'none';
|
|
52
|
+
}
|
|
53
|
+
let databaseEngine;
|
|
54
|
+
if (values.engine !== undefined && !isDatabaseEngine(values.engine)) {
|
|
55
|
+
errors.push(`Invalid database engine: "${values.engine}". Expected: [ ${availableDatabaseEngines.join(', ')} ]`);
|
|
56
|
+
}
|
|
57
|
+
else if (values.engine !== undefined) {
|
|
58
|
+
databaseEngine = values.engine;
|
|
59
|
+
}
|
|
60
|
+
else if (values.skip) {
|
|
61
|
+
databaseEngine = 'none';
|
|
62
|
+
}
|
|
63
|
+
let databaseHost;
|
|
64
|
+
if (values.host !== undefined && !isDatabaseHost(values.host)) {
|
|
65
|
+
errors.push(`Invalid database host: "${values.host}". Expected: [ ${availableDatabaseHosts.join(', ')} ]`);
|
|
66
|
+
}
|
|
67
|
+
else if (values.host !== undefined) {
|
|
68
|
+
databaseHost = values.host;
|
|
69
|
+
}
|
|
70
|
+
else if (values.skip) {
|
|
71
|
+
databaseHost = 'none';
|
|
72
|
+
}
|
|
73
|
+
const { orm: ormValue } = values;
|
|
74
|
+
let orm;
|
|
75
|
+
if (ormValue !== undefined && !isORM(ormValue)) {
|
|
76
|
+
errors.push(`Invalid ORM: "${values.orm}". Expected: [ ${availableORMs.join(', ')} ]`);
|
|
77
|
+
}
|
|
78
|
+
else if (ormValue !== undefined) {
|
|
79
|
+
orm = ormValue;
|
|
80
|
+
}
|
|
81
|
+
else if (values.skip) {
|
|
82
|
+
orm = 'none';
|
|
83
|
+
}
|
|
84
|
+
const codeQualityTool = isCodeQualityTool(values.quality)
|
|
85
|
+
? values.quality
|
|
86
|
+
: undefined;
|
|
87
|
+
if (values.quality !== undefined && codeQualityTool === undefined) {
|
|
88
|
+
errors.push(`Invalid code quality tool: "${values.quality}". Expected: [ ${availableCodeQualityTools.join(', ')} ]`);
|
|
89
|
+
}
|
|
90
|
+
const directoryConfig = values.directory !== undefined && isDirectoryConfig(values.directory)
|
|
91
|
+
? values.directory
|
|
92
|
+
: undefined;
|
|
93
|
+
if (values.directory !== undefined && directoryConfig === undefined) {
|
|
94
|
+
errors.push(`Invalid directory configuration: "${values.directory}". Expected: [ ${availableDirectoryConfigurations.join(', ')} ]`);
|
|
95
|
+
}
|
|
96
|
+
for (const f of values.frontend || []) {
|
|
97
|
+
if (isFrontend(f))
|
|
98
|
+
continue;
|
|
99
|
+
errors.push(`Invalid frontend: "${f}". Expected: [ ${availableFrontends.join(', ')} ]`);
|
|
100
|
+
}
|
|
101
|
+
if (errors.length > 0) {
|
|
102
|
+
console.error(errors.join('\n'));
|
|
103
|
+
exit(1);
|
|
104
|
+
}
|
|
105
|
+
if (databaseEngine === 'none' && databaseHost !== 'none') {
|
|
106
|
+
console.warn('Warning: Setting the database host without a database engine has no effect.');
|
|
107
|
+
}
|
|
108
|
+
if (databaseEngine === 'none' && orm !== 'none') {
|
|
109
|
+
console.warn('Warning: Setting an ORM without a database engine has no effect.');
|
|
110
|
+
}
|
|
111
|
+
let databaseDirectory = values.database;
|
|
112
|
+
if (databaseEngine === 'none' && databaseDirectory !== undefined) {
|
|
113
|
+
console.warn('Warning: Setting a database directory without a database engine has no effect.');
|
|
114
|
+
databaseDirectory = undefined;
|
|
115
|
+
}
|
|
116
|
+
const frontendsWithDirectory = availableFrontends.filter((f) => values[f] !== undefined);
|
|
117
|
+
const frontendDirectories = {};
|
|
118
|
+
for (const frontend of frontendsWithDirectory) {
|
|
119
|
+
frontendDirectories[frontend] = values[frontend];
|
|
120
|
+
}
|
|
121
|
+
const originalFrontends = values.frontend;
|
|
122
|
+
const collector = new Set(originalFrontends ?? []);
|
|
123
|
+
for (const frontend of frontendsWithDirectory) {
|
|
124
|
+
collector.add(frontend);
|
|
125
|
+
}
|
|
126
|
+
values.frontend = collector.size > 0 ? Array.from(collector) : undefined;
|
|
127
|
+
if (values.plugin === undefined && values.skip) {
|
|
128
|
+
values.plugin = ['none'];
|
|
129
|
+
}
|
|
130
|
+
const plugins = values.plugin && values.plugin[0] === 'none' ? [] : values.plugin;
|
|
131
|
+
const hasTailwindFiles = values['tailwind-input'] !== undefined ||
|
|
132
|
+
values['tailwind-output'] !== undefined;
|
|
133
|
+
let tailwind = hasTailwindFiles
|
|
134
|
+
? {
|
|
135
|
+
input: values['tailwind-input'],
|
|
136
|
+
output: values['tailwind-output']
|
|
137
|
+
}
|
|
138
|
+
: undefined;
|
|
139
|
+
const useTailwind = values.tailwind ?? (hasTailwindFiles ? true : undefined);
|
|
140
|
+
if (useTailwind === false && hasTailwindFiles) {
|
|
141
|
+
console.warn('Warning: Tailwind CSS input/output files are specified but Tailwind is disabled.');
|
|
142
|
+
tailwind = undefined;
|
|
143
|
+
}
|
|
144
|
+
const argumentConfiguration = {
|
|
145
|
+
assetsDirectory: values.assets,
|
|
146
|
+
authProvider,
|
|
147
|
+
buildDirectory: values.build,
|
|
148
|
+
codeQualityTool,
|
|
149
|
+
databaseDirectory,
|
|
150
|
+
databaseEngine,
|
|
151
|
+
databaseHost,
|
|
152
|
+
directoryConfig,
|
|
153
|
+
frontendDirectories,
|
|
154
|
+
frontends: values.frontend?.filter(isFrontend),
|
|
155
|
+
initializeGitNow: values.git,
|
|
156
|
+
installDependenciesNow: values.npm,
|
|
157
|
+
orm,
|
|
158
|
+
plugins,
|
|
159
|
+
projectName,
|
|
160
|
+
tailwind,
|
|
161
|
+
useHTMLScripts: values['html-script'],
|
|
162
|
+
useTailwind
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
argumentConfiguration,
|
|
166
|
+
debug: values.debug,
|
|
167
|
+
help: values.help,
|
|
168
|
+
latest: values.lts
|
|
169
|
+
};
|
|
170
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { env } from 'node:process';
|
|
2
|
+
/**
|
|
3
|
+
* @author Adapted from the create-t3-app project
|
|
4
|
+
* @see https://github.com/t3-oss/create-t3-app
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
export const getUserPackageManager = () => {
|
|
8
|
+
// This environment variable is set by npm and yarn but pnpm seems less consistent
|
|
9
|
+
const userAgent = env.npm_config_user_agent;
|
|
10
|
+
if (userAgent) {
|
|
11
|
+
if (userAgent.startsWith('yarn')) {
|
|
12
|
+
return 'yarn';
|
|
13
|
+
}
|
|
14
|
+
else if (userAgent.startsWith('pnpm')) {
|
|
15
|
+
return 'pnpm';
|
|
16
|
+
}
|
|
17
|
+
else if (userAgent.startsWith('bun')) {
|
|
18
|
+
return 'bun';
|
|
19
|
+
}
|
|
20
|
+
return 'npm';
|
|
21
|
+
}
|
|
22
|
+
// If no user agent is set, assume npm
|
|
23
|
+
return 'npm';
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typescript": "5.8.3"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "rm -rf dist &&
|
|
41
|
+
"build": "rm -rf dist && tsc --project tsconfig.build.json && cp -R src/templates dist/templates",
|
|
42
42
|
"dev": "rm -rf absolutejs-project && bun run src/index.ts",
|
|
43
43
|
"format": "prettier --write \"./**/*.{js,jsx,ts,tsx,css,json,mjs,md,svelte,html,vue}\"",
|
|
44
44
|
"lint": "eslint ./",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"typecheck": "bun run tsc --noEmit"
|
|
48
48
|
},
|
|
49
49
|
"type": "module",
|
|
50
|
-
"version": "0.3.
|
|
50
|
+
"version": "0.3.2"
|
|
51
51
|
}
|