Skip to content

Commit

Permalink
Merge pull request #89 from qonto/typescript-setup
Browse files Browse the repository at this point in the history
feat: setup TypeScript
  • Loading branch information
vscav authored Nov 6, 2023
2 parents 7be7b65 + b74407b commit 3475c28
Show file tree
Hide file tree
Showing 20 changed files with 627 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# compiled output
dist/
.pnpm-store/
declarations/

# dependencies
node_modules/
Expand Down
1 change: 1 addition & 0 deletions ember-prismic-dom/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# compiled output
/dist/
/declarations/

# misc
/coverage/
7 changes: 6 additions & 1 deletion ember-prismic-dom/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
Expand Down Expand Up @@ -42,5 +42,10 @@ module.exports = {
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
// ts files
{
files: ['**/*.ts'],
extends: ['@qonto/eslint-config-typescript'],
},
],
};
1 change: 1 addition & 0 deletions ember-prismic-dom/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# compiled output
/dist/
/declarations/
/tmp/

# dependencies
Expand Down
1 change: 1 addition & 0 deletions ember-prismic-dom/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"presets": [["@babel/preset-typescript"]],
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
Expand Down
37 changes: 32 additions & 5 deletions ember-prismic-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@
"author": "",
"files": [
"addon-main.cjs",
"declarations",
"dist"
],
"scripts": {
"build": "rollup --config",
"build": "concurrently 'pnpm:build:*'",
"build:js": "rollup --config",
"build:types": "glint --declaration",
"lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:types": "glint",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js:fix": "eslint . --fix",
"start": "rollup --config --watch",
"start": "concurrently 'pnpm:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "glint -d --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
"prepack": "rollup --config",
"prepare": "rollup --config"
Expand All @@ -36,9 +42,16 @@
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.23.2",
"@babel/plugin-syntax-decorators": "^7.22.10",
"@babel/preset-typescript": "^7.23.2",
"@babel/runtime": "^7.23.2",
"@embroider/addon-dev": "^3.0.0",
"@glint/core": "^1.2.1",
"@glint/environment-ember-loose": "^1.2.1",
"@glint/template": "^1.2.1",
"@qonto/eslint-config-typescript": "1.0.0-rc.0",
"@rollup/plugin-babel": "^6.0.4",
"@tsconfig/ember": "^3.0.1",
"@typescript-eslint/parser": "^6.9.0",
"concurrently": "^8.2.2",
"ember-template-lint": "^5.11.2",
"eslint": "^8.53.0",
Expand All @@ -48,7 +61,8 @@
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.0.3",
"rollup": "^3.22.0",
"rollup-plugin-copy": "^3.5.0"
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.2.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand All @@ -69,10 +83,23 @@
}
},
"exports": {
".": "./dist/index.js",
"./*": "./dist/*.js",
".": {
"types": "./declarations/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./declarations/*.d.ts",
"default": "./dist/*.js"
},
"./addon-main.js": "./addon-main.cjs"
},
"typesVersions": {
"*": {
"*": [
"declarations/*"
]
}
},
"peerDependencies": {
"ember-source": "^3.28.0 || ^4.0.0"
}
Expand Down
26 changes: 15 additions & 11 deletions ember-prismic-dom/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { babel } from "@rollup/plugin-babel";
import copy from "rollup-plugin-copy";
import { Addon } from "@embroider/addon-dev/rollup";
import { babel } from '@rollup/plugin-babel';
import copy from 'rollup-plugin-copy';
import { Addon } from '@embroider/addon-dev/rollup';

const addon = new Addon({
srcDir: "src",
destDir: "dist",
srcDir: 'src',
destDir: 'dist',
});

// Add extensions here, such as ts, gjs, etc that you may import
const extensions = ['.js', '.ts'];

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
// You can augment this if you need to.
Expand All @@ -15,12 +18,12 @@ export default {
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints(["index.js", "**/*.js"]),
addon.publicEntrypoints(['components/**/*.js', 'helpers/**/*.js']),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports(["components/**/*.js", "helpers/**/*.js"]),
addon.appReexports(['components/**/*.js', 'helpers/**/*.js']),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
Expand All @@ -34,24 +37,25 @@ export default {
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
babelHelpers: "bundled",
extensions,
babelHelpers: 'bundled',
}),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(["**/*.css"]),
addon.keepAssets(['**/*.css']),

// Remove leftover build artifacts when starting a new build.
addon.clean(),

// Copy Readme and License into published package
copy({
targets: [
{ src: "../README.md", dest: "." },
{ src: "../LICENSE.md", dest: "." },
{ src: '../README.md', dest: '.' },
{ src: '../LICENSE.md', dest: '.' },
],
}),
],
Expand Down
1 change: 1 addition & 0 deletions ember-prismic-dom/src/components/prismic/children.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{! @glint-nocheck: not typesafe yet }}
{{~#each @node.children as |child|~}}
<Prismic::Element
@componentNames={{@componentNames}}
Expand Down
1 change: 1 addition & 0 deletions ember-prismic-dom/src/components/prismic/dom.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{! @glint-nocheck: not typesafe yet }}
<div ...attributes>
{{~#if this.isString~}}
{{@nodes}}
Expand Down
1 change: 1 addition & 0 deletions ember-prismic-dom/src/components/prismic/element.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{! @glint-nocheck: not typesafe yet }}
{{~#if this.isCustom~}}
{{~#let (ensure-safe-component this.componentName) as |CustomComponent|~}}
{{~#CustomComponent node=@node~}}
Expand Down
1 change: 1 addition & 0 deletions ember-prismic-dom/src/components/prismic/image.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{! @glint-nocheck: not typesafe yet }}
{{~#if @node.element.linkUrl~}}
<a
href={{@node.element.linkUrl}}
Expand Down
10 changes: 10 additions & 0 deletions ember-prismic-dom/src/unpublished-development-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '@glint/environment-ember-loose';
import 'ember-source/types';
import 'ember-source/types/preview';

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
}
}
12 changes: 12 additions & 0 deletions ember-prismic-dom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": ["src/**/*", "unpublished-development-types/**/*"],
"glint": {
"environment": "ember-loose"
},
"compilerOptions": {
"allowJs": true,
"declarationDir": "declarations",
"skipLibCheck": true
}
}
Loading

0 comments on commit 3475c28

Please sign in to comment.