Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "tsc --build tsconfig.build.json",
"build:watch": "tsc --build --watch tsconfig.build.json",
"build:logos": "npm run build:logos -w resources/logos",
"create-package": "./scripts/create-package.js",
"create-package": "./scripts/create-package/execute.ts",
"lint": "npm run lint:biome && npm run lint:tsc",
"lint:biome": "biome check",
"lint:tsc": "tsc",
Expand Down
2 changes: 1 addition & 1 deletion resources/logos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"node": "^22.12 || ^24"
},
"scripts": {
"build:logos": "./scripts/build.js"
"build:logos": "./scripts/build.ts"
},
"dependencies": {
"sharp": "^0.34.4",
Expand Down
File renamed without changes.
117 changes: 0 additions & 117 deletions scripts/create-package.js

This file was deleted.

75 changes: 75 additions & 0 deletions scripts/create-package/execute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env node
// biome-ignore-all lint/suspicious/noConsole: only used in local dev

import { glob, mkdir, readFile, writeFile } from 'node:fs/promises';
import { dirname, join, resolve } from 'node:path';
import releasePleaseManifest from '../../.release-please-manifest.json' with { type: 'json' };
import releasePleaseConfig from '../../release-please-config.json' with { type: 'json' };
import typeScriptBuildConfig from '../../tsconfig.build.json' with { type: 'json' };

// Get the package name
const name = process.argv[2];
if (!name) {
console.error('❌ No package name provided');
process.exit(1);
}
if (!/^[a-z][a-z0-9-]+$/.test(name)) {
console.error('❌ Package name must be lowercase and alphanumeric with dashes');
process.exit(1);
}

// Get other package details
const year = new Date().getFullYear();

// Create the package directory
const packagePath = resolve(import.meta.dirname, '..', '..', 'packages', name);
console.log(`📂 creating package directory "packages/${name}"`);
await mkdir(packagePath, { recursive: true });

// Copy across all template files
const templatePath = join(import.meta.dirname, 'template');
for await (const template of glob('**/*.*', { cwd: templatePath })) {
const inputPath = join(templatePath, template);
const outputPath = join(packagePath, template);
await mkdir(dirname(outputPath), { recursive: true });

const input = await readFile(inputPath, 'utf-8');
const output = input.replaceAll('{{name}}', name).replaceAll('{{year}}', `${year}`);

console.log(`📝 writing "${template}"`);
await writeFile(outputPath, output);
}

// Add package to Release Please config (re-ordering the packages)
console.log('🚢 adding package to Release Please config');
releasePleaseConfig.packages[`packages/${name}`] = {};
releasePleaseConfig.packages = Object.fromEntries(
Object.entries(releasePleaseConfig.packages).toSorted(([a], [b]) => (a > b ? 1 : -1))
) as typeof releasePleaseConfig.packages;
await writeFile(
resolve(import.meta.dirname, '..', '..', 'release-please-config.json'),
`${JSON.stringify(releasePleaseConfig, null, '\t')}\n`
);

console.log('🚢 adding package to Release Please manifest');
releasePleaseManifest[`packages/${name}`] = '0.0.0';
const sortedReleasePleaseManifest = Object.fromEntries(
Object.entries(releasePleaseManifest).toSorted(([a], [b]) => (a > b ? 1 : -1))
) as typeof releasePleaseManifest;
await writeFile(
resolve(import.meta.dirname, '..', '..', '.release-please-manifest.json'),
JSON.stringify(sortedReleasePleaseManifest, null, 2) // Must be two spaces because Release Please sets it to this
);

// Add package to TypeScript build config
console.log('🏗️ adding package to TypeScript build config');
if (!typeScriptBuildConfig.references.find(({ path }) => path === `packages/${name}`)) {
typeScriptBuildConfig.references.push({ path: `packages/${name}` });
typeScriptBuildConfig.references = typeScriptBuildConfig.references.toSorted(
({ path: a }, { path: b }) => (a > b ? 1 : -1)
);
await writeFile(
resolve(import.meta.dirname, '..', '..', 'tsconfig.build.json'),
`${JSON.stringify(typeScriptBuildConfig, null, '\t')}\n`
);
}
30 changes: 30 additions & 0 deletions scripts/create-package/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# @dotcom-reliability-kit/{{name}}

This module is part of [FT.com Reliability Kit](https://github.com/Financial-Times/dotcom-reliability-kit#readme).

* [Usage](#usage)
* [Contributing](#contributing)
* [License](#license)


## Usage

Install `@dotcom-reliability-kit/{{name}}` as a dependency:

```bash
npm install --save @dotcom-reliability-kit/{{name}}
```

TODO write a usage guide.


## Contributing

See the [central contributing guide for Reliability Kit](https://github.com/Financial-Times/dotcom-reliability-kit/blob/main/docs/contributing.md).


## License

Licensed under the [MIT](https://github.com/Financial-Times/dotcom-reliability-kit/blob/main/LICENSE) license.<br/>
Copyright &copy; {{year}}, The Financial Times Ltd.
1 change: 1 addition & 0 deletions scripts/create-package/template/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
32 changes: 32 additions & 0 deletions scripts/create-package/template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@dotcom-reliability-kit/{{name}}",
"version": "0.0.0",
"type": "module",
"description": "TODO write a description",
"repository": {
"type": "git",
"url": "https://github.com/Financial-Times/dotcom-reliability-kit.git",
"directory": "packages/{{name}}"
},
"homepage": "https://github.com/Financial-Times/dotcom-reliability-kit/tree/main/packages/{{name}}#readme",
"bugs": "https://github.com/Financial-Times/dotcom-reliability-kit/issues?q=label:\"package: {{name}}\"",
"license": "MIT",
"scripts": {
"test": "npm run test:unit && npm run test:end-to-end",
"test:unit": "node --test --experimental-test-module-mocks --experimental-test-coverage --test-coverage-exclude='**/*.spec.ts' --test-coverage-branches=100 --test-coverage-functions=100 --test-coverage-lines=100 'test/unit/**/*.spec.ts'",
"test:end-to-end": "node --test 'test/end-to-end/**/*.spec.ts'"
},
"engines": {
"node": "^22.12 || ^24"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"files": [
"dist",
"!*.tsbuildinfo"
]
}
8 changes: 8 additions & 0 deletions scripts/create-package/template/test/unit/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

describe('@dotcom-reliability-kit/{{name}}', () => {
it('has some tests', () => {
assert.strictEqual(true, false);
});
});
8 changes: 8 additions & 0 deletions scripts/create-package/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "dist"
},
"exclude": ["dist", "test"]
}
Loading