Skip to content

Commit

Permalink
feat: add ts-playground template (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
noshiro-pf authored Mar 2, 2025
1 parent b398d20 commit d74b04f
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"create:react-app": "zx scripts/commands/create-new-react-app.mjs",
"create:slides": "zx scripts/commands/create-new-slides.mjs",
"create:util": "zx scripts/commands/create-new-util.mjs",
"create:playground": "zx scripts/commands/create-new-ts-playground.mjs",
"fmt": "yarn fmt:diff:from-main",
"fmt:all": "yarn zz:prettier:cache . > /dev/null",
"fmt:all:no-cache": "yarn zz:prettier . > /dev/null",
Expand Down
11 changes: 11 additions & 0 deletions packages/others/template/configs/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable import/no-default-export */
/* eslint-disable import/no-internal-modules */

import { toThisDir } from '@noshiro/mono-utils';
import { defineRollupConfig } from '../../../../configs/define-rollup-config.mjs';
import tsconfig from './tsconfig.build.json' with { type: 'json' };

export default defineRollupConfig({
configDir: toThisDir(import.meta.url),
outDirRelative: tsconfig.compilerOptions.outDir,
});
13 changes: 13 additions & 0 deletions packages/others/template/configs/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"../../../../configs/tsconfig/tsconfig.lib.build.json",
"../../../../configs/tsconfig/tsconfig.vite.json"
],
"compilerOptions": {
"outDir": "../esm",
"declarationDir": "../esm",
"rootDir": "../src"
},
"include": ["../src"],
"exclude": ["../src/**/*.test.mts"]
}
7 changes: 7 additions & 0 deletions packages/others/template/configs/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": [
"../../../../configs/tsconfig/tsconfig.test.json",
"../../../../configs/tsconfig/tsconfig.vite.json"
],
"include": ["../src"]
}
18 changes: 18 additions & 0 deletions packages/others/template/configs/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { toThisDir } from '@noshiro/mono-utils';
import * as path from 'node:path';
import { defineConfig } from 'vitest/config';

const thisDir: string = toThisDir(import.meta.url);

// https://github.com/vitest-dev/vitest/blob/v1.5.0/test/import-meta/vite.config.ts
export default defineConfig({
test: {
globals: true,
dir: path.resolve(thisDir, '../src'),
includeSource: [path.resolve(thisDir, '../src/**/*.mts')],
typecheck: {
tsconfig: path.resolve(thisDir, 'tsconfig.test.json'),
},
passWithNoTests: true,
},
});
43 changes: 43 additions & 0 deletions packages/others/template/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** @typedef {import('@noshiro/eslint-configs').FlatConfig} FlatConfig */

import {
eslintFlatConfigForTypeScript,
eslintFlatConfigForVitest,
genEsLintRestrictedImportsDefFromDevDependencies,
} from '@noshiro/eslint-configs';
import { toThisDir } from '@noshiro/mono-utils';
import * as path from 'node:path';
import packageJson from './package.json' with { type: 'json' };

const thisDir = toThisDir(import.meta.url);

/** @returns {Promise<readonly FlatConfig[]>} */
const defineConfig = async () => {
const restrictedImports =
await genEsLintRestrictedImportsDefFromDevDependencies(
packageJson.devDependencies,
);

/** @type {readonly FlatConfig[]} */
const configs = [
...eslintFlatConfigForTypeScript({
tsconfigRootDir: thisDir,
tsconfigFileName: './tsconfig.json',
packageDirs: [path.resolve(thisDir, '../../..'), thisDir],
}),
eslintFlatConfigForVitest(['src/**/*']),

{
rules: {
'@typescript-eslint/no-restricted-imports': [
'error',
...restrictedImports,
],
},
},
];

return configs;
};

export default defineConfig();
54 changes: 54 additions & 0 deletions packages/others/template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@noshiro/template-ts-playground",
"version": "1.0.0",
"private": false,
"license": "MIT",
"author": "noshiro-pf <[email protected]>",
"sideEffects": true,
"type": "module",
"scripts": {
"build": "wireit",
"clean": "run-p clean:**",
"clean:build": "rimraf esm",
"clean:wireit": "rimraf .wireit/**",
"fmt": "yarn zz:prettier .",
"lint": "yarn zz:eslint:src",
"lint:fix": "yarn zz:eslint:src --fix",
"start": "wireit",
"test": "yarn zz:vitest run",
"testw": "yarn zz:vitest watch",
"tsc": "yarn type-check",
"tscw": "tsc --noEmit --watch",
"type-check": "tsc --noEmit",
"zz:eslint": "ESLINT_USE_FLAT_CONFIG=true TIMING=1 eslint",
"zz:eslint:print-config": "yarn zz:eslint --print-config src/index.mts",
"zz:eslint:src": "yarn zz:eslint --config eslint.config.js './src/**/*'",
"zz:prettier": "prettier --cache --cache-strategy content --ignore-path ../../../.prettierignore --write",
"zz:vitest": "vitest --config ./configs/vitest.config.ts"
},
"dependencies": {
"@noshiro/ts-utils": "*"
},
"devDependencies": {
"@noshiro/eslint-configs": "*",
"@noshiro/mono-utils": "*",
"@noshiro/ts-type-utils": "*"
},
"wireit": {
"pre-build": {
"command": "run-s clean:build type-check"
},
"build": {
"dependencies": [
"pre-build"
],
"command": "rollup --config ./configs/rollup.config.ts --configPlugin typescript --configImportAttributesKey with"
},
"start": {
"dependencies": [
"build"
],
"command": "node ./esm/index.mjs"
}
}
}
1 change: 1 addition & 0 deletions packages/others/template/src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
8 changes: 8 additions & 0 deletions packages/others/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"../../../configs/tsconfig/tsconfig.lib.type-check.json",
"../../../configs/tsconfig/tsconfig.dom",
"../../../configs/tsconfig/tsconfig.vite.json"
],
"include": ["./src", "./configs"]
}
11 changes: 11 additions & 0 deletions scripts/commands/create-new-ts-playground.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// usage: yarn create:slides <new-slides-name>

import 'zx/globals';
import { createNewPackageShared } from './create-new-package-shared.mjs';

await createNewPackageShared({
newPackageName: argv._[0],
templatePackageName: 'template-ts-playground',
parentDirFromMonoRoot: '/packages/others',
templateDirName: '/template',
});

0 comments on commit d74b04f

Please sign in to comment.