@elaraai/create-east 1.0.18 → 1.0.19

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -43,6 +43,18 @@ var MANIFEST_FILE = "template.json";
43
43
  function substituteTokens(content, names) {
44
44
  return content.replaceAll("__PROJECT_NAME__", names.projectName).replaceAll("__DISPLAY_NAME__", names.displayName).replaceAll("__WORKSPACE_NAME__", names.workspaceName);
45
45
  }
46
+ function isPlainObject(v) {
47
+ return typeof v === "object" && v !== null && !Array.isArray(v);
48
+ }
49
+ function mergeInto(target, source) {
50
+ for (const [k, v] of Object.entries(source)) {
51
+ const existing = target[k];
52
+ if (isPlainObject(existing) && isPlainObject(v))
53
+ mergeInto(existing, v);
54
+ else
55
+ target[k] = v;
56
+ }
57
+ }
46
58
  function transformPackageJson(raw, names, version, manifest, enabled) {
47
59
  const pkg = JSON.parse(raw);
48
60
  pkg.name = `@elaraai/${names.projectName}`;
@@ -70,6 +82,10 @@ function transformPackageJson(raw, names, version, manifest, enabled) {
70
82
  else
71
83
  delete scripts?.[name];
72
84
  }
85
+ for (const [feature, spec] of Object.entries(manifest.features)) {
86
+ if (enabled(feature) && spec.packageJson)
87
+ mergeInto(pkg, spec.packageJson);
88
+ }
73
89
  }
74
90
  const pin = `^${version}`;
75
91
  for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
@@ -114,7 +130,12 @@ function scaffold(options) {
114
130
  throw new Error(`Template directory not found: ${templateDir}`);
115
131
  }
116
132
  const manifest = loadManifest(templateDir);
117
- const enabled = (feature) => options.features?.[feature] ?? manifest?.features[feature]?.default ?? true;
133
+ const enabled = (feature) => {
134
+ const spec = manifest?.features[feature];
135
+ if (spec?.allOf)
136
+ return spec.allOf.every(enabled);
137
+ return options.features?.[feature] ?? spec?.default ?? true;
138
+ };
118
139
  const skip = /* @__PURE__ */ new Set();
119
140
  const renames = {};
120
141
  if (manifest) {
@@ -129,6 +150,17 @@ function scaffold(options) {
129
150
  skip.add(f);
130
151
  }
131
152
  }
153
+ const variants = manifest.indexVariants ?? [];
154
+ if (variants.length > 0) {
155
+ const dest = (variants.find((v) => v.when.length === 0) ?? variants[variants.length - 1]).source;
156
+ const winner = variants.find((v) => v.when.every(enabled)) ?? variants[variants.length - 1];
157
+ for (const v of variants) {
158
+ if (v.source !== winner.source)
159
+ skip.add(v.source);
160
+ }
161
+ if (winner.source !== dest)
162
+ renames[winner.source] = dest;
163
+ }
132
164
  }
133
165
  const names = deriveNames(name, cwd);
134
166
  const inPlace = name === ".";
@@ -219,12 +251,15 @@ async function resolveFeatures(templateDir, args) {
219
251
  return {};
220
252
  const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
221
253
  const features = {};
222
- for (const [key, spec] of Object.entries(manifest.features))
254
+ for (const [key, spec] of Object.entries(manifest.features)) {
255
+ if (spec.allOf)
256
+ continue;
223
257
  features[key] = spec.default ?? true;
258
+ }
224
259
  const runnerKeys = Object.keys(manifest.features).filter((k) => k.startsWith("runner:"));
225
260
  const runnerName = (key) => key.slice("runner:".length);
226
261
  const runnersFlag = args.find((a) => a.startsWith("--runners="));
227
- const selectionFlags = ["--tests", "--no-tests", "--ui", "--no-ui", "--eslint", "--no-eslint"].some((f) => args.includes(f)) || Boolean(runnersFlag);
262
+ const selectionFlags = ["--tests", "--no-tests", "--ui", "--no-ui", "--platform", "--no-platform", "--eslint", "--no-eslint"].some((f) => args.includes(f)) || Boolean(runnersFlag);
228
263
  if (args.includes("--tests"))
229
264
  features["tests"] = true;
230
265
  if (args.includes("--no-tests"))
@@ -233,6 +268,10 @@ async function resolveFeatures(templateDir, args) {
233
268
  features["ui"] = true;
234
269
  if (args.includes("--no-ui"))
235
270
  features["ui"] = false;
271
+ if (args.includes("--platform"))
272
+ features["platform"] = true;
273
+ if (args.includes("--no-platform"))
274
+ features["platform"] = false;
236
275
  if (args.includes("--eslint"))
237
276
  features["eslint"] = true;
238
277
  if (args.includes("--no-eslint"))
@@ -264,6 +303,9 @@ async function resolveFeatures(templateDir, args) {
264
303
  for (const key of runnerKeys)
265
304
  features[key] = picks.has(runnerName(key));
266
305
  }
306
+ if ("platform" in manifest.features) {
307
+ features["platform"] = await askYesNo(rl, "Include a project-owned platform module (custom TS-East functions, plus Python when east-py is on)?", features["platform"]);
308
+ }
267
309
  if ("eslint" in manifest.features) {
268
310
  features["eslint"] = await askYesNo(rl, "Include ESLint with the East lint rules?", features["eslint"]);
269
311
  }
@@ -292,6 +334,7 @@ function printHelp(kind) {
292
334
  if (kind === "e3") {
293
335
  console.log(" --tests | --no-tests include test files (default: yes)");
294
336
  console.log(" --ui | --no-ui include east-ui + e3-ui UI components (default: no)");
337
+ console.log(" --platform | --no-platform include a project-owned platform module (TS-East; +Python when east-py is on) (default: no)");
295
338
  console.log(" --runners=east-node,east-c,east-py East runtimes to include (default: all)");
296
339
  }
297
340
  console.log("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elaraai/create-east",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Scaffold a new East project (AGPL-3.0, Node-only): npm create @elaraai/east",
5
5
  "type": "module",
6
6
  "bin": {