Skip to content

Commit

Permalink
Add Ember Starter
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 3, 2025
1 parent 6c8a5a2 commit f6578c3
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/create-vite/template-ember/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


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

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
26 changes: 26 additions & 0 deletions packages/create-vite/template-ember/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# compiled output
/dist/

# dependencies
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/connect.lock
/.eslintcache
/coverage/
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try

# broccoli-debug
/DEBUG/
3 changes: 3 additions & 0 deletions packages/create-vite/template-ember/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["dist"]
}
23 changes: 23 additions & 0 deletions packages/create-vite/template-ember/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# app-template

This README outlines the details of collaborating on this Ember application.
A short introduction of this app could easily go here.

## Running / Development

* `pnpm ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).
* Visit your tests at [http://localhost:4200/tests](http://localhost:4200/tests).

### Running Tests

* `pnpm start` then visit `/tests/` in your browser
* `pnpm test:ember` for CI / CLI

## Further Reading / Useful Links

* [ember.js](https://emberjs.com/)
* [ember-cli](https://cli.emberjs.com/release/)
* Development Browser Extensions
* [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi)
* [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/)
37 changes: 37 additions & 0 deletions packages/create-vite/template-ember/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { buildMacros } = require('@embroider/macros/babel');

const macros = buildMacros();

module.exports = {
plugins: [
[
'babel-plugin-ember-template-compilation',
{
compilerPath: 'ember-source/dist/ember-template-compiler.js',
enableLegacyModules: ['ember-cli-htmlbars'],
transforms: [...macros.templateMacros],
},
],
[
'module:decorator-transforms',
{
runtime: {
import: require.resolve('decorator-transforms/runtime-esm'),
},
},
],
[
'@babel/plugin-transform-runtime',
{
absoluteRuntime: __dirname,
useESModules: true,
regenerator: false,
},
],
...macros.babelMacros,
],

generatorOpts: {
compact: false,
},
};
22 changes: 22 additions & 0 deletions packages/create-vite/template-ember/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>Vite Ember Starter</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="stylesheet" href="./src/styles/app.css" />
</head>

<body>
<script type="module">
import Application from "./src/app";
import environment from "./src/config";

Application.create(environment.APP);
</script>
</body>

</html>
62 changes: 62 additions & 0 deletions packages/create-vite/template-ember/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "vite-ember-starter",
"version": "0.0.0",
"private": true,
"description": "Small description for app-template goes here",
"repository": "",
"license": "MIT",
"author": "",
"type": "module",
"imports": {
"#/*": "./src/*",
"#config": "./src/config.js",
"#components/*": "./src/components/*"
},
"exports": {
"./tests/*": "./tests/*",
"./*": "./src/*"
},
"scripts": {
"build": "vite build",
"build:test": "NODE_ENV=development vite build --mode test",
"start": "vite",
"test": "pnpm test:ember",
"test:ember": "pnpm build:test && pnpm dist:ember:test",
"dist:ember:test": "ember test --path dist --config-file ./testem.cjs"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/plugin-transform-runtime": "^7.25.4",
"@babel/runtime": "^7.25.6",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^5.0.0",
"@embroider/core": "^4.0.0-alpha.6",
"@embroider/macros": "^1.17.0-alpha.5",
"@embroider/router": "^3.0.0-alpha.1",
"@embroider/vite": "^1.0.0-alpha.7",
"@glimmer/component": "^2.0.0",
"@glimmer/tracking": "^1.1.2",
"@rollup/plugin-babel": "^5.3.1",
"babel-plugin-ember-template-compilation": "^2.3.0",
"decorator-transforms": "^2.0.0",
"ember-cli": "^6.2.2",
"ember-modifier": "^4.1.0",
"ember-page-title": "^8.2.4",
"ember-qunit": "^9.0.1",
"ember-resolver": "^13.1.0",
"ember-source": "6.4.0-alpha.4",
"qunit": "^2.19.4",
"qunit-dom": "^3.4.0",
"vite": "^6.2.0"
},
"engines": {
"node": ">= 18"
},
"ember": {
"edition": "octane"
},
"ember-addon": {
"type": "app",
"version": 2
}
}
10 changes: 10 additions & 0 deletions packages/create-vite/template-ember/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import config from '#config';

import { registry } from './registry.js';

export default class App extends Application {
modulePrefix = config.modulePrefix;
Resolver = Resolver.withModules(registry);
}
18 changes: 18 additions & 0 deletions packages/create-vite/template-ember/src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const ENV = {
modulePrefix: 'vite-ember-starter',
environment: import.meta.env.DEV ? 'development' : 'production',
rootURL: '/',
locationType: 'history',
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
};

export default ENV;

export function enterTestMode() {
ENV.locationType = 'none';
ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}
28 changes: 28 additions & 0 deletions packages/create-vite/template-ember/src/registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Router from './router.js';
import PageTitleService from 'ember-page-title/services/page-title';
import config from './config.js';

const appName = config.modulePrefix;

function formatAsResolverEntries(imports) {
return Object.fromEntries(
Object.entries(imports).map(([k, v]) => [k.replace(/\.g?(j|t)s$/, '').replace(/^\.\//, `${appName}/`), v])
);
}

/**
* A global registry is needed until:
* - Services can be referenced via import paths (rather than strings)
* - we design a new routing system
*/
const resolverRegistry = {
...formatAsResolverEntries(import.meta.glob('./templates/**/*.{gjs,gts,js,ts}', { eager: true })),
...formatAsResolverEntries(import.meta.glob('./services/**/*.{js,ts}', { eager: true })),
...formatAsResolverEntries(import.meta.glob('./routes/**/*.{js,ts}', { eager: true })),
[`${appName}/router`]: Router,
};

export const registry = {
...resolverRegistry,
[`${appName}/services/page-title`]: PageTitleService,
};
9 changes: 9 additions & 0 deletions packages/create-vite/template-ember/src/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import EmberRouter from '@ember/routing/router';
import config from '#config';

export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
}

Router.map(function () {});
5 changes: 5 additions & 0 deletions packages/create-vite/template-ember/src/styles/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */

legend {
font-style: italic;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<fieldset><legend>app/templates/application.gjs</legend>

{{outlet}}
</fieldset>
</template>
26 changes: 26 additions & 0 deletions packages/create-vite/template-ember/testem.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

if (typeof module !== 'undefined') {
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
browser_start_timeout: 120,
browser_args: {
Chrome: {
ci: [
// --no-sandbox is needed when running Chrome inside a container
process.env.CI ? '--no-sandbox' : null,
'--disable-gpu',
'--headless',
'--disable-dev-shm-usage',
'--disable-software-rasterizer',
'--mute-audio',
'--remote-debugging-port=0',
'--window-size=1440,900',
].filter(Boolean),
},
},
};
}
42 changes: 42 additions & 0 deletions packages/create-vite/template-ember/tests/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
setupApplicationTest as upstreamSetupApplicationTest,
setupRenderingTest as upstreamSetupRenderingTest,
setupTest as upstreamSetupTest,
} from 'ember-qunit';

// This file exists to provide wrappers around ember-qunit's / ember-mocha's
// test setup functions. This way, you can easily extend the setup that is
// needed per test type.

function setupApplicationTest(hooks, options) {
upstreamSetupApplicationTest(hooks, options);

// Additional setup for application tests can be done here.
//
// For example, if you need an authenticated session for each
// application test, you could do:
//
// hooks.beforeEach(async function () {
// await authenticateSession(); // ember-simple-auth
// });
//
// This is also a good place to call test setup functions coming
// from other addons:
//
// setupIntl(hooks); // ember-intl
// setupMirage(hooks); // ember-cli-mirage
}

function setupRenderingTest(hooks, options) {
upstreamSetupRenderingTest(hooks, options);

// Additional setup for rendering tests can be done here.
}

function setupTest(hooks, options) {
upstreamSetupTest(hooks, options);

// Additional setup for unit tests can be done here.
}

export { setupApplicationTest, setupRenderingTest, setupTest };
32 changes: 32 additions & 0 deletions packages/create-vite/template-ember/tests/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>AppTemplate Tests</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="../src/styles/app.css" />
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
</div>

<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script type="module">
import "ember-testing";
// Needed until we have:
// https://github.com/emberjs/ember-test-helpers/pull/1528
globalThis.EmberENV = {};
</script>

<script type="module">
import { start } from "./test-helper";
import.meta.glob("./**/*.{js,gjs,gts}", { eager: true });
start();
</script>
</body>
</html>
Empty file.
Loading

0 comments on commit f6578c3

Please sign in to comment.