@quincarter/create-lit-app 1.2.0 → 1.3.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.
@@ -9,9 +9,9 @@ const __dirname = dirname(__filename);
9
9
  const scriptPath = join(__dirname, "..", "create-app-shell.sh");
10
10
 
11
11
  const child = spawn("bash", [scriptPath, ...process.argv.slice(2)], {
12
- stdio: "inherit",
12
+ stdio: "inherit",
13
13
  });
14
14
 
15
15
  child.on("exit", (code) => {
16
- process.exit(code ?? 0);
16
+ process.exit(code ?? 0);
17
17
  });
@@ -9,9 +9,9 @@ const __dirname = dirname(__filename);
9
9
  const scriptPath = join(__dirname, "..", "create-app-shell.sh");
10
10
 
11
11
  const child = spawn("bash", [scriptPath, ...process.argv.slice(2)], {
12
- stdio: "inherit",
12
+ stdio: "inherit",
13
13
  });
14
14
 
15
15
  child.on("exit", (code) => {
16
- process.exit(code ?? 0);
16
+ process.exit(code ?? 0);
17
17
  });
@@ -99,7 +99,7 @@ parse_args() {
99
99
  --no-install) RUN_INSTALL=false ;;
100
100
  -y|--yes) NON_INTERACTIVE=true ;;
101
101
  -v|--version)
102
- echo "@quincarter/create-lit-app v1.0.12"
102
+ echo "@quincarter/create-lit-app v1.3.0"
103
103
  exit 0
104
104
  ;;
105
105
  --help|-h)
@@ -140,6 +140,7 @@ parse_args() {
140
140
  exit 0
141
141
  ;;
142
142
  -*)
143
+ log_warn "Unknown option ignored: $arg"
143
144
  ;;
144
145
  *)
145
146
  if [ -z "$APP_NAME" ]; then
@@ -506,6 +507,19 @@ if [ "$ENABLE_TODOS" = true ]; then
506
507
  ENABLE_SIGNALS=true
507
508
  fi
508
509
 
510
+ # The MFE loader is handed to views through @lit/context, so the package and
511
+ # the loader context are needed even when the Context feature itself is off.
512
+ USE_LIT_CONTEXT=false
513
+ if [ "$ENABLE_CONTEXT" = true ] || [ "$ENABLE_MFE_LOADER" = true ]; then
514
+ USE_LIT_CONTEXT=true
515
+ fi
516
+
517
+ # APP_NAME becomes both the directory and the npm package name
518
+ if [[ ! "$APP_NAME" =~ ^[a-z0-9][a-z0-9._-]*$ ]]; then
519
+ log_error "Invalid app name '$APP_NAME' (use lowercase letters, digits, '.', '_' and '-')."
520
+ exit 1
521
+ fi
522
+
509
523
  TARGET_DIR="$(pwd)/$APP_NAME"
510
524
 
511
525
  if [ -d "$TARGET_DIR" ]; then
@@ -528,7 +542,7 @@ if [ "$ENABLE_ROUTER" = true ]; then
528
542
  \"@lit-labs/router\": \"^0.1.4\",
529
543
  \"urlpattern-polyfill\": \"^10.1.0\""
530
544
  fi
531
- if [ "$ENABLE_CONTEXT" = true ]; then
545
+ if [ "$USE_LIT_CONTEXT" = true ]; then
532
546
  DEPS="$DEPS,
533
547
  \"@lit/context\": \"^1.1.6\""
534
548
  fi
@@ -542,7 +556,7 @@ if [ "$ENABLE_CHARTS" = true ]; then
542
556
  \"chart.js\": \"^4.5.1\",
543
557
  \"chartjs-adapter-luxon\": \"^1.3.1\",
544
558
  \"luxon\": \"^3.7.2\",
545
- \"@kurkle/color\": \"^0.4.0\""
559
+ \"@kurkle/color\": \"^0.6.4\""
546
560
  fi
547
561
 
548
562
  cat <<EOF > package.json
@@ -554,7 +568,7 @@ cat <<EOF > package.json
554
568
  "scripts": {
555
569
  "start": "vite",
556
570
  "build": "tsc && vite build",
557
- "preview": "yarn build && vite preview",
571
+ "preview": "tsc && vite build && vite preview",
558
572
  "test": "vitest run",
559
573
  "fmt": "oxfmt",
560
574
  "fmt:check": "oxfmt --check",
@@ -565,14 +579,14 @@ cat <<EOF > package.json
565
579
  $DEPS
566
580
  },
567
581
  "devDependencies": {
568
- "@types/luxon": "^3.7.5",
582
+ "@types/luxon": "^3.7.6",
569
583
  "@types/mocha": "^10.0.10",
570
- "oxfmt": "^0.65.0",
571
- "oxlint": "^1.80.0",
584
+ "oxfmt": "^0.72.0",
585
+ "oxlint": "^1.87.0",
572
586
  "typescript": "^7.0.2",
573
- "vite": "^8.2.2",
574
- "vite-plugin-pwa": "^1.3.0",
575
- "vitest": "^4.1.11"
587
+ "vite": "^8.3.2",
588
+ "vite-plugin-pwa": "^2.0.0",
589
+ "vitest": "^5.0.3"
576
590
  }
577
591
  }
578
592
  EOF
@@ -973,6 +987,8 @@ import { createContext } from "@lit/context";
973
987
  import type { NavItem } from "../interfaces/navigation.interface";
974
988
  export const NavigationContext = createContext<NavItem[]>("navContext");
975
989
  EOF
990
+ fi
991
+ if [ "$USE_LIT_CONTEXT" = true ]; then
976
992
  cat <<'EOF' > src/shared/contexts/mfe-loader.context.ts
977
993
  import { createContext } from "@lit/context";
978
994
  import type { MfeLoader } from "../utilities/mfe-loader.utility";
@@ -1246,7 +1262,11 @@ import { property } from "lit/decorators.js";
1246
1262
  import { withBase } from "../../shared/configuration/base-path";
1247
1263
  import type { NavItem } from "../../shared/interfaces/navigation.interface";
1248
1264
  import { AppShellHeaderStyles } from "./app-shell-header.styles";
1249
- import "../theme-switcher/theme-switcher";
1265
+ EOF
1266
+ if [ "$ENABLE_THEME_SWITCHER" = true ]; then
1267
+ echo 'import "../theme-switcher/theme-switcher";' >> src/components/header/AppShellHeader.ts
1268
+ fi
1269
+ cat <<'EOF' >> src/components/header/AppShellHeader.ts
1250
1270
 
1251
1271
  export class AppShellHeader extends LitElement {
1252
1272
  @property({ attribute: "routes", type: Array })
@@ -1796,17 +1816,27 @@ export const AppShellStyles = css`
1796
1816
  `;
1797
1817
  EOF
1798
1818
 
1819
+ # @state is only used by the router/header nav list and the MFE loader
1820
+ DECORATORS="customElement, property"
1821
+ if [ "$ENABLE_ROUTER" = true ] || [ "$ENABLE_HEADER" = true ] || [ "$ENABLE_MFE_LOADER" = true ]; then
1822
+ DECORATORS="$DECORATORS, state"
1823
+ fi
1824
+
1799
1825
  IMPORTS="import { type HTMLTemplateResult, html, LitElement } from 'lit';
1800
- import { customElement, property, state } from 'lit/decorators.js';
1826
+ import { $DECORATORS } from 'lit/decorators.js';
1801
1827
  import { AppShellStyles } from './app-shell.styles';
1802
1828
  import type { NavItem } from './shared/interfaces/navigation.interface';
1803
1829
  import \"./shared/internal-views/404-not-found/page-not-found\";
1804
1830
  import \"./shared/internal-views/no-access/no-access\";
1805
1831
  import \"./shared/internal-views/under-construction/under-construction\";"
1806
1832
 
1833
+ if [ "$USE_LIT_CONTEXT" = true ]; then
1834
+ IMPORTS="$IMPORTS
1835
+ import { provide } from '@lit/context';"
1836
+ fi
1837
+
1807
1838
  if [ "$ENABLE_CONTEXT" = true ]; then
1808
1839
  IMPORTS="$IMPORTS
1809
- import { provide } from '@lit/context';
1810
1840
  import { AccessesContext } from './shared/contexts/accesses.context';
1811
1841
  import { NavigationContext } from './shared/contexts/navigation.context';"
1812
1842
  fi
@@ -1867,10 +1897,16 @@ cat <<EOF >> src/app-shell.ts
1867
1897
  EOF
1868
1898
  fi
1869
1899
 
1870
- if [ "$ENABLE_ROUTER" = true ]; then
1900
+ # The header binds to navRoutes, so it exists even without the router
1901
+ if [ "$ENABLE_ROUTER" = true ] || [ "$ENABLE_HEADER" = true ]; then
1871
1902
  cat <<EOF >> src/app-shell.ts
1872
1903
  @state()
1873
1904
  navRoutes: NavItem[] = [] as NavItem[];
1905
+ EOF
1906
+ fi
1907
+
1908
+ if [ "$ENABLE_ROUTER" = true ]; then
1909
+ cat <<EOF >> src/app-shell.ts
1874
1910
 
1875
1911
  @state()
1876
1912
  notAllowedRouteList: NavItem[] = [];
@@ -1889,7 +1925,9 @@ fi
1889
1925
 
1890
1926
  if [ "$ENABLE_ROUTER" = true ]; then
1891
1927
  cat <<EOF >> src/app-shell.ts
1892
- private _router = new Router(this, []);
1928
+ private _router = new Router(this, [], {
1929
+ fallback: { render: () => html\`<page-not-found></page-not-found>\` },
1930
+ });
1893
1931
  EOF
1894
1932
  fi
1895
1933
 
@@ -1983,8 +2021,12 @@ cat <<EOF >> src/app-shell.ts
1983
2021
  EOF
1984
2022
 
1985
2023
  if [ "$ENABLE_HEADER" = true ]; then
2024
+ HEADER_ATTRS=""
2025
+ if [ "$ENABLE_THEME_SWITCHER" = true ]; then
2026
+ HEADER_ATTRS=" enable-theme-switcher"
2027
+ fi
1986
2028
  cat <<EOF >> src/app-shell.ts
1987
- <app-shell-header .routes="\${this.navRoutes}" enable-theme-switcher>
2029
+ <app-shell-header .routes="\${this.navRoutes}"$HEADER_ATTRS>
1988
2030
  <main>
1989
2031
  EOF
1990
2032
  else
@@ -2172,7 +2214,7 @@ $(echo -e "$FEATURES")
2172
2214
 
2173
2215
  ### Prerequisites
2174
2216
 
2175
- Node.js v18+ and \`$PACKAGE_MANAGER\`.
2217
+ Node.js 20.19+ (or 22.12+) and \`$PACKAGE_MANAGER\`.
2176
2218
 
2177
2219
  ### Installation
2178
2220
 
@@ -2234,9 +2276,16 @@ if [ "$INIT_GIT" = true ]; then
2234
2276
  log_success "Git repository initialized."
2235
2277
  fi
2236
2278
 
2279
+ # The templates are not written in oxfmt's style, so format once the
2280
+ # formatter is available to leave the new project passing `fmt:check`.
2281
+ install_deps() {
2282
+ $PACKAGE_MANAGER install
2283
+ $PACKAGE_MANAGER run fmt >/dev/null 2>&1 || log_warn "Could not format the project; run '$PACKAGE_MANAGER run fmt' manually."
2284
+ }
2285
+
2237
2286
  if [ "$RUN_INSTALL" = true ]; then
2238
2287
  log_info "Installing dependencies with $PACKAGE_MANAGER..."
2239
- $PACKAGE_MANAGER install
2288
+ install_deps
2240
2289
  log_success "Dependencies installed."
2241
2290
  fi
2242
2291
 
@@ -2253,7 +2302,7 @@ if [ "$NON_INTERACTIVE" = false ]; then
2253
2302
  cd "$TARGET_DIR" || exit 1
2254
2303
  if [ "$RUN_INSTALL" = false ]; then
2255
2304
  log_info "Installing dependencies first..."
2256
- $PACKAGE_MANAGER install
2305
+ install_deps
2257
2306
  fi
2258
2307
  exec $PACKAGE_MANAGER start
2259
2308
  fi
@@ -17,7 +17,7 @@ Set the project directory and package name (default: my-app-shell).
17
17
  Starter template preset: \fBfull\fR | \fBblank\fR | \fBcustom\fR (default: full).
18
18
  .TP
19
19
  .BR \-\-pm= \fIPM\fR
20
- Package manager to use: \fByarn\fR | \fBnpm\fR (default: yarn).
20
+ Package manager to use: \fByarn\fR | \fBnpm\fR | \fBpnpm\fR (default: yarn).
21
21
  .TP
22
22
  .BR \-\-router ", " \-\-no-router
23
23
  Enable or disable @lit-labs/router (automatically enables @lit/context).
package/package.json CHANGED
@@ -1,23 +1,27 @@
1
1
  {
2
2
  "name": "@quincarter/create-lit-app",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Interactive CLI initializer for Lit Element App Shell architecture",
5
- "type": "module",
6
- "bin": {
7
- "create-lit-app": "./bin/create-lit-app.js",
8
- "create-app-shell": "./bin/create-lit-app.js"
9
- },
10
- "scripts": {
11
- "build": "tsx scripts/build-cli.ts",
12
- "prepare": "npm run build",
13
- "prepublishOnly": "npm run build",
14
- "changeset": "changeset",
15
- "version-packages": "changeset version",
16
- "release": "changeset publish"
5
+ "keywords": [
6
+ "app-shell",
7
+ "cli",
8
+ "create-lit-app",
9
+ "lit",
10
+ "lit-element",
11
+ "scaffold",
12
+ "signals",
13
+ "vite"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "Quin Carter",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/quincarter/app-shell-starter.git"
17
20
  },
18
21
  "man": "./man/create-lit-app.1",
19
- "publishConfig": {
20
- "access": "public"
22
+ "bin": {
23
+ "create-app-shell": "./bin/create-lit-app.js",
24
+ "create-lit-app": "./bin/create-lit-app.js"
21
25
  },
22
26
  "files": [
23
27
  "bin/",
@@ -25,26 +29,28 @@
25
29
  "man/",
26
30
  "README.md"
27
31
  ],
32
+ "type": "module",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "build": "tsx scripts/build-cli.ts",
38
+ "fmt": "oxfmt scripts bin package.json tsconfig.json",
39
+ "fmt:check": "oxfmt --check scripts bin package.json tsconfig.json",
40
+ "lint": "oxlint scripts bin",
41
+ "lint:fix": "oxlint --fix scripts bin",
42
+ "prepare": "npm run build",
43
+ "prepublishOnly": "npm run build",
44
+ "changeset": "changeset",
45
+ "version-packages": "changeset version",
46
+ "release": "changeset publish && git push --tags && tsx scripts/sync-releases.ts"
47
+ },
28
48
  "devDependencies": {
29
- "@changesets/cli": "^3.0.1",
30
- "@types/node": "^26.2.0",
31
- "tsx": "^4.23.12",
49
+ "@changesets/cli": "^3.0.3",
50
+ "@types/node": "^26.6.4",
51
+ "oxfmt": "^0.72.0",
52
+ "oxlint": "^1.87.0",
53
+ "tsx": "^4.23.15",
32
54
  "typescript": "^7.0.2"
33
- },
34
- "keywords": [
35
- "create-lit-app",
36
- "lit",
37
- "lit-element",
38
- "app-shell",
39
- "signals",
40
- "vite",
41
- "scaffold",
42
- "cli"
43
- ],
44
- "author": "Quin Carter",
45
- "license": "MIT",
46
- "repository": {
47
- "type": "git",
48
- "url": "git+https://github.com/quincarter/app-shell-starter.git"
49
55
  }
50
56
  }