@aurostack/stacks 0.1.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.
- package/LICENSE +21 -0
- package/README.md +209 -0
- package/cli/src/extract.mjs +165 -0
- package/cli/src/fsx.mjs +197 -0
- package/cli/src/generate.mjs +235 -0
- package/cli/src/hooks.mjs +55 -0
- package/cli/src/manifest.mjs +163 -0
- package/cli/src/strip.mjs +208 -0
- package/cli/src/tokens.mjs +102 -0
- package/cli/stack.mjs +672 -0
- package/package.json +37 -0
- package/templates/nest-api/files/.bin/db.ts +123 -0
- package/templates/nest-api/files/.bin/dc.ts +74 -0
- package/templates/nest-api/files/.bin/helpers.ts +49 -0
- package/templates/nest-api/files/.bin/secrets.ts +68 -0
- package/templates/nest-api/files/.bin/start.ts +47 -0
- package/templates/nest-api/files/.dockerignore +7 -0
- package/templates/nest-api/files/.env.example +91 -0
- package/templates/nest-api/files/.env.test.example +75 -0
- package/templates/nest-api/files/.forgejo/workflows/build-and-push.yml +41 -0
- package/templates/nest-api/files/.forgejo/workflows/test-e2e.yml +83 -0
- package/templates/nest-api/files/.forgejo/workflows/test.yml +53 -0
- package/templates/nest-api/files/.npmrc.example +1 -0
- package/templates/nest-api/files/.nvmrc +1 -0
- package/templates/nest-api/files/.prettierrc +8 -0
- package/templates/nest-api/files/.swcrc +15 -0
- package/templates/nest-api/files/.watchmanconfig +3 -0
- package/templates/nest-api/files/.yarnrc.yml +1 -0
- package/templates/nest-api/files/Dockerfile +40 -0
- package/templates/nest-api/files/__mocks__/activation-twofa.js +7 -0
- package/templates/nest-api/files/__mocks__/activation.js +7 -0
- package/templates/nest-api/files/__mocks__/forgot-password.js +7 -0
- package/templates/nest-api/files/__mocks__/main-layout.js +7 -0
- package/templates/nest-api/files/__mocks__/password-changed.js +7 -0
- package/templates/nest-api/files/__mocks__/reset-password.js +7 -0
- package/templates/nest-api/files/__mocks__/set-password.js +7 -0
- package/templates/nest-api/files/__mocks__/welcome.js +7 -0
- package/templates/nest-api/files/_gitignore +62 -0
- package/templates/nest-api/files/compose.test.yml +33 -0
- package/templates/nest-api/files/compose.yml +39 -0
- package/templates/nest-api/files/emails/activation-twofa.tsx +58 -0
- package/templates/nest-api/files/emails/activation.tsx +36 -0
- package/templates/nest-api/files/emails/forgot-password.tsx +29 -0
- package/templates/nest-api/files/emails/main-layout.tsx +134 -0
- package/templates/nest-api/files/emails/password-changed.tsx +24 -0
- package/templates/nest-api/files/emails/reset-password.tsx +24 -0
- package/templates/nest-api/files/emails/set-password.tsx +25 -0
- package/templates/nest-api/files/emails/welcome.tsx +39 -0
- package/templates/nest-api/files/eslint.config.mjs +28 -0
- package/templates/nest-api/files/global.d.ts +5 -0
- package/templates/nest-api/files/nest-cli.json +8 -0
- package/templates/nest-api/files/package.json +150 -0
- package/templates/nest-api/files/prisma/schema/auth.prisma +75 -0
- package/templates/nest-api/files/prisma/schema/base.prisma +17 -0
- package/templates/nest-api/files/prisma/schema/enum.prisma +17 -0
- package/templates/nest-api/files/prisma/schema/notification.prisma +14 -0
- package/templates/nest-api/files/prisma.config.ts +13 -0
- package/templates/nest-api/files/public/.gitkeep +0 -0
- package/templates/nest-api/files/seeders/index.ts +27 -0
- package/templates/nest-api/files/seeders/util.ts +88 -0
- package/templates/nest-api/files/src/__tests__/app.controller.spec.ts +29 -0
- package/templates/nest-api/files/src/app.controller.ts +40 -0
- package/templates/nest-api/files/src/app.module.ts +268 -0
- package/templates/nest-api/files/src/app.resolver.ts +32 -0
- package/templates/nest-api/files/src/app.setup.ts +178 -0
- package/templates/nest-api/files/src/common/__tests__/auth.service.spec.ts +31 -0
- package/templates/nest-api/files/src/common/__tests__/cache.service.spec.ts +214 -0
- package/templates/nest-api/files/src/common/__tests__/config.service.spec.ts +56 -0
- package/templates/nest-api/files/src/common/__tests__/generator.service.spec.ts +114 -0
- package/templates/nest-api/files/src/common/__tests__/health.controller.spec.ts +72 -0
- package/templates/nest-api/files/src/common/__tests__/helpers.spec.ts +124 -0
- package/templates/nest-api/files/src/common/__tests__/mail.service.spec.ts +75 -0
- package/templates/nest-api/files/src/common/__tests__/prisma.indicator.spec.ts +39 -0
- package/templates/nest-api/files/src/common/__tests__/prisma.service.spec.ts +15 -0
- package/templates/nest-api/files/src/common/__tests__/records.spec.ts +87 -0
- package/templates/nest-api/files/src/common/__tests__/schemas.spec.ts +142 -0
- package/templates/nest-api/files/src/common/__tests__/throttler-storage.service.spec.ts +80 -0
- package/templates/nest-api/files/src/common/common.module.ts +72 -0
- package/templates/nest-api/files/src/common/constants/index.ts +2 -0
- package/templates/nest-api/files/src/common/constants/options.ts +52 -0
- package/templates/nest-api/files/src/common/constants/pino.ts +24 -0
- package/templates/nest-api/files/src/common/controllers/health.controller.ts +54 -0
- package/templates/nest-api/files/src/common/controllers/index.ts +2 -0
- package/templates/nest-api/files/src/common/controllers/metrics.controller.ts +21 -0
- package/templates/nest-api/files/src/common/decorators/index.ts +2 -0
- package/templates/nest-api/files/src/common/decorators/misc.decorator.ts +49 -0
- package/templates/nest-api/files/src/common/decorators/multi-part.decorator.ts +6 -0
- package/templates/nest-api/files/src/common/dto/filters.dto.ts +25 -0
- package/templates/nest-api/files/src/common/dto/index.ts +1 -0
- package/templates/nest-api/files/src/common/entity/index.ts +2 -0
- package/templates/nest-api/files/src/common/entity/ok.entity.ts +11 -0
- package/templates/nest-api/files/src/common/entity/pagination.entity.ts +24 -0
- package/templates/nest-api/files/src/common/exceptions/index.ts +1 -0
- package/templates/nest-api/files/src/common/exceptions/prisma.exception.ts +57 -0
- package/templates/nest-api/files/src/common/guards/feature-flag.guard.ts +51 -0
- package/templates/nest-api/files/src/common/guards/index.ts +1 -0
- package/templates/nest-api/files/src/common/interceptors/index.ts +1 -0
- package/templates/nest-api/files/src/common/interceptors/metrics.interceptor.ts +37 -0
- package/templates/nest-api/files/src/common/misc/helpers.ts +26 -0
- package/templates/nest-api/files/src/common/misc/index.ts +3 -0
- package/templates/nest-api/files/src/common/misc/origin-builder.ts +56 -0
- package/templates/nest-api/files/src/common/misc/prisma.indicator.ts +24 -0
- package/templates/nest-api/files/src/common/modules/index.ts +3 -0
- package/templates/nest-api/files/src/common/modules/logger.module.ts +104 -0
- package/templates/nest-api/files/src/common/modules/metrics.module.ts +28 -0
- package/templates/nest-api/files/src/common/modules/queue.module.ts +23 -0
- package/templates/nest-api/files/src/common/processors/index.ts +1 -0
- package/templates/nest-api/files/src/common/processors/mail/index.ts +47 -0
- package/templates/nest-api/files/src/common/processors/mail/process.ts +225 -0
- package/templates/nest-api/files/src/common/schemas/fields.ts +76 -0
- package/templates/nest-api/files/src/common/schemas/index.ts +1 -0
- package/templates/nest-api/files/src/common/services/auth-rate-limit.storage.ts +79 -0
- package/templates/nest-api/files/src/common/services/auth.service.ts +16 -0
- package/templates/nest-api/files/src/common/services/cache.service.ts +118 -0
- package/templates/nest-api/files/src/common/services/config.service.ts +388 -0
- package/templates/nest-api/files/src/common/services/feature-flag.service.ts +117 -0
- package/templates/nest-api/files/src/common/services/generator.service.ts +54 -0
- package/templates/nest-api/files/src/common/services/index.ts +10 -0
- package/templates/nest-api/files/src/common/services/logger.service.ts +14 -0
- package/templates/nest-api/files/src/common/services/mail.service.ts +44 -0
- package/templates/nest-api/files/src/common/services/prisma.service.ts +106 -0
- package/templates/nest-api/files/src/common/services/throttler-storage.service.ts +112 -0
- package/templates/nest-api/files/src/common/types/email.ts +55 -0
- package/templates/nest-api/files/src/common/types/index.ts +3 -0
- package/templates/nest-api/files/src/common/types/misc.ts +20 -0
- package/templates/nest-api/files/src/common/types/prisma.ts +18 -0
- package/templates/nest-api/files/src/common/utils/enum.ts +39 -0
- package/templates/nest-api/files/src/common/utils/helpers.ts +139 -0
- package/templates/nest-api/files/src/common/utils/index.ts +5 -0
- package/templates/nest-api/files/src/common/utils/ip.ts +22 -0
- package/templates/nest-api/files/src/common/utils/records.ts +66 -0
- package/templates/nest-api/files/src/common/utils/redis.keys.ts +31 -0
- package/templates/nest-api/files/src/lib/__tests__/access.spec.ts +33 -0
- package/templates/nest-api/files/src/lib/access.ts +114 -0
- package/templates/nest-api/files/src/lib/auth.ts +76 -0
- package/templates/nest-api/files/src/lib/rate-limit.ts +20 -0
- package/templates/nest-api/files/src/main.ts +28 -0
- package/templates/nest-api/files/src/media/__tests__/media.service.spec.ts +60 -0
- package/templates/nest-api/files/src/media/__tests__/s3.service.spec.ts +159 -0
- package/templates/nest-api/files/src/media/entity/file.entity.ts +7 -0
- package/templates/nest-api/files/src/media/entity/index.ts +1 -0
- package/templates/nest-api/files/src/media/media.module.ts +20 -0
- package/templates/nest-api/files/src/media/processors/index.ts +44 -0
- package/templates/nest-api/files/src/media/services/index.ts +2 -0
- package/templates/nest-api/files/src/media/services/media.service.ts +29 -0
- package/templates/nest-api/files/src/media/services/s3.service.ts +168 -0
- package/templates/nest-api/files/src/notifications/controllers/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/controllers/notifications.controller.ts +72 -0
- package/templates/nest-api/files/src/notifications/dto/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/dto/notification.dto.ts +11 -0
- package/templates/nest-api/files/src/notifications/entity/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/entity/notification.entity.ts +37 -0
- package/templates/nest-api/files/src/notifications/notifications.module.ts +11 -0
- package/templates/nest-api/files/src/notifications/services/index.ts +1 -0
- package/templates/nest-api/files/src/notifications/services/notifications.service.ts +98 -0
- package/templates/nest-api/files/src/realtime/__tests__/events.gateway.spec.ts +88 -0
- package/templates/nest-api/files/src/realtime/__tests__/rooms.spec.ts +29 -0
- package/templates/nest-api/files/src/realtime/__tests__/ws-permissions.guard.spec.ts +54 -0
- package/templates/nest-api/files/src/realtime/adapters/redis-io.adapter.ts +57 -0
- package/templates/nest-api/files/src/realtime/constants/index.ts +68 -0
- package/templates/nest-api/files/src/realtime/decorators/index.ts +1 -0
- package/templates/nest-api/files/src/realtime/decorators/ws-permissions.decorator.ts +14 -0
- package/templates/nest-api/files/src/realtime/gateways/events.gateway.ts +187 -0
- package/templates/nest-api/files/src/realtime/guards/index.ts +2 -0
- package/templates/nest-api/files/src/realtime/guards/ws-auth.guard.ts +20 -0
- package/templates/nest-api/files/src/realtime/guards/ws-permissions.guard.ts +35 -0
- package/templates/nest-api/files/src/realtime/misc/session-from-socket.ts +54 -0
- package/templates/nest-api/files/src/realtime/realtime.module.ts +26 -0
- package/templates/nest-api/files/src/realtime/services/presence.service.ts +56 -0
- package/templates/nest-api/files/src/realtime/services/realtime.service.ts +72 -0
- package/templates/nest-api/files/src/users/__tests__/current-user.controller.spec.ts +77 -0
- package/templates/nest-api/files/src/users/__tests__/current-user.service.spec.ts +159 -0
- package/templates/nest-api/files/src/users/__tests__/user.entity.spec.ts +175 -0
- package/templates/nest-api/files/src/users/__tests__/users.controller.spec.ts +89 -0
- package/templates/nest-api/files/src/users/__tests__/users.service.spec.ts +398 -0
- package/templates/nest-api/files/src/users/controllers/current-user.controller.ts +82 -0
- package/templates/nest-api/files/src/users/controllers/index.ts +2 -0
- package/templates/nest-api/files/src/users/controllers/users.controller.ts +40 -0
- package/templates/nest-api/files/src/users/decorators/index.ts +1 -0
- package/templates/nest-api/files/src/users/decorators/permissions.decorator.ts +24 -0
- package/templates/nest-api/files/src/users/dto/avatar.dto.ts +13 -0
- package/templates/nest-api/files/src/users/dto/filters.dto.ts +8 -0
- package/templates/nest-api/files/src/users/dto/index.ts +2 -0
- package/templates/nest-api/files/src/users/entity/index.ts +1 -0
- package/templates/nest-api/files/src/users/entity/user.entity.ts +53 -0
- package/templates/nest-api/files/src/users/services/current-user.service.ts +46 -0
- package/templates/nest-api/files/src/users/services/index.ts +2 -0
- package/templates/nest-api/files/src/users/services/users.service.ts +88 -0
- package/templates/nest-api/files/src/users/users.module.ts +10 -0
- package/templates/nest-api/files/test/app.spec.ts +102 -0
- package/templates/nest-api/files/test/auth.spec.ts +108 -0
- package/templates/nest-api/files/test/current-user.spec.ts +154 -0
- package/templates/nest-api/files/test/factory/app.ts +172 -0
- package/templates/nest-api/files/test/factory/constants.ts +22 -0
- package/templates/nest-api/files/test/factory/dto.ts +27 -0
- package/templates/nest-api/files/test/factory/entity.ts +70 -0
- package/templates/nest-api/files/test/factory/gen.ts +75 -0
- package/templates/nest-api/files/test/factory/util.ts +21 -0
- package/templates/nest-api/files/test/notifications.spec.ts +176 -0
- package/templates/nest-api/files/test/rate-limit.spec.ts +180 -0
- package/templates/nest-api/files/test/setup.ts +1 -0
- package/templates/nest-api/files/test/users.spec.ts +437 -0
- package/templates/nest-api/files/tsconfig.build.json +13 -0
- package/templates/nest-api/files/tsconfig.json +35 -0
- package/templates/nest-api/files/vitest.config.ts +53 -0
- package/templates/nest-api/template.json +452 -0
- package/templates/node-worker/files/.bin/db.ts +123 -0
- package/templates/node-worker/files/.bin/helpers.ts +49 -0
- package/templates/node-worker/files/.bin/secrets.ts +68 -0
- package/templates/node-worker/files/.dockerignore +5 -0
- package/templates/node-worker/files/.env.example +21 -0
- package/templates/node-worker/files/.forgejo/workflows/build-and-push.yml +41 -0
- package/templates/node-worker/files/.nvmrc +1 -0
- package/templates/node-worker/files/.prettierignore +4 -0
- package/templates/node-worker/files/.prettierrc +8 -0
- package/templates/node-worker/files/.yarnrc.yml +5 -0
- package/templates/node-worker/files/Dockerfile +63 -0
- package/templates/node-worker/files/Dockerfile.dev +59 -0
- package/templates/node-worker/files/_gitignore +48 -0
- package/templates/node-worker/files/ecosystem.config.cjs +10 -0
- package/templates/node-worker/files/eslint.config.js +37 -0
- package/templates/node-worker/files/package.json +67 -0
- package/templates/node-worker/files/prisma/_gitignore +1 -0
- package/templates/node-worker/files/prisma/schema/base.prisma +36 -0
- package/templates/node-worker/files/prisma.config.ts +13 -0
- package/templates/node-worker/files/src/config.ts +55 -0
- package/templates/node-worker/files/src/db.ts +118 -0
- package/templates/node-worker/files/src/index.ts +7 -0
- package/templates/node-worker/files/src/logger.ts +45 -0
- package/templates/node-worker/files/src/types.ts +23 -0
- package/templates/node-worker/files/src/utils/browser.ts +16 -0
- package/templates/node-worker/files/src/utils/date.ts +68 -0
- package/templates/node-worker/files/src/utils/helpers.ts +17 -0
- package/templates/node-worker/files/src/utils/number.ts +47 -0
- package/templates/node-worker/files/src/utils/worker.ts +29 -0
- package/templates/node-worker/files/src/workers/constants.ts +6 -0
- package/templates/node-worker/files/src/workers/example/index.ts +27 -0
- package/templates/node-worker/files/src/workers/index.ts +1 -0
- package/templates/node-worker/files/tsconfig.json +30 -0
- package/templates/node-worker/template.json +135 -0
- package/templates/py-worker/files/.dockerignore +176 -0
- package/templates/py-worker/files/.env.example +20 -0
- package/templates/py-worker/files/.forgejo/workflows/build-amd-push.yml +39 -0
- package/templates/py-worker/files/Dockerfile +10 -0
- package/templates/py-worker/files/README.md +3 -0
- package/templates/py-worker/files/_gitignore +176 -0
- package/templates/py-worker/files/config.py +89 -0
- package/templates/py-worker/files/models/decorators.py +42 -0
- package/templates/py-worker/files/models/enums.py +32 -0
- package/templates/py-worker/files/models/mixins.py +61 -0
- package/templates/py-worker/files/requirements.txt +18 -0
- package/templates/py-worker/files/utils/db.py +67 -0
- package/templates/py-worker/files/utils/logger.py +97 -0
- package/templates/py-worker/files/utils/misc.py +45 -0
- package/templates/py-worker/files/utils/worker.py +80 -0
- package/templates/py-worker/files/worker.py +41 -0
- package/templates/py-worker/files/workers/hello/process.py +22 -0
- package/templates/py-worker/template.json +87 -0
- package/templates/react-app/README.md +78 -0
- package/templates/react-app/derive.sh +128 -0
- package/templates/react-app/files/.bin/openapi.js +32 -0
- package/templates/react-app/files/.bin/secrets.js +47 -0
- package/templates/react-app/files/.dockerignore +16 -0
- package/templates/react-app/files/.editorconfig +12 -0
- package/templates/react-app/files/.env.example +34 -0
- package/templates/react-app/files/.forgejo/workflows/build-and-push.yml +55 -0
- package/templates/react-app/files/.forgejo/workflows/ci.yml +39 -0
- package/templates/react-app/files/.husky/pre-commit +1 -0
- package/templates/react-app/files/.nvmrc +1 -0
- package/templates/react-app/files/.prettierignore +6 -0
- package/templates/react-app/files/.prettierrc +9 -0
- package/templates/react-app/files/.yarnrc.yml +2 -0
- package/templates/react-app/files/Dockerfile +52 -0
- package/templates/react-app/files/_gitignore +33 -0
- package/templates/react-app/files/build.sh +53 -0
- package/templates/react-app/files/docker/nginx.conf +134 -0
- package/templates/react-app/files/eslint.config.mjs +75 -0
- package/templates/react-app/files/index.html +62 -0
- package/templates/react-app/files/openapi-ts.config.ts +22 -0
- package/templates/react-app/files/package.json +80 -0
- package/templates/react-app/files/src/app/nav.tsx +32 -0
- package/templates/react-app/files/src/app/providers.tsx +39 -0
- package/templates/react-app/files/src/app/router.tsx +142 -0
- package/templates/react-app/files/src/app/store.ts +20 -0
- package/templates/react-app/files/src/features/auth/components/auth-card.tsx +23 -0
- package/templates/react-app/files/src/features/auth/components/checkbox-field.tsx +32 -0
- package/templates/react-app/files/src/features/auth/components/google-button.tsx +41 -0
- package/templates/react-app/files/src/features/auth/components/or-divider.tsx +9 -0
- package/templates/react-app/files/src/features/auth/components/password-field.tsx +70 -0
- package/templates/react-app/files/src/features/auth/components/submit-button.tsx +16 -0
- package/templates/react-app/files/src/features/auth/lib/auth-actions.ts +68 -0
- package/templates/react-app/files/src/features/auth/lib/password-strength.ts +20 -0
- package/templates/react-app/files/src/features/auth/lib/redirect.ts +6 -0
- package/templates/react-app/files/src/features/auth/lib/schemas.ts +37 -0
- package/templates/react-app/files/src/features/seo/routes.ts +65 -0
- package/templates/react-app/files/src/lib/env.ts +28 -0
- package/templates/react-app/files/src/lib/paths.ts +58 -0
- package/templates/react-app/files/src/main.tsx +19 -0
- package/templates/react-app/files/src/routes/admin/home.tsx +24 -0
- package/templates/react-app/files/src/routes/auth/forgot-password.tsx +93 -0
- package/templates/react-app/files/src/routes/auth/login.tsx +87 -0
- package/templates/react-app/files/src/routes/auth/reset-password.tsx +83 -0
- package/templates/react-app/files/src/routes/auth/signup.tsx +117 -0
- package/templates/react-app/files/src/routes/auth/verified.tsx +31 -0
- package/templates/react-app/files/src/routes/auth/verify-email.tsx +97 -0
- package/templates/react-app/files/src/routes/home.tsx +17 -0
- package/templates/react-app/files/src/routes/legal/privacy.tsx +26 -0
- package/templates/react-app/files/src/routes/legal/terms.tsx +28 -0
- package/templates/react-app/files/src/routes/marketing/home.tsx +18 -0
- package/templates/react-app/files/src/routes/settings.tsx +10 -0
- package/templates/react-app/files/src/shared/api/base-api.ts +24 -0
- package/templates/react-app/files/src/shared/api/base-query.ts +29 -0
- package/templates/react-app/files/src/shared/api/config.ts +21 -0
- package/templates/react-app/files/src/shared/api/index.ts +15 -0
- package/templates/react-app/files/src/shared/api/realtime-events.ts +34 -0
- package/templates/react-app/files/src/shared/api/socket.ts +41 -0
- package/templates/react-app/files/src/shared/api/store.ts +39 -0
- package/templates/react-app/files/src/shared/api/upload-query.ts +115 -0
- package/templates/react-app/files/src/shared/auth/client.ts +27 -0
- package/templates/react-app/files/src/shared/auth/config.ts +28 -0
- package/templates/react-app/files/src/shared/auth/guards.tsx +75 -0
- package/templates/react-app/files/src/shared/auth/hooks.ts +13 -0
- package/templates/react-app/files/src/shared/auth/index.ts +20 -0
- package/templates/react-app/files/src/shared/auth/logout.ts +23 -0
- package/templates/react-app/files/src/shared/auth/provider.tsx +52 -0
- package/templates/react-app/files/src/shared/auth/redirect.ts +65 -0
- package/templates/react-app/files/src/shared/auth/slice.ts +54 -0
- package/templates/react-app/files/src/shared/hooks/index.ts +6 -0
- package/templates/react-app/files/src/shared/layouts/app-shell/app-shell.tsx +225 -0
- package/templates/react-app/files/src/shared/layouts/app-shell/user-menu.tsx +74 -0
- package/templates/react-app/files/src/shared/layouts/auth-layout.tsx +137 -0
- package/templates/react-app/files/src/shared/layouts/error-boundary.tsx +38 -0
- package/templates/react-app/files/src/shared/layouts/index.ts +23 -0
- package/templates/react-app/files/src/shared/layouts/marketing/marketing-layout.tsx +29 -0
- package/templates/react-app/files/src/shared/layouts/marketing/section-heading.tsx +38 -0
- package/templates/react-app/files/src/shared/layouts/marketing/section.tsx +30 -0
- package/templates/react-app/files/src/shared/layouts/states/app-shell-skeleton.tsx +47 -0
- package/templates/react-app/files/src/shared/layouts/states/empty.tsx +22 -0
- package/templates/react-app/files/src/shared/layouts/states/forbidden.tsx +14 -0
- package/templates/react-app/files/src/shared/layouts/states/loading.tsx +11 -0
- package/templates/react-app/files/src/shared/layouts/states/not-found.tsx +21 -0
- package/templates/react-app/files/src/shared/layouts/states/page-skeleton.tsx +39 -0
- package/templates/react-app/files/src/shared/layouts/states/route-fallback.tsx +26 -0
- package/templates/react-app/files/src/shared/layouts/states/state-screen.tsx +22 -0
- package/templates/react-app/files/src/shared/types/README.md +28 -0
- package/templates/react-app/files/src/shared/types/api/index.ts +9 -0
- package/templates/react-app/files/src/shared/types/api/zod.gen.ts +5 -0
- package/templates/react-app/files/src/shared/types/index.ts +4 -0
- package/templates/react-app/files/src/shared/ui/components/brand/logo.tsx +51 -0
- package/templates/react-app/files/src/shared/ui/components/brand/social-icons.tsx +37 -0
- package/templates/react-app/files/src/shared/ui/components/form/form.tsx +120 -0
- package/templates/react-app/files/src/shared/ui/components/ui/alert.tsx +25 -0
- package/templates/react-app/files/src/shared/ui/components/ui/button.tsx +43 -0
- package/templates/react-app/files/src/shared/ui/components/ui/calendar.tsx +78 -0
- package/templates/react-app/files/src/shared/ui/components/ui/card.tsx +44 -0
- package/templates/react-app/files/src/shared/ui/components/ui/checkbox.tsx +16 -0
- package/templates/react-app/files/src/shared/ui/components/ui/date-picker.tsx +76 -0
- package/templates/react-app/files/src/shared/ui/components/ui/input.tsx +22 -0
- package/templates/react-app/files/src/shared/ui/components/ui/label.tsx +19 -0
- package/templates/react-app/files/src/shared/ui/components/ui/modal.tsx +94 -0
- package/templates/react-app/files/src/shared/ui/components/ui/popover.tsx +31 -0
- package/templates/react-app/files/src/shared/ui/components/ui/progress.tsx +33 -0
- package/templates/react-app/files/src/shared/ui/components/ui/search-input.tsx +69 -0
- package/templates/react-app/files/src/shared/ui/components/ui/select.tsx +80 -0
- package/templates/react-app/files/src/shared/ui/components/ui/skeleton.tsx +12 -0
- package/templates/react-app/files/src/shared/ui/components/ui/sonner.tsx +23 -0
- package/templates/react-app/files/src/shared/ui/components/ui/spinner.tsx +8 -0
- package/templates/react-app/files/src/shared/ui/components/ui/textarea.tsx +22 -0
- package/templates/react-app/files/src/shared/ui/index.ts +45 -0
- package/templates/react-app/files/src/shared/ui/lib/utils.ts +7 -0
- package/templates/react-app/files/src/shared/ui/lib/zod-setup.ts +28 -0
- package/templates/react-app/files/src/shared/ui/meta/brand.ts +18 -0
- package/templates/react-app/files/src/shared/ui/meta/meta-context.ts +30 -0
- package/templates/react-app/files/src/shared/ui/meta/meta-provider.tsx +24 -0
- package/templates/react-app/files/src/shared/ui/meta/page-meta.tsx +69 -0
- package/templates/react-app/files/src/shared/ui/meta/use-meta-config.ts +11 -0
- package/templates/react-app/files/src/shared/ui/styles/globals.css +285 -0
- package/templates/react-app/files/src/shared/ui/styles/theme.css +48 -0
- package/templates/react-app/files/src/shared/ui/theme/init-script.ts +23 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-colors.ts +14 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-context.ts +60 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-provider.tsx +101 -0
- package/templates/react-app/files/src/shared/ui/theme/theme-toggle.tsx +40 -0
- package/templates/react-app/files/src/shared/ui/theme/use-theme.ts +11 -0
- package/templates/react-app/files/src/vite-env.d.ts +13 -0
- package/templates/react-app/files/tsconfig.json +26 -0
- package/templates/react-app/files/tsconfig.node.json +25 -0
- package/templates/react-app/files/vite.config.ts +344 -0
- package/templates/react-app/overrides/src/routes/auth/forgot-password.tsx +93 -0
- package/templates/react-app/overrides/src/routes/auth/login.tsx +87 -0
- package/templates/react-app/overrides/src/routes/auth/signup.tsx +117 -0
- package/templates/react-app/overrides/src/routes/auth/verified.tsx +31 -0
- package/templates/react-app/overrides/src/routes/auth/verify-email.tsx +97 -0
- package/templates/react-app/overrides/src/shared/auth/config.ts +28 -0
- package/templates/react-app/overrides/src/shared/auth/guards.tsx +75 -0
- package/templates/react-app/overrides/src/shared/auth/index.ts +20 -0
- package/templates/react-app/overrides/src/shared/auth/redirect.ts +65 -0
- package/templates/react-app/overrides/src/shared/hooks/index.ts +6 -0
- package/templates/react-app/overrides/src/shared/types/README.md +28 -0
- package/templates/react-app/template.json +222 -0
- package/templates/react-monorepo/files/.dockerignore +19 -0
- package/templates/react-monorepo/files/.editorconfig +12 -0
- package/templates/react-monorepo/files/.forgejo/workflows/build-and-push.yml +98 -0
- package/templates/react-monorepo/files/.forgejo/workflows/ci.yml +35 -0
- package/templates/react-monorepo/files/.husky/pre-commit +1 -0
- package/templates/react-monorepo/files/.nvmrc +1 -0
- package/templates/react-monorepo/files/.prettierignore +6 -0
- package/templates/react-monorepo/files/.prettierrc +9 -0
- package/templates/react-monorepo/files/.yarnrc.yml +2 -0
- package/templates/react-monorepo/files/Dockerfile +90 -0
- package/templates/react-monorepo/files/_gitignore +35 -0
- package/templates/react-monorepo/files/apps/admin/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/admin/.env.example +16 -0
- package/templates/react-monorepo/files/apps/admin/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/admin/index.html +57 -0
- package/templates/react-monorepo/files/apps/admin/package.json +33 -0
- package/templates/react-monorepo/files/apps/admin/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/admin/src/app/nav.tsx +14 -0
- package/templates/react-monorepo/files/apps/admin/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/admin/src/app/router.tsx +50 -0
- package/templates/react-monorepo/files/apps/admin/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/admin/src/lib/env.ts +12 -0
- package/templates/react-monorepo/files/apps/admin/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/admin/src/routes/home.tsx +17 -0
- package/templates/react-monorepo/files/apps/admin/src/routes/settings.tsx +10 -0
- package/templates/react-monorepo/files/apps/admin/src/vite-env.d.ts +14 -0
- package/templates/react-monorepo/files/apps/admin/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/admin/vite.config.ts +13 -0
- package/templates/react-monorepo/files/apps/auth/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/auth/.env.example +16 -0
- package/templates/react-monorepo/files/apps/auth/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/auth/index.html +57 -0
- package/templates/react-monorepo/files/apps/auth/package.json +32 -0
- package/templates/react-monorepo/files/apps/auth/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/auth/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/auth/src/app/router.tsx +19 -0
- package/templates/react-monorepo/files/apps/auth/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/auth/src/components/auth-card.tsx +23 -0
- package/templates/react-monorepo/files/apps/auth/src/components/checkbox-field.tsx +32 -0
- package/templates/react-monorepo/files/apps/auth/src/components/google-button.tsx +41 -0
- package/templates/react-monorepo/files/apps/auth/src/components/or-divider.tsx +9 -0
- package/templates/react-monorepo/files/apps/auth/src/components/password-field.tsx +70 -0
- package/templates/react-monorepo/files/apps/auth/src/components/submit-button.tsx +16 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/auth-actions.ts +68 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/env.ts +8 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/password-strength.ts +20 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/redirect.ts +6 -0
- package/templates/react-monorepo/files/apps/auth/src/lib/schemas.ts +37 -0
- package/templates/react-monorepo/files/apps/auth/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/forgot-password.tsx +91 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/login.tsx +82 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/reset-password.tsx +83 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/signup.tsx +117 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/verified.tsx +30 -0
- package/templates/react-monorepo/files/apps/auth/src/routes/verify-email.tsx +96 -0
- package/templates/react-monorepo/files/apps/auth/src/vite-env.d.ts +14 -0
- package/templates/react-monorepo/files/apps/auth/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/auth/vite.config.ts +13 -0
- package/templates/react-monorepo/files/apps/client/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/client/.env.example +16 -0
- package/templates/react-monorepo/files/apps/client/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/client/index.html +57 -0
- package/templates/react-monorepo/files/apps/client/package.json +35 -0
- package/templates/react-monorepo/files/apps/client/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/client/src/app/nav.tsx +14 -0
- package/templates/react-monorepo/files/apps/client/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/client/src/app/router.tsx +50 -0
- package/templates/react-monorepo/files/apps/client/src/app/store.ts +15 -0
- package/templates/react-monorepo/files/apps/client/src/lib/env.ts +12 -0
- package/templates/react-monorepo/files/apps/client/src/main.tsx +19 -0
- package/templates/react-monorepo/files/apps/client/src/routes/home.tsx +17 -0
- package/templates/react-monorepo/files/apps/client/src/routes/settings.tsx +10 -0
- package/templates/react-monorepo/files/apps/client/src/vite-env.d.ts +15 -0
- package/templates/react-monorepo/files/apps/client/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/client/vite.config.ts +120 -0
- package/templates/react-monorepo/files/apps/landing/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/apps/landing/.env.example +20 -0
- package/templates/react-monorepo/files/apps/landing/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/apps/landing/index.html +51 -0
- package/templates/react-monorepo/files/apps/landing/package.json +33 -0
- package/templates/react-monorepo/files/apps/landing/src/App.tsx +3 -0
- package/templates/react-monorepo/files/apps/landing/src/app/providers.tsx +42 -0
- package/templates/react-monorepo/files/apps/landing/src/app/router.tsx +21 -0
- package/templates/react-monorepo/files/apps/landing/src/app/store.ts +18 -0
- package/templates/react-monorepo/files/apps/landing/src/features/seo/routes.ts +65 -0
- package/templates/react-monorepo/files/apps/landing/src/lib/env.ts +10 -0
- package/templates/react-monorepo/files/apps/landing/src/main.tsx +14 -0
- package/templates/react-monorepo/files/apps/landing/src/routes/home.tsx +18 -0
- package/templates/react-monorepo/files/apps/landing/src/vite-env.d.ts +15 -0
- package/templates/react-monorepo/files/apps/landing/tsconfig.json +10 -0
- package/templates/react-monorepo/files/apps/landing/vite.config.ts +169 -0
- package/templates/react-monorepo/files/build.sh +61 -0
- package/templates/react-monorepo/files/docker/nginx.conf +136 -0
- package/templates/react-monorepo/files/package.json +37 -0
- package/templates/react-monorepo/files/packages/.gitkeep +0 -0
- package/templates/react-monorepo/files/packages/api/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/api/package.json +30 -0
- package/templates/react-monorepo/files/packages/api/src/base-api.ts +24 -0
- package/templates/react-monorepo/files/packages/api/src/base-query.ts +29 -0
- package/templates/react-monorepo/files/packages/api/src/config.ts +21 -0
- package/templates/react-monorepo/files/packages/api/src/index.ts +15 -0
- package/templates/react-monorepo/files/packages/api/src/realtime-events.ts +34 -0
- package/templates/react-monorepo/files/packages/api/src/socket.ts +41 -0
- package/templates/react-monorepo/files/packages/api/src/store.ts +39 -0
- package/templates/react-monorepo/files/packages/api/src/upload-query.ts +115 -0
- package/templates/react-monorepo/files/packages/api/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/auth/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/auth/package.json +33 -0
- package/templates/react-monorepo/files/packages/auth/src/client.ts +27 -0
- package/templates/react-monorepo/files/packages/auth/src/config.ts +22 -0
- package/templates/react-monorepo/files/packages/auth/src/guards.tsx +61 -0
- package/templates/react-monorepo/files/packages/auth/src/hooks.ts +13 -0
- package/templates/react-monorepo/files/packages/auth/src/index.ts +20 -0
- package/templates/react-monorepo/files/packages/auth/src/logout.ts +23 -0
- package/templates/react-monorepo/files/packages/auth/src/provider.tsx +52 -0
- package/templates/react-monorepo/files/packages/auth/src/redirect.ts +37 -0
- package/templates/react-monorepo/files/packages/auth/src/slice.ts +54 -0
- package/templates/react-monorepo/files/packages/auth/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/config/README.md +47 -0
- package/templates/react-monorepo/files/packages/config/eslint/base.mjs +83 -0
- package/templates/react-monorepo/files/packages/config/package.json +37 -0
- package/templates/react-monorepo/files/packages/config/tailwind/theme.css +48 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/base.json +22 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/node.json +9 -0
- package/templates/react-monorepo/files/packages/config/tsconfig/react.json +9 -0
- package/templates/react-monorepo/files/packages/config/vite/index.d.ts +18 -0
- package/templates/react-monorepo/files/packages/config/vite/index.mjs +129 -0
- package/templates/react-monorepo/files/packages/hooks/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/hooks/package.json +16 -0
- package/templates/react-monorepo/files/packages/hooks/src/index.ts +3 -0
- package/templates/react-monorepo/files/packages/hooks/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/layouts/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/layouts/package.json +30 -0
- package/templates/react-monorepo/files/packages/layouts/src/app-shell/app-shell.tsx +225 -0
- package/templates/react-monorepo/files/packages/layouts/src/app-shell/user-menu.tsx +74 -0
- package/templates/react-monorepo/files/packages/layouts/src/auth-layout.tsx +137 -0
- package/templates/react-monorepo/files/packages/layouts/src/error-boundary.tsx +38 -0
- package/templates/react-monorepo/files/packages/layouts/src/index.ts +23 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/marketing-layout.tsx +29 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/section-heading.tsx +38 -0
- package/templates/react-monorepo/files/packages/layouts/src/marketing/section.tsx +30 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/app-shell-skeleton.tsx +47 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/empty.tsx +22 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/forbidden.tsx +14 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/loading.tsx +11 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/not-found.tsx +21 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/page-skeleton.tsx +39 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/route-fallback.tsx +26 -0
- package/templates/react-monorepo/files/packages/layouts/src/states/state-screen.tsx +22 -0
- package/templates/react-monorepo/files/packages/layouts/tsconfig.json +4 -0
- package/templates/react-monorepo/files/packages/types/.bin/openapi.js +32 -0
- package/templates/react-monorepo/files/packages/types/.bin/secrets.js +57 -0
- package/templates/react-monorepo/files/packages/types/README.md +28 -0
- package/templates/react-monorepo/files/packages/types/eslint.config.mjs +3 -0
- package/templates/react-monorepo/files/packages/types/openapi-ts.config.ts +22 -0
- package/templates/react-monorepo/files/packages/types/package.json +29 -0
- package/templates/react-monorepo/files/packages/types/src/index.ts +4 -0
- package/templates/react-monorepo/files/packages/types/src/types/api/index.ts +9 -0
- package/templates/react-monorepo/files/packages/types/src/types/api/zod.gen.ts +5 -0
- package/templates/react-monorepo/files/packages/types/tsconfig.json +7 -0
- package/templates/react-monorepo/files/packages/ui/components.json +21 -0
- package/templates/react-monorepo/files/packages/ui/eslint.config.mjs +13 -0
- package/templates/react-monorepo/files/packages/ui/package.json +44 -0
- package/templates/react-monorepo/files/packages/ui/src/components/brand/logo.tsx +51 -0
- package/templates/react-monorepo/files/packages/ui/src/components/brand/social-icons.tsx +37 -0
- package/templates/react-monorepo/files/packages/ui/src/components/form/form.tsx +120 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/alert.tsx +25 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/button.tsx +43 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/calendar.tsx +78 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/card.tsx +44 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/checkbox.tsx +16 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/date-picker.tsx +76 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/input.tsx +22 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/label.tsx +19 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/modal.tsx +94 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/popover.tsx +31 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/progress.tsx +33 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/search-input.tsx +69 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/select.tsx +80 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/skeleton.tsx +12 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/sonner.tsx +23 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/spinner.tsx +8 -0
- package/templates/react-monorepo/files/packages/ui/src/components/ui/textarea.tsx +22 -0
- package/templates/react-monorepo/files/packages/ui/src/index.ts +45 -0
- package/templates/react-monorepo/files/packages/ui/src/lib/utils.ts +7 -0
- package/templates/react-monorepo/files/packages/ui/src/lib/zod-setup.ts +28 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/brand.ts +18 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/meta-context.ts +30 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/meta-provider.tsx +24 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/page-meta.tsx +69 -0
- package/templates/react-monorepo/files/packages/ui/src/meta/use-meta-config.ts +11 -0
- package/templates/react-monorepo/files/packages/ui/src/styles/globals.css +285 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/init-script.ts +23 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-colors.ts +14 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-context.ts +60 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-provider.tsx +101 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/theme-toggle.tsx +40 -0
- package/templates/react-monorepo/files/packages/ui/src/theme/use-theme.ts +11 -0
- package/templates/react-monorepo/files/packages/ui/tsconfig.json +9 -0
- package/templates/react-monorepo/files/turbo.json +24 -0
- package/templates/react-monorepo/template.json +230 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generation: templates/<t>/files -> a new project directory.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline per file:
|
|
5
|
+
* 1. drop it entirely if a disabled feature owns it (`features.x.files`)
|
|
6
|
+
* 2. rewrite its path through `pathReplacements`
|
|
7
|
+
* 3. strip `@feature` regions for disabled features
|
|
8
|
+
* 4. apply `replacements` (renaming the project)
|
|
9
|
+
* 5. prune package.json keys belonging to disabled features
|
|
10
|
+
*/
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import {
|
|
14
|
+
walk,
|
|
15
|
+
matcher,
|
|
16
|
+
isTextFile,
|
|
17
|
+
readText,
|
|
18
|
+
writeText,
|
|
19
|
+
copyBinary,
|
|
20
|
+
DEFAULT_SKIP_DIRS
|
|
21
|
+
} from './fsx.mjs';
|
|
22
|
+
import { stripFeatures, evalExpr } from './strip.mjs';
|
|
23
|
+
import {
|
|
24
|
+
buildContext,
|
|
25
|
+
interpolate,
|
|
26
|
+
compileReplacements,
|
|
27
|
+
applyReplacements
|
|
28
|
+
} from './tokens.mjs';
|
|
29
|
+
import { resolveFeatures } from './manifest.mjs';
|
|
30
|
+
|
|
31
|
+
/** Detect a JSON file's existing indentation so we round-trip it faithfully. */
|
|
32
|
+
function detectIndent(raw) {
|
|
33
|
+
const m = raw.match(/\n([ \t]+)"/);
|
|
34
|
+
if (!m) return '\t';
|
|
35
|
+
return m[1].includes('\t') ? '\t' : m[1];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Remove dependency / script keys owned by disabled features.
|
|
40
|
+
* `spec` is either { dependencies, devDependencies, scripts } (implicitly
|
|
41
|
+
* targeting `package.json` at the project root) or an array of such objects
|
|
42
|
+
* each carrying a `file`.
|
|
43
|
+
*/
|
|
44
|
+
function collectPrunes(manifest, enabled) {
|
|
45
|
+
/** @type {Map<string, { dependencies: Set<string>, devDependencies: Set<string>, scripts: Set<string> }>} */
|
|
46
|
+
const byFile = new Map();
|
|
47
|
+
|
|
48
|
+
const add = (file, spec) => {
|
|
49
|
+
if (!byFile.has(file)) {
|
|
50
|
+
byFile.set(file, {
|
|
51
|
+
dependencies: new Set(),
|
|
52
|
+
devDependencies: new Set(),
|
|
53
|
+
scripts: new Set()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const bucket = byFile.get(file);
|
|
57
|
+
for (const key of ['dependencies', 'devDependencies', 'scripts']) {
|
|
58
|
+
for (const entry of spec[key] || []) bucket[key].add(entry);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
for (const [name, def] of Object.entries(manifest.features)) {
|
|
63
|
+
if (enabled.has(name) || !def.packageJson) continue;
|
|
64
|
+
const specs = Array.isArray(def.packageJson)
|
|
65
|
+
? def.packageJson
|
|
66
|
+
: [def.packageJson];
|
|
67
|
+
for (const spec of specs) add(spec.file || 'package.json', spec);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return byFile;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Remove requirement lines owned by disabled features. Matching is on the
|
|
75
|
+
* distribution name only, so a pin (`SQLAlchemy==2.0.50`) or an extra
|
|
76
|
+
* (`uvicorn[standard]`) is removed by naming just `SQLAlchemy` / `uvicorn`.
|
|
77
|
+
*/
|
|
78
|
+
function collectRequirementPrunes(manifest, enabled) {
|
|
79
|
+
const drop = new Set();
|
|
80
|
+
for (const [name, def] of Object.entries(manifest.features)) {
|
|
81
|
+
if (enabled.has(name) || !def.requirements) continue;
|
|
82
|
+
for (const req of def.requirements) drop.add(req.toLowerCase());
|
|
83
|
+
}
|
|
84
|
+
return drop;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function pruneRequirements(raw, drop) {
|
|
88
|
+
if (drop.size === 0) return { raw, removed: 0 };
|
|
89
|
+
let removed = 0;
|
|
90
|
+
const kept = raw.split(/\r?\n/).filter((line) => {
|
|
91
|
+
const name = line.trim().split(/[=<>!~\[; ]/)[0].toLowerCase();
|
|
92
|
+
if (name && drop.has(name)) {
|
|
93
|
+
removed++;
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
});
|
|
98
|
+
return { raw: kept.join('\n'), removed };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function prunePackageJson(raw, prune) {
|
|
102
|
+
let pkg;
|
|
103
|
+
try {
|
|
104
|
+
pkg = JSON.parse(raw);
|
|
105
|
+
} catch {
|
|
106
|
+
// Not valid JSON after substitution — leave it and let the caller notice.
|
|
107
|
+
return { raw, removed: 0 };
|
|
108
|
+
}
|
|
109
|
+
const indent = detectIndent(raw);
|
|
110
|
+
let removed = 0;
|
|
111
|
+
for (const key of ['dependencies', 'devDependencies', 'scripts']) {
|
|
112
|
+
if (!pkg[key]) continue;
|
|
113
|
+
for (const entry of prune[key]) {
|
|
114
|
+
if (entry in pkg[key]) {
|
|
115
|
+
delete pkg[key][entry];
|
|
116
|
+
removed++;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (Object.keys(pkg[key]).length === 0) delete pkg[key];
|
|
120
|
+
}
|
|
121
|
+
return { raw: JSON.stringify(pkg, null, indent) + '\n', removed };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function generate(manifest, target, options) {
|
|
125
|
+
const { dryRun = false, force = false } = options;
|
|
126
|
+
const enabled = resolveFeatures(manifest, options);
|
|
127
|
+
const ctx = buildContext({
|
|
128
|
+
name: options.name,
|
|
129
|
+
scope: options.scope,
|
|
130
|
+
description: options.description,
|
|
131
|
+
port: options.port ?? manifest.defaults?.port,
|
|
132
|
+
author: options.author
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const filesDir = manifest.__filesDir;
|
|
136
|
+
if (!fs.existsSync(filesDir)) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`Template "${manifest.name}" has no files/ directory yet. ` +
|
|
139
|
+
`Run: stack extract ${manifest.name}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!dryRun && fs.existsSync(target) && fs.readdirSync(target).length > 0 && !force) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Target ${target} is not empty. Pass --force to write into it anyway.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// A file owned by any disabled feature is dropped wholesale.
|
|
150
|
+
const dropMatchers = [];
|
|
151
|
+
for (const [name, def] of Object.entries(manifest.features)) {
|
|
152
|
+
if (enabled.has(name)) continue;
|
|
153
|
+
if (def.files?.length) dropMatchers.push(matcher(def.files));
|
|
154
|
+
}
|
|
155
|
+
const isDropped = (rel) => dropMatchers.some((m) => m(rel));
|
|
156
|
+
|
|
157
|
+
const replacements = compileReplacements(manifest.replacements, ctx);
|
|
158
|
+
const pathReplacements = compileReplacements(manifest.pathReplacements, ctx);
|
|
159
|
+
const prunes = collectPrunes(manifest, enabled);
|
|
160
|
+
const requirementPrunes = collectRequirementPrunes(manifest, enabled);
|
|
161
|
+
|
|
162
|
+
const all = walk(filesDir, { skipDirs: DEFAULT_SKIP_DIRS });
|
|
163
|
+
const report = {
|
|
164
|
+
enabled: [...enabled].sort(),
|
|
165
|
+
disabled: Object.keys(manifest.features).filter((f) => !enabled.has(f)).sort(),
|
|
166
|
+
written: [],
|
|
167
|
+
dropped: [],
|
|
168
|
+
pruned: 0
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
for (const rel of all) {
|
|
172
|
+
if (isDropped(rel)) {
|
|
173
|
+
report.dropped.push(rel);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let destRel = applyReplacements(rel, pathReplacements, enabled, evalExpr);
|
|
178
|
+
destRel = interpolate(destRel, ctx);
|
|
179
|
+
// `.gitignore` cannot ship inside a template dir that is itself
|
|
180
|
+
// git-tracked without being honoured, so templates store it renamed.
|
|
181
|
+
destRel = destRel.replace(/(^|\/)_gitignore$/, '$1.gitignore');
|
|
182
|
+
destRel = destRel.replace(/(^|\/)_npmrc$/, '$1.npmrc');
|
|
183
|
+
|
|
184
|
+
const from = path.join(filesDir, rel);
|
|
185
|
+
const to = path.join(target, destRel);
|
|
186
|
+
|
|
187
|
+
if (!isTextFile(rel)) {
|
|
188
|
+
if (!dryRun) copyBinary(from, to);
|
|
189
|
+
report.written.push(destRel);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let content = readText(from);
|
|
194
|
+
const stripped = stripFeatures(content, enabled);
|
|
195
|
+
content = stripped.content;
|
|
196
|
+
content = applyReplacements(content, replacements, enabled, evalExpr);
|
|
197
|
+
|
|
198
|
+
const prune = prunes.get(destRel);
|
|
199
|
+
if (prune && path.basename(destRel) === 'package.json') {
|
|
200
|
+
const result = prunePackageJson(content, prune);
|
|
201
|
+
content = result.raw;
|
|
202
|
+
report.pruned += result.removed;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (path.basename(destRel) === 'requirements.txt') {
|
|
206
|
+
const result = pruneRequirements(content, requirementPrunes);
|
|
207
|
+
content = result.raw;
|
|
208
|
+
report.pruned += result.removed;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!dryRun) writeText(to, content);
|
|
212
|
+
report.written.push(destRel);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!dryRun) {
|
|
216
|
+
writeText(
|
|
217
|
+
path.join(target, 'stack.json'),
|
|
218
|
+
JSON.stringify(
|
|
219
|
+
{
|
|
220
|
+
template: manifest.name,
|
|
221
|
+
templateVersion: manifest.version || '0.1.0',
|
|
222
|
+
stackVersion: options.toolVersion,
|
|
223
|
+
generatedAt: new Date().toISOString(),
|
|
224
|
+
name: ctx.name,
|
|
225
|
+
scope: ctx.scope,
|
|
226
|
+
features: report.enabled
|
|
227
|
+
},
|
|
228
|
+
null,
|
|
229
|
+
'\t'
|
|
230
|
+
) + '\n'
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return { report, ctx, enabled };
|
|
235
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-generation hooks: install deps, generate the Prisma client, init git.
|
|
3
|
+
*
|
|
4
|
+
* A hook is { run, when?, cwd?, optional?, title? }. `when` is a feature
|
|
5
|
+
* expression, so `yarn prisma generate` only runs for stacks that kept Prisma.
|
|
6
|
+
* A non-optional hook that fails aborts with a non-zero exit; an optional one
|
|
7
|
+
* warns and continues, because a missing `yarn` on the machine should not throw
|
|
8
|
+
* away an otherwise-correct scaffold.
|
|
9
|
+
*/
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { evalExpr } from './strip.mjs';
|
|
13
|
+
import { interpolate } from './tokens.mjs';
|
|
14
|
+
|
|
15
|
+
export function runHooks(manifest, target, enabled, ctx, { skip = false, log }) {
|
|
16
|
+
const hooks = manifest.hooks || [];
|
|
17
|
+
const results = [];
|
|
18
|
+
|
|
19
|
+
for (const hook of hooks) {
|
|
20
|
+
if (hook.when && !evalExpr(hook.when, enabled)) continue;
|
|
21
|
+
const command = interpolate(hook.run, ctx);
|
|
22
|
+
const cwd = path.join(target, interpolate(hook.cwd || '.', ctx));
|
|
23
|
+
const label = hook.title || command;
|
|
24
|
+
|
|
25
|
+
if (skip) {
|
|
26
|
+
log(` skipped ${label}`);
|
|
27
|
+
results.push({ command, status: 'skipped' });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
log(` running ${label}`);
|
|
32
|
+
const res = spawnSync(command, {
|
|
33
|
+
cwd,
|
|
34
|
+
shell: true,
|
|
35
|
+
stdio: 'inherit',
|
|
36
|
+
env: process.env
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (res.status === 0) {
|
|
40
|
+
results.push({ command, status: 'ok' });
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (hook.optional) {
|
|
45
|
+
log(` warning "${label}" failed (exit ${res.status}) — continuing`);
|
|
46
|
+
results.push({ command, status: 'failed-optional' });
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
results.push({ command, status: 'failed' });
|
|
51
|
+
throw new Error(`Hook failed: ${label} (exit ${res.status})`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* template.json loading, validation and feature resolution.
|
|
3
|
+
*
|
|
4
|
+
* Shape:
|
|
5
|
+
* {
|
|
6
|
+
* "name": "nest-api",
|
|
7
|
+
* "title": "NestJS API",
|
|
8
|
+
* "description": "...",
|
|
9
|
+
* "defaults": { "port": 5000 },
|
|
10
|
+
* // extraction config lives in stacks.local.json — see sourceConfig()
|
|
11
|
+
* "replacements": [ { "from": "...", "to": "{{name}}" } ],
|
|
12
|
+
* "pathReplacements": [ { "from": "acme", "to": "{{name}}" } ],
|
|
13
|
+
* "features": {
|
|
14
|
+
* "realtime": {
|
|
15
|
+
* "title": "Socket.IO realtime layer",
|
|
16
|
+
* "description": "...",
|
|
17
|
+
* "default": false,
|
|
18
|
+
* "core": false, // core features cannot be disabled
|
|
19
|
+
* "requires": ["cache"],
|
|
20
|
+
* "files": ["src/realtime/**"], // deleted wholesale when off
|
|
21
|
+
* "packageJson": {
|
|
22
|
+
* "dependencies": ["socket.io", "@nestjs/websockets"],
|
|
23
|
+
* "devDependencies": [],
|
|
24
|
+
* "scripts": []
|
|
25
|
+
* },
|
|
26
|
+
* "env": ["REALTIME_PATH=/realtime"]
|
|
27
|
+
* }
|
|
28
|
+
* },
|
|
29
|
+
* "hooks": [ { "run": "yarn install", "when": "...", "optional": true } ]
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
import fs from 'node:fs';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
import os from 'node:os';
|
|
35
|
+
|
|
36
|
+
export function expandHome(p) {
|
|
37
|
+
if (!p) return p;
|
|
38
|
+
return p.startsWith('~') ? path.join(os.homedir(), p.slice(1)) : p;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Where each template is extracted from lives outside the public manifests, in
|
|
43
|
+
* a maintainer-local `stacks.local.json` (gitignored) or the file named by
|
|
44
|
+
* STACKS_LOCAL: `{ "sources": { "<template>": { path, include, exclude,
|
|
45
|
+
* skipDirs, replacements } } }`. A manifest's own `source` block is still
|
|
46
|
+
* honoured when the local file has no entry for that template.
|
|
47
|
+
*/
|
|
48
|
+
export function sourceConfig(root, manifest) {
|
|
49
|
+
const file = process.env.STACKS_LOCAL || path.join(root, 'stacks.local.json');
|
|
50
|
+
let local = {};
|
|
51
|
+
if (fs.existsSync(file)) {
|
|
52
|
+
try {
|
|
53
|
+
local = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
54
|
+
} catch (err) {
|
|
55
|
+
throw new Error(`Could not parse ${file}: ${err.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return local.sources?.[manifest.name] ?? manifest.source ?? {};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function templatesDir(root) {
|
|
62
|
+
return path.join(root, 'templates');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function listTemplates(root) {
|
|
66
|
+
const dir = templatesDir(root);
|
|
67
|
+
if (!fs.existsSync(dir)) return [];
|
|
68
|
+
return fs
|
|
69
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
70
|
+
.filter((e) => e.isDirectory())
|
|
71
|
+
.filter((e) => fs.existsSync(path.join(dir, e.name, 'template.json')))
|
|
72
|
+
.map((e) => e.name)
|
|
73
|
+
.sort();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function loadManifest(root, templateName) {
|
|
77
|
+
const file = path.join(templatesDir(root), templateName, 'template.json');
|
|
78
|
+
if (!fs.existsSync(file)) {
|
|
79
|
+
const available = listTemplates(root);
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Unknown template "${templateName}". Available: ${
|
|
82
|
+
available.join(', ') || '(none)'
|
|
83
|
+
}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
87
|
+
manifest.__dir = path.join(templatesDir(root), templateName);
|
|
88
|
+
manifest.__filesDir = path.join(manifest.__dir, 'files');
|
|
89
|
+
manifest.features = manifest.features || {};
|
|
90
|
+
return manifest;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Resolve the enabled feature set from defaults + `--with` / `--without`.
|
|
95
|
+
* Core features are always on. Requirements are pulled in transitively, and an
|
|
96
|
+
* explicit `--without` of something another selected feature requires is a hard
|
|
97
|
+
* error rather than a silently broken project.
|
|
98
|
+
*/
|
|
99
|
+
export function resolveFeatures(manifest, { with: withList = [], without = [], all = false }) {
|
|
100
|
+
const features = manifest.features;
|
|
101
|
+
const known = new Set(Object.keys(features));
|
|
102
|
+
|
|
103
|
+
for (const name of [...withList, ...without]) {
|
|
104
|
+
if (!known.has(name)) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Unknown feature "${name}" for template "${manifest.name}". ` +
|
|
107
|
+
`Known: ${[...known].sort().join(', ')}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const enabled = new Set();
|
|
113
|
+
for (const [name, def] of Object.entries(features)) {
|
|
114
|
+
if (def.core || all || def.default) enabled.add(name);
|
|
115
|
+
}
|
|
116
|
+
for (const name of withList) enabled.add(name);
|
|
117
|
+
for (const name of without) {
|
|
118
|
+
if (features[name].core) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`Feature "${name}" is core to template "${manifest.name}" and cannot be removed.`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
enabled.delete(name);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Transitively pull in requirements, then verify nothing explicitly removed
|
|
127
|
+
// got dragged back in.
|
|
128
|
+
const explicitlyOff = new Set(without);
|
|
129
|
+
let grew = true;
|
|
130
|
+
while (grew) {
|
|
131
|
+
grew = false;
|
|
132
|
+
for (const name of [...enabled]) {
|
|
133
|
+
for (const dep of features[name].requires || []) {
|
|
134
|
+
if (!known.has(dep)) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Feature "${name}" requires "${dep}", which is not declared in template.json.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (explicitlyOff.has(dep)) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
`Cannot disable "${dep}": feature "${name}" requires it. ` +
|
|
142
|
+
`Drop "${name}" too, or keep "${dep}".`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (!enabled.has(dep)) {
|
|
146
|
+
enabled.add(dep);
|
|
147
|
+
grew = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return enabled;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function featureSummary(manifest, enabled) {
|
|
157
|
+
const on = [];
|
|
158
|
+
const off = [];
|
|
159
|
+
for (const [name, def] of Object.entries(manifest.features)) {
|
|
160
|
+
(enabled.has(name) ? on : off).push({ name, ...def });
|
|
161
|
+
}
|
|
162
|
+
return { on, off };
|
|
163
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature-region stripping.
|
|
3
|
+
*
|
|
4
|
+
* Templates are *subtractive*: `templates/<name>/files` is a complete, runnable
|
|
5
|
+
* app with every optional feature switched on, annotated so the generator can
|
|
6
|
+
* delete the parts you did not ask for. That keeps the template itself
|
|
7
|
+
* installable and testable, which a pile of additive fragments never is.
|
|
8
|
+
*
|
|
9
|
+
* Three marker forms, comment-syntax agnostic (we look for the marker text
|
|
10
|
+
* anywhere on the line, so `//`, `#`, `<!-- -->` and `/* *\/` all work):
|
|
11
|
+
*
|
|
12
|
+
* // @feature:start realtime
|
|
13
|
+
* ...kept only when `realtime` is on...
|
|
14
|
+
* // @feature:else
|
|
15
|
+
* ...kept only when it is off...
|
|
16
|
+
* // @feature:end
|
|
17
|
+
*
|
|
18
|
+
* import { Gateway } from 'realtime'; // @feature realtime
|
|
19
|
+
*
|
|
20
|
+
* The expression is a comma/space separated list OR'd together, where a leading
|
|
21
|
+
* `!` negates: `@feature:start realtime, notifications` keeps the block if
|
|
22
|
+
* either is on; `@feature:start !realtime` keeps it only when realtime is off.
|
|
23
|
+
*
|
|
24
|
+
* Strict JSON cannot carry comments, so package.json is pruned through the
|
|
25
|
+
* manifest's per-feature `packageJson` lists instead — see `prunePackageJson`
|
|
26
|
+
* in generate.mjs. JSONC files (tsconfig.json) take markers like any other.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const START = /@feature:start\b/;
|
|
30
|
+
const ELSE = /@feature:else\b/;
|
|
31
|
+
const END = /@feature:end\b/;
|
|
32
|
+
const INLINE = /@feature\b/;
|
|
33
|
+
|
|
34
|
+
const COMMENT_LEADERS = ['<!--', '/*', '//', '#', '--', ';'];
|
|
35
|
+
|
|
36
|
+
/** Evaluate `realtime, !media` against the enabled set. */
|
|
37
|
+
export function evalExpr(expr, enabled) {
|
|
38
|
+
const terms = expr
|
|
39
|
+
.split(/[,\s]+/)
|
|
40
|
+
.map((t) => t.trim())
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
if (terms.length === 0) return true;
|
|
43
|
+
return terms.some((term) =>
|
|
44
|
+
term.startsWith('!') ? !enabled.has(term.slice(1)) : enabled.has(term)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readExpr(line, marker) {
|
|
49
|
+
const idx = line.search(marker);
|
|
50
|
+
let rest = line.slice(idx).replace(marker, '');
|
|
51
|
+
// Trim a trailing block-comment / HTML close so `<!-- @feature:start x -->`
|
|
52
|
+
// does not leak `-->` into the expression.
|
|
53
|
+
rest = rest.replace(/(-->|\*\/)\s*$/, '');
|
|
54
|
+
return rest.trim();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Remove the trailing marker comment from a line we are keeping. */
|
|
58
|
+
function stripInlineMarker(line) {
|
|
59
|
+
const at = line.indexOf('@feature');
|
|
60
|
+
if (at === -1) return line;
|
|
61
|
+
let cut = -1;
|
|
62
|
+
for (const leader of COMMENT_LEADERS) {
|
|
63
|
+
const idx = line.lastIndexOf(leader, at);
|
|
64
|
+
if (idx !== -1 && idx > cut) cut = idx;
|
|
65
|
+
}
|
|
66
|
+
if (cut === -1) return line;
|
|
67
|
+
const kept = line.slice(0, cut).replace(/\s+$/, '');
|
|
68
|
+
return kept;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @returns {{ content: string, changed: boolean, markers: number }}
|
|
73
|
+
*/
|
|
74
|
+
export function stripFeatures(content, enabled) {
|
|
75
|
+
if (!content.includes('@feature')) {
|
|
76
|
+
return { content, changed: false, markers: 0 };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const eol = content.includes('\r\n') ? '\r\n' : '\n';
|
|
80
|
+
const lines = content.split(/\r?\n/);
|
|
81
|
+
const out = [];
|
|
82
|
+
/** @type {{ keep: boolean, seenElse: boolean, parentKeep: boolean }[]} */
|
|
83
|
+
const stack = [];
|
|
84
|
+
let markers = 0;
|
|
85
|
+
|
|
86
|
+
const emitting = () => stack.every((f) => f.keep);
|
|
87
|
+
|
|
88
|
+
for (const line of lines) {
|
|
89
|
+
if (START.test(line)) {
|
|
90
|
+
markers++;
|
|
91
|
+
const parentKeep = emitting();
|
|
92
|
+
const keep = parentKeep && evalExpr(readExpr(line, START), enabled);
|
|
93
|
+
stack.push({ keep, seenElse: false, parentKeep });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (ELSE.test(line)) {
|
|
98
|
+
markers++;
|
|
99
|
+
const frame = stack[stack.length - 1];
|
|
100
|
+
if (!frame) continue; // unbalanced; ignore rather than corrupt the file
|
|
101
|
+
frame.seenElse = true;
|
|
102
|
+
frame.keep = frame.parentKeep && !frame.keep;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (END.test(line)) {
|
|
107
|
+
markers++;
|
|
108
|
+
stack.pop();
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!emitting()) continue;
|
|
113
|
+
|
|
114
|
+
if (INLINE.test(line)) {
|
|
115
|
+
markers++;
|
|
116
|
+
if (!evalExpr(readExpr(line, INLINE), enabled)) continue;
|
|
117
|
+
const kept = stripInlineMarker(line);
|
|
118
|
+
// A line that was *only* a marker comment leaves nothing behind.
|
|
119
|
+
if (kept.trim() === '') continue;
|
|
120
|
+
out.push(kept);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
out.push(line);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Deleting blocks leaves ragged gaps; collapse runs of 3+ blank lines.
|
|
128
|
+
let result = out.join(eol).replace(/(\r?\n[ \t]*){3,}/g, `${eol}${eol}`);
|
|
129
|
+
// A block at the end of a file leaves blank lines before EOF, which every
|
|
130
|
+
// formatter then wants to remove — enough on its own to fail a `format:check`
|
|
131
|
+
// step in the generated project's CI.
|
|
132
|
+
result = result.replace(/(\r?\n[ \t]*)+$/, '');
|
|
133
|
+
if (!result.endsWith(eol)) result += eol;
|
|
134
|
+
|
|
135
|
+
return { content: result, changed: result !== content, markers };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Collect every feature name referenced by markers in a file, so `stack doctor`
|
|
140
|
+
* can flag markers for features the manifest never declares (a typo'd
|
|
141
|
+
* `@feature realtimee` silently deletes code otherwise).
|
|
142
|
+
*/
|
|
143
|
+
export function collectFeatureNames(content) {
|
|
144
|
+
const names = new Set();
|
|
145
|
+
if (!content.includes('@feature')) return names;
|
|
146
|
+
for (const line of content.split(/\r?\n/)) {
|
|
147
|
+
let expr = null;
|
|
148
|
+
if (START.test(line)) expr = readExpr(line, START);
|
|
149
|
+
else if (ELSE.test(line) || END.test(line)) continue;
|
|
150
|
+
else if (INLINE.test(line)) expr = readExpr(line, INLINE);
|
|
151
|
+
if (!expr) continue;
|
|
152
|
+
for (const term of expr.split(/[,\s]+/)) {
|
|
153
|
+
const clean = term.replace(/^!/, '').trim();
|
|
154
|
+
if (clean) names.add(clean);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return names;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Count net bracket depth, ignoring strings and comments.
|
|
162
|
+
*
|
|
163
|
+
* Used by `stack doctor` to catch the sharpest edge of the marker syntax: an
|
|
164
|
+
* inline `// @feature x` placed on the *closing* line of a multi-line construct
|
|
165
|
+
* deletes only that line, silently leaving a half-open import or object. The
|
|
166
|
+
* template compiles (every feature is on), so nothing catches it until someone
|
|
167
|
+
* generates a project without that feature.
|
|
168
|
+
*/
|
|
169
|
+
export function bracketBalance(code) {
|
|
170
|
+
let depth = 0;
|
|
171
|
+
let i = 0;
|
|
172
|
+
const n = code.length;
|
|
173
|
+
while (i < n) {
|
|
174
|
+
const ch = code[i];
|
|
175
|
+
const next = code[i + 1];
|
|
176
|
+
|
|
177
|
+
if (ch === '/' && next === '/') {
|
|
178
|
+
while (i < n && code[i] !== '\n') i++;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (ch === '/' && next === '*') {
|
|
182
|
+
i += 2;
|
|
183
|
+
while (i < n && !(code[i] === '*' && code[i + 1] === '/')) i++;
|
|
184
|
+
i += 2;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (ch === "'" || ch === '"' || ch === '`') {
|
|
188
|
+
const quote = ch;
|
|
189
|
+
i++;
|
|
190
|
+
while (i < n) {
|
|
191
|
+
if (code[i] === '\\') {
|
|
192
|
+
i += 2;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
// A template literal's ${...} is code again, but its braces are
|
|
196
|
+
// balanced within the literal, so skipping the whole span is safe.
|
|
197
|
+
if (code[i] === quote) break;
|
|
198
|
+
i++;
|
|
199
|
+
}
|
|
200
|
+
i++;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (ch === '{' || ch === '(' || ch === '[') depth++;
|
|
204
|
+
else if (ch === '}' || ch === ')' || ch === ']') depth--;
|
|
205
|
+
i++;
|
|
206
|
+
}
|
|
207
|
+
return depth;
|
|
208
|
+
}
|