primate 0.39.0 → 0.39.1
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/lib/commands/init.js +47 -46
- package/package.json +2 -2
package/lib/commands/init.js
CHANGED
|
@@ -135,9 +135,7 @@ const command_init = async () => {
|
|
|
135
135
|
// files
|
|
136
136
|
await gitignore(target);
|
|
137
137
|
await tsconfig_json(target, { frontends });
|
|
138
|
-
await app_config(target, { frontends, backends, runtime });
|
|
139
|
-
if (with_i18n)
|
|
140
|
-
await i18n_config(target);
|
|
138
|
+
await app_config(target, { frontends, backends, runtime, with_i18n });
|
|
141
139
|
if (with_sessions)
|
|
142
140
|
await session_config(target);
|
|
143
141
|
if (is.defined(db))
|
|
@@ -170,58 +168,62 @@ async function gitignore(root) {
|
|
|
170
168
|
].join("\n");
|
|
171
169
|
await gi.write(content);
|
|
172
170
|
}
|
|
173
|
-
|
|
174
|
-
const config =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
.
|
|
171
|
+
function app_config_imports(choices) {
|
|
172
|
+
const config = `import config from "primate/config";`;
|
|
173
|
+
const frontend = choices.frontends.length > 0
|
|
174
|
+
? choices.frontends
|
|
175
|
+
.map(i => `import ${to_ident(i)} from "@primate/${i}";`)
|
|
176
|
+
.join("\n")
|
|
177
|
+
: false;
|
|
178
|
+
const backend = choices.backends.length > 0
|
|
179
|
+
? choices.backends
|
|
180
|
+
.map(i => `import ${to_ident(i)} from "@primate/${i}";`)
|
|
181
|
+
.join("\n")
|
|
182
|
+
: false;
|
|
183
|
+
const i18n = choices.with_i18n
|
|
184
|
+
? `import en from "../locales/en-US.ts";`
|
|
185
|
+
: false;
|
|
186
|
+
return [config, frontend, backend, i18n, "\n"].filter(Boolean).join("\n");
|
|
187
|
+
}
|
|
188
|
+
function app_config_export(choices) {
|
|
182
189
|
const modules = [
|
|
183
|
-
...
|
|
184
|
-
...
|
|
190
|
+
...choices.frontends.map((f) => `${to_ident(f)}()`),
|
|
191
|
+
...choices.backends.map((b) => `${to_ident(b)}()`),
|
|
185
192
|
];
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
const i18n = choices.with_i18n
|
|
194
|
+
? ` i18n: {
|
|
195
|
+
defaultLocale: "en-US",
|
|
196
|
+
locales: {
|
|
197
|
+
"en-US": en,
|
|
198
|
+
},
|
|
199
|
+
},\n`
|
|
200
|
+
: "";
|
|
201
|
+
return `export default config({
|
|
202
|
+
${i18n} modules: [
|
|
203
|
+
${modules.join(",\n ")},
|
|
192
204
|
],
|
|
193
205
|
});`;
|
|
194
|
-
await config.write(body);
|
|
195
206
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
async function app_config(root, choices) {
|
|
208
|
+
const config = root.join("config").join("app.ts");
|
|
209
|
+
await config.directory.create();
|
|
210
|
+
if (choices.with_i18n) {
|
|
211
|
+
const locale = root.join("locales").join("en-US.ts");
|
|
212
|
+
await locale.directory.create();
|
|
213
|
+
await locale.write(`import i18n from "primate/i18n";
|
|
214
|
+
|
|
204
215
|
export default i18n.locale({
|
|
205
|
-
hi: "
|
|
216
|
+
hi: "Hi",
|
|
206
217
|
placeheld: "Hello, {name}",
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
import i18n from "primate/i18n";
|
|
211
|
-
|
|
212
|
-
export default i18n({
|
|
213
|
-
defaultLocale: "en-US",
|
|
214
|
-
locales: {
|
|
215
|
-
"en-US": en,
|
|
216
|
-
},
|
|
217
|
-
});`;
|
|
218
|
-
await i18i.write(config);
|
|
218
|
+
});`);
|
|
219
|
+
}
|
|
220
|
+
await config.write(app_config_imports(choices) + app_config_export(choices));
|
|
219
221
|
}
|
|
220
222
|
async function session_config(root) {
|
|
221
223
|
const file = root.join("config").join("session.ts");
|
|
222
224
|
await file.directory.create();
|
|
223
225
|
const body = `import session from "primate/session";
|
|
224
|
-
export default session({})
|
|
226
|
+
export default session({}); `;
|
|
225
227
|
await file.write(body);
|
|
226
228
|
}
|
|
227
229
|
async function database_config(root, db) {
|
|
@@ -229,7 +231,7 @@ async function database_config(root, db) {
|
|
|
229
231
|
await file.directory.create();
|
|
230
232
|
const ident = to_ident(db);
|
|
231
233
|
const body = `import ${ident} from "@primate/${db}";
|
|
232
|
-
export default ${ident}()
|
|
234
|
+
export default ${ident} (); `;
|
|
233
235
|
await file.write(body);
|
|
234
236
|
}
|
|
235
237
|
async function package_json(root, c) {
|
|
@@ -266,7 +268,6 @@ function safe(s) {
|
|
|
266
268
|
.replace(/[^a-z0-9._-]/g, "") || "primate-app";
|
|
267
269
|
}
|
|
268
270
|
function to_ident(token) {
|
|
269
|
-
// turn tokens like "web-components" into valid identifiers: "web_components"
|
|
270
271
|
return token.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
271
272
|
}
|
|
272
273
|
function compute_packages(args) {
|
|
@@ -344,9 +345,9 @@ async function tsconfig_json(root, opts) {
|
|
|
344
345
|
compilerOptions: {
|
|
345
346
|
baseUrl: "${configDir}",
|
|
346
347
|
paths: {
|
|
348
|
+
"#app": ["config/app"],
|
|
347
349
|
"#session": ["config/session"],
|
|
348
350
|
"#db": ["config/db"],
|
|
349
|
-
"#i18n": ["config/i18n"],
|
|
350
351
|
"#config/*": ["config/*"],
|
|
351
352
|
"#view/*": ["views/*"],
|
|
352
353
|
"#component/*": ["components/*"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primate",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@rcompat/is": "^0.11.0",
|
|
28
28
|
"@rcompat/runtime": "^0.16.0",
|
|
29
29
|
"@rcompat/test": "^0.17.0",
|
|
30
|
-
"@primate/core": "^0.8.
|
|
30
|
+
"@primate/core": "^0.8.5"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@rcompat/type": "^0.17.0"
|