Skip to content

Commit

Permalink
Merge pull request #336 from Jimdo/revamp
Browse files Browse the repository at this point in the history
complete revamp
  • Loading branch information
smellai authored Jun 21, 2024
2 parents 7e8a7ac + 59e5131 commit ee6d537
Show file tree
Hide file tree
Showing 21 changed files with 5,486 additions and 16,534 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'node', 'prettier'],
plugins: ['@typescript-eslint', 'node'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
Expand All @@ -12,10 +12,8 @@ module.exports = {
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended',
],
rules: {
'prettier/prettier': 'warn',
'node/no-missing-import': 'off',
'node/no-empty-function': 'off',
'node/no-unsupported-features/es-syntax': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jspm_packages/
lib/

# Config file
config.js
config.json
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
3 changes: 0 additions & 3 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

(exec </dev/tty && node_modules/.bin/cz --hook) || true 2> /dev/null
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ const result = getFilteredReposWithPackageForOrg({
```bash
npx package-adoption

package-adoption --config /path/to/config.js --output /path/to/output.json
package-adoption --config /path/to/config.json --output /path/to/output.json
```

If output file path omitted, `package-adoption` ouputs to stdout.
When config option omitted, default for config file will be local `config.js`. The file must export an object like this:
If output file path omitted, `package-adoption` outputs to stdout.
When config option omitted, default for config file will be local `config.json`. The file must export an object like this:

```ts
module.exports = {
org: 'myOrg',
daysUntilStale: 90, // If omitted, 365 will be used as default
ghAuthToken: 'my-GH-auth-token',
pkgName: 'myPkg',
};
```json
{
"org": "myOrg",
"daysUntilStale": 90, // If omitted, 365 will be used as default
"ghAuthToken": "my-GH-auth-token",
"pkgName": "myPkg",
}
```

### With inline arguments
Expand All @@ -82,6 +82,12 @@ module.exports = {
package-adoption --org=myOrg --token=my-GH-auth-token --pkg=myPkg --output /path/to/output.json
```

### Run locally

```bash
npm run dev
```

[build-img]: https://github.com/jimdo/package-adoption/actions/workflows/release.yml/badge.svg
[build-url]: https://github.com/jimdo/package-adoption/actions/workflows/release.yml
[downloads-img]: https://img.shields.io/npm/dt/package-adoption
Expand Down
47 changes: 27 additions & 20 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,43 @@ import path from 'path';
import { cwd } from 'process';
import fs from 'fs';

import { getFilteredReposWithPackageForOrg } from '../src/getFilteredReposWithPackageForOrg';
import { getFilteredReposWithPackageForOrg } from '../src/getFilteredReposWithPackageForOrg.js';
import { InputParameters } from '../src/types';

const argv = yargs(process.argv.slice(2)).options({
config: { type: 'string', default: 'config.js' },
output: { type: 'string' },
'days-until-stale': { type: 'number', default: 365 },
pkg: { type: 'string' },
token: { type: 'string' },
org: { type: 'string' },
}).argv;
const argv = yargs(process.argv.slice(2))
.options({
config: { type: 'string', default: 'config.json' },
output: { type: 'string' },
'days-until-stale': { type: 'number', default: 365 },
pkg: { type: 'string' },
token: { type: 'string' },
org: { type: 'string' },
})
.parseSync();

(async () => {
const configPath = path.resolve(cwd(), argv.config);
let config: InputParameters;

let fromArgs = false;
try {
config = require(configPath);
} catch {
config = {
org: argv.org || '',
pkgName: argv.pkg || '',
ghAuthToken: argv.token || '',
daysUntilStale: argv['days-until-stale'],
};
fromArgs = true;
const file = fs.readFileSync(configPath, 'utf-8');
config = JSON.parse(file);
} catch (err) {
if (argv.pkg && argv.org && argv.token) {
config = {
org: argv.org,
pkgName: argv.pkg,
ghAuthToken: argv.token,
daysUntilStale: argv['days-until-stale'],
};
fromArgs = true;
} else {
console.log('Error reading config file');
throw err;
}
}

const { pkgName } = config;

const repositories = await getFilteredReposWithPackageForOrg(
config,
fromArgs
Expand All @@ -47,6 +53,7 @@ const argv = yargs(process.argv.slice(2)).options({
const outputPath = path.resolve(cwd(), argv.output);
fs.writeFileSync(outputPath, JSON.stringify(repositories));
} else {
const { pkgName } = config;
console.log(`\n\n${pkgName} found in the following repositories:`);
console.log(repositories);
}
Expand Down
9 changes: 8 additions & 1 deletion jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/test/**/*.spec.ts'],
Expand All @@ -12,4 +14,9 @@ module.exports = {
isolatedModules: true,
},
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};

export default config;
Loading

0 comments on commit ee6d537

Please sign in to comment.