Skip to content

Commit

Permalink
feat(create-analog): simplify prompts add template for upcoming Angul…
Browse files Browse the repository at this point in the history
…ar v18 release (#1094)
  • Loading branch information
brandonroberts authored May 17, 2024
1 parent aad974d commit 29c42a1
Show file tree
Hide file tree
Showing 38 changed files with 640 additions and 113 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Visit the docs at [https://analogjs.org](https://analogjs.org)

## Features

- Supports Vite/Vitest/Playwright
- Powerd by Vite
- Supports Vitest/Storybook
- Server and deployment integrations powered by [Nitro](https://nitro.unjs.io)
- File-based routing
- Server-side data fetching
Expand Down
6 changes: 5 additions & 1 deletion apps/docs-app/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TabItem from '@theme/TabItem';

Analog requires the following Node and Angular versions:

- Node 16.17.0, or v18.13.0 and higher is recommended
- Node v18.13.0 and higher is recommended
- Angular v15 or higher

## Creating a New Application
Expand Down Expand Up @@ -115,3 +115,7 @@ The server for the API/SSR build artifacts is located in the `dist/analog/server

</TabItem>
</Tabs>

## Migrating an Existing Application

You can also migrate an existing Angular application to Analog. See the [migration guide](/docs/guides/migrating) for migration steps.
7 changes: 0 additions & 7 deletions packages/create-analog/CHANGELOG.md

This file was deleted.

19 changes: 11 additions & 8 deletions packages/create-analog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ Analog is the fullstack meta-framework for Angular.

## Features

- File-based routing
- SSR/SSG support with prerendering
- Support for API/server routes
- Powerd by Vite
- Supports Vitest/Storybook
- Server and deployment integrations powered by [Nitro](https://nitro.unjs.io)
- Filesystem-based routing
- Server-side data fetching
- Support for using markdown as content routes
- Supports Angular CLI or Nx workspaces
- Powered by Vite
- Integrated API/server routes
- Hybrid SSR/SSG support
- Supports Angular CLI and Nx workspaces

## Creating an Analog Project

Expand Down Expand Up @@ -37,9 +40,9 @@ Follow the prompts to install the application dependencies and run the project i

Learn more at [analogjs.org](https://analogjs.org)

## Community
## Supporting Analog

- Visit and Star the [GitHub Repo](https://github.com/analogjs/analog)
- Star the [GitHub Repo](https://github.com/analogjs/analog)
- Join the [Discord](https://chat.analogjs.org)
- Follow us on [Twitter](https://twitter.com/analogjs)
- Become a [Sponsor](https://github.com/sponsors/brandonroberts)
- Become a [Sponsor](https://analogjs.org/docs/sponsoring)
23 changes: 9 additions & 14 deletions packages/create-analog/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const createNonEmptyDir = () => {
writeFileSync(pkgJson, '{ "foo": "bar" }');
};

// Angular v16 starter template
let templateFiles = readdirSync(join(CLI_PATH, 'template-angular-v16'));
// Angular v18 starter template
let templateFiles = readdirSync(join(CLI_PATH, 'template-latest'));
templateFiles.push('.git');
// _gitignore is renamed to .gitignore
templateFiles = templateFiles
Expand All @@ -47,23 +47,18 @@ test('prompts for the project name if none supplied', () => {
expect(stdout).toContain('Project name:');
});

test('prompts for the framework if none supplied when target dir is current directory', () => {
test('prompts for the starter if none supplied when target dir is current directory', () => {
mkdirpSync(genPath);
const { stdout } = run(['.'], { cwd: genPath });
expect(stdout).toContain('Select a template:');
expect(stdout).toContain('What would you like to start?:');
});

test('prompts for the framework if none supplied', () => {
test('prompts for the starter if none supplied', () => {
const { stdout } = run([projectName]);
expect(stdout).toContain('Select a template:');
expect(stdout).toContain('What would you like to start?:');
});

test('prompts for the framework on not supplying a value for --template', () => {
const { stdout } = run([projectName, '--template']);
expect(stdout).toContain('Select a template:');
});

test('prompts for the framework on supplying an invalid template', () => {
test.skip('prompts for the framework on supplying an invalid template', () => {
const { stdout } = run([projectName, '--template', 'unknown']);
expect(stdout).toContain(
`"unknown" isn't a valid template. Please choose from below:`
Expand All @@ -84,7 +79,7 @@ test('asks to overwrite non-empty current directory', () => {

test('successfully scaffolds a project based on angular starter template', () => {
const { stdout } = run(
[projectName, '--template', 'angular-v16', '--skipTailwind'],
[projectName, '--template', 'latest', '--skipTailwind'],
{
cwd: __dirname,
}
Expand All @@ -97,7 +92,7 @@ test('successfully scaffolds a project based on angular starter template', () =>
});

test('works with the -t alias', () => {
const { stdout } = run([projectName, '-t', 'angular-v16', '--skipTailwind'], {
const { stdout } = run([projectName, '-t', 'latest', '--skipTailwind'], {
cwd: __dirname,
});
const generatedFiles = readdirSync(genPath).sort();
Expand Down
55 changes: 13 additions & 42 deletions packages/create-analog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,19 @@ const APPS = [
color: yellow,
variants: [
{
name: 'angular-v17',
display: 'TypeScript',
name: 'Full-stack Application',
template: 'angular-v17',
color: green,
},
{
name: 'blog',
display: 'TypeScript',
color: green,
},
{
name: 'angular-v16',
display: 'TypeScript',
color: green,
name: 'Blog',
template: 'blog',
color: yellow,
},
],
},
];

const TEMPLATES = APPS.map(
(f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
).reduce((a, b) => a.concat(b), []);

const renameFiles = {
_gitignore: '.gitignore',
};
Expand Down Expand Up @@ -97,38 +88,18 @@ async function init() {
isValidPackageName(dir) || 'Invalid package.json name',
},
{
type: template && TEMPLATES.includes(template) ? null : 'select',
name: 'framework',
message:
typeof template === 'string' && !TEMPLATES.includes(template)
? reset(
`"${template}" isn't a valid template. Please choose from below: `
)
: reset('Select a template:'),
initial: 0,
choices: APPS.map((framework) => {
const frameworkColor = framework.color;
type: template ? null : 'select',
name: 'variant',
message: reset('What would you like to start?:'),
// @ts-ignore
choices: APPS[0].variants.map((variant) => {
const variantColor = variant.color;
return {
title: frameworkColor(framework.name),
value: framework,
title: variantColor(variant.name),
value: variant.template,
};
}),
},
{
type: (framework) =>
framework && framework.variants ? 'select' : null,
name: 'variant',
message: reset('Select a variant:'),
// @ts-ignore
choices: (framework) =>
framework.variants.map((variant) => {
const variantColor = variant.color;
return {
title: variantColor(variant.name),
value: variant.name,
};
}),
},
{
type: skipTailwind ? null : 'confirm',
name: 'tailwind',
Expand Down
1 change: 1 addition & 0 deletions packages/create-analog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"template-angular-v16",
"template-angular-v17",
"template-blog",
"template-latest",
"files"
],
"main": "index.js",
Expand Down
16 changes: 16 additions & 0 deletions packages/create-analog/template-latest/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = single

[*.md]
max_line_length = off
trim_trailing_whitespace = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}
19 changes: 19 additions & 0 deletions packages/create-analog/template-latest/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:5173/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test"
}
]
}
42 changes: 42 additions & 0 deletions packages/create-analog/template-latest/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
{
"type": "npm",
"script": "test",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}
26 changes: 26 additions & 0 deletions packages/create-analog/template-latest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Analog App

This project was generated with [Analog](https://analogjs.org), the fullstack meta-framework for Angular.

## Setup

Run `npm install` to install the application dependencies.

## Development

Run `npm start` for a dev server. Navigate to `http://localhost:5173/`. The application automatically reloads if you change any of the source files.

## Build

Run `npm run build` to build the client/server project. The client build artifacts are located in the `dist/analog/public` directory. The server for the API build artifacts are located in the `dist/analog/server` directory.

## Test

Run `npm run test` to run unit tests with [Vitest](https://vitest.dev).

## Community

- Visit and Star the [GitHub Repo](https://github.com/analogjs/analog)
- Join the [Discord](https://chat.analogjs.org)
- Follow us on [Twitter](https://twitter.com/analogjs)
- Become a [Sponsor](https://github.com/sponsors/brandonroberts)
43 changes: 43 additions & 0 deletions packages/create-analog/template-latest/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# Compiled output
/dist
/tmp
/out-tsc
/bazel-out

# Node
/node_modules
npm-debug.log
yarn-error.log

# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# Miscellaneous
/.angular/cache
/.nx/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings

# System files
.DS_Store
Thumbs.db
Loading

0 comments on commit 29c42a1

Please sign in to comment.