Skip to content

Commit

Permalink
fix(javascript): keep comments and jsdoc in build (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Mar 31, 2022
1 parent 7a65dac commit 7cd51e2
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
},
{
"path": "packages/client-common/dist/client-common.esm.node.js",
"maxSize": "3.80KB"
"maxSize": "5.25KB"
},
{
"path": "packages/requester-browser-xhr/dist/requester-browser-xhr.esm.node.js",
"maxSize": "825B"
"maxSize": "900B"
},
{
"path": "packages/requester-node-http/dist/requester-node-http.esm.node.js",
"maxSize": "1.10KB"
"maxSize": "1.15KB"
}
]
}
10 changes: 5 additions & 5 deletions clients/algoliasearch-client-javascript/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ packagesConfig.forEach((packageConfig) => {

packageConfig.formats.forEach((format) => {
// Avoid generating types multiple times.
let isTypesGenerated = false;
let areTypesGenerated = false;
const output = bundlers[format];
const isUmdBuild = format === 'umd-browser';
const isEsmBrowserBuild = format === 'esm-browser';
Expand Down Expand Up @@ -244,12 +244,12 @@ packagesConfig.forEach((packageConfig) => {
}),
nodeResolve(),
ts({
check: !isTypesGenerated,
check: !areTypesGenerated,
tsconfig: path.resolve(clientPath, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
declaration: !isTypesGenerated,
declarationMap: !isTypesGenerated,
declaration: !areTypesGenerated,
declarationMap: !areTypesGenerated,
},
},
}),
Expand All @@ -269,7 +269,7 @@ packagesConfig.forEach((packageConfig) => {
},
});

isTypesGenerated = true;
areTypesGenerated = true;
});
});

Expand Down
4 changes: 2 additions & 2 deletions clients/algoliasearch-client-javascript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"lib": ["dom", "esnext", "dom.iterable", "scripthost"],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": false,
"noImplicitAny": true,
"noImplicitThis": true,
"noLib": false,
"noUnusedLocals": true,
"outDir": "dist",
"removeComments": true,
"removeComments": false,
"sourceMap": true,
"strict": true,
"suppressImplicitAnyIndexErrors": true,
Expand Down
1 change: 0 additions & 1 deletion templates/javascript/api-all.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { Region } from '../src/{{apiName}}Api';

export * from '../src/{{apiName}}Api';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function {{apiName}}Api(
appId: string,
apiKey: string,{{#hasRegionalHost}}region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region,{{/hasRegionalHost}}
Expand Down
223 changes: 112 additions & 111 deletions templates/javascript/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -108,150 +108,151 @@ export function create{{capitalizedApiName}}Api(options: CreateClientOptions{{#h
transporter.userAgent.add({ segment, version });
}

{{#operation}}
/**
{{#notes}}
* {{&notes}}
{{/notes}}
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#allParams.0}}
{{^bodyParams.0}}
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
{{/bodyParams.0}}
{{#bodyParams.0}}
{{^queryParams.0}}
{{^pathParams.0}}
{{#bodyParams.0.isArray}}
{{^bodyParams.1}}
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
{{/bodyParams.1}}
{{/bodyParams.0.isArray}}
{{^bodyParams.0.isArray}}
* @param {{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/bodyParams.0.isArray}}
{{/pathParams.0}}
{{#pathParams.0}}
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
{{/pathParams.0}}
{{/queryParams.0}}
{{#queryParams.0}}
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
{{/queryParams.0}}
{{/bodyParams.0}}
{{/allParams.0}}
*/
function {{nickname}}(
return {
addUserAgent,
{{#operation}}
/**
{{#notes}}
* {{&notes}}
{{/notes}}
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#allParams.0}}
{{^bodyParams.0}}
{
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
{{paramName}},
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/bodyParams.0}}
{{#bodyParams.0}}
{{^queryParams.0}}
{{^pathParams.0}}
{{#bodyParams.0.isArray}}
{{^bodyParams.1}}
{
{{#allParams}}
{{paramName}},
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
{{/bodyParams.1}}
{{/bodyParams.0.isArray}}
{{^bodyParams.0.isArray}}
{{#bodyParams}}
{{paramName}}: {{{dataType}}},
{{/bodyParams}}
* @param {{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/bodyParams.0.isArray}}
{{/pathParams.0}}
{{#pathParams.0}}
{
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
{{paramName}},
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/pathParams.0}}
{{/queryParams.0}}
{{#queryParams.0}}
{
* @param {{nickname}} - The {{nickname}} object.
{{#allParams}}
{{paramName}},
* @param {{nickname}}.{{paramName}} {{^description}}The {{paramName}} object.{{/description}}{{#description}}{{{description}}}{{/description}}
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/queryParams.0}}
{{/bodyParams.0}}
{{/allParams.0}}
requestOptions?: RequestOptions
) : Promise<{{{returnType}}}> {
const requestPath = '{{{path}}}'{{#pathParams}}.replace(
{{=<% %>=}}
'{<%baseName%>}',
<%={{ }}=%>
encodeURIComponent(String({{paramName}}))
){{/pathParams}};
const headers: Headers = {};
const queryParameters: QueryParameters = {};

{{#allParams}}
{{#required}}
if ({{#isBoolean}}{{paramName}} === null || {{paramName}} === undefined{{/isBoolean}}{{^isBoolean}}!{{paramName}}{{/isBoolean}}) {
throw new Error('Parameter `{{paramName}}` is required when calling `{{nickname}}`.');
}
*/
{{nickname}}(
{{#allParams.0}}
{{^bodyParams.0}}
{
{{#allParams}}
{{paramName}},
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/bodyParams.0}}
{{#bodyParams.0}}
{{^queryParams.0}}
{{^pathParams.0}}
{{#bodyParams.0.isArray}}
{{^bodyParams.1}}
{
{{#allParams}}
{{paramName}},
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/bodyParams.1}}
{{/bodyParams.0.isArray}}
{{^bodyParams.0.isArray}}
{{#bodyParams}}
{{paramName}}: {{{dataType}}},
{{/bodyParams}}
{{/bodyParams.0.isArray}}
{{/pathParams.0}}
{{#pathParams.0}}
{
{{#allParams}}
{{paramName}},
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/pathParams.0}}
{{/queryParams.0}}
{{#queryParams.0}}
{
{{#allParams}}
{{paramName}},
{{/allParams}}
}: {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props,
{{/queryParams.0}}
{{/bodyParams.0}}
{{/allParams.0}}
requestOptions?: RequestOptions
) : Promise<{{{returnType}}}> {
const requestPath = '{{{path}}}'{{#pathParams}}.replace(
{{=<% %>=}}
'{<%baseName%>}',
<%={{ }}=%>
encodeURIComponent(String({{paramName}}))
){{/pathParams}};
const headers: Headers = {};
const queryParameters: QueryParameters = {};

{{#vars}}
{{#required}}
if ({{#isBoolean}}{{paramName}}.{{baseName}} === null || {{paramName}}.{{baseName}} === undefined{{/isBoolean}}{{^isBoolean}}!{{paramName}}.{{baseName}}{{/isBoolean}}) {
throw new Error('Parameter `{{paramName}}.{{baseName}}` is required when calling `{{nickname}}`.');
}
{{/required}}
{{/vars}}
{{#allParams}}
{{#required}}
if ({{#isBoolean}}{{paramName}} === null || {{paramName}} === undefined{{/isBoolean}}{{^isBoolean}}!{{paramName}}{{/isBoolean}}) {
throw new Error('Parameter `{{paramName}}` is required when calling `{{nickname}}`.');
}

{{/required}}
{{/allParams}}
{{#queryParams}}
if ({{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = {{paramName}}.toString();
}
{{#vars}}
{{#required}}
if ({{#isBoolean}}{{paramName}}.{{baseName}} === null || {{paramName}}.{{baseName}} === undefined{{/isBoolean}}{{^isBoolean}}!{{paramName}}.{{baseName}}{{/isBoolean}}) {
throw new Error('Parameter `{{paramName}}.{{baseName}}` is required when calling `{{nickname}}`.');
}
{{/required}}
{{/vars}}

{{/queryParams}}
{{#headerParams}}
headers['{{baseName}}'] = {{paramName}};
{{/headerParams}}
{{/required}}
{{/allParams}}
{{#queryParams}}
if ({{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = {{paramName}}.toString();
}

const request: Request = {
method: '{{httpMethod}}',
path: requestPath,
{{#bodyParam}}
data: {{paramName}},
{{/bodyParam}}
};
{{/queryParams}}
{{#headerParams}}
headers['{{baseName}}'] = {{paramName}};
{{/headerParams}}

return transporter.request(request, {
queryParameters,
headers,
}, requestOptions);
}
const request: Request = {
method: '{{httpMethod}}',
path: requestPath,
{{#bodyParam}}
data: {{paramName}},
{{/bodyParam}}
};

{{/operation}}
return transporter.request(request, {
queryParameters,
headers,
}, requestOptions);
},

return { addUserAgent, {{#operation}}{{nickname}},{{/operation}} };
{{/operation}}
};
}

export type {{capitalizedApiName}}Api = ReturnType<typeof create{{capitalizedApiName}}Api>;
Expand Down
3 changes: 0 additions & 3 deletions templates/javascript/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export type {{classname}} = {{#oneOf}}{{.}} {{^-last}}|{{/-last}} {{/oneOf}}{{#a
*/
{{/description}}
{{^isEnum}}
{{#parent}}
{{! TODO: Add back 'extends parent' when we understand where parent come from, but for now it's breaking the code}}
{{/parent}}
export type {{classname}} = {
{{#vars}}
{{#description}}
Expand Down

0 comments on commit 7cd51e2

Please sign in to comment.