Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] fix create def with scopes #4234

Merged
merged 1 commit into from Jan 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions cli/src/commands/create-def.js
Expand Up @@ -35,22 +35,37 @@ export async function run({libName, ver}: Args): Promise<number> {
return 1;
}

const definitionsPath = path.join(process.cwd(), '/definitions/npm');
const rootDefDir = `${definitionsPath}/${libName}_v${ver}`;
const scope = libName.startsWith('@') ? libName.split('/')[0] : '';
const packageName = scope ? libName.split('/')[1] : libName;
const definitionsPath = path.join(
process.cwd(),
'/definitions/npm',
scope ?? '',
);
const rootDefDir = `${definitionsPath}/${packageName}_v${ver}`;
const defDir = `${rootDefDir}/flow_v${flowVersion}-`;

if (scope) {
try {
fs.mkdirSync(definitionsPath);
} catch (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
}
fs.mkdirSync(rootDefDir);
fs.mkdirSync(defDir);

fs.writeFileSync(
`${defDir}/${libName}_v${ver}.js`,
`${defDir}/${packageName}_v${ver}.js`,
`declare module '${libName}' {
declare module.exports: any;
}`,
);

fs.writeFileSync(
`${defDir}/test_${libName}_v${ver}.js`,
`${defDir}/test_${packageName}_v${ver}.js`,
`// @flow
import { describe, it } from 'flow-typed-test';
// import library from '${libName}';
Expand Down