@google-cloud/storage-control
Version:
Cloud Storage API client for Node.js
88 lines (85 loc) • 3.48 kB
JavaScript
"use strict";
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.fixIndexFile = fixIndexFile;
exports.fixV2Index = fixV2Index;
const fs = require("fs");
const path = require("path");
const LICENSE_HEADER = `// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//`;
/**
* Fixes the content of an index file by overwriting it with a predefined correct content.
* This function is specifically designed to correct `synthtool`-generated index files
* to ensure the proper export of `v2`, `StorageControlClient`, and `protos`.
*
* @param filePath The path to the index file to fix, relative to the project root.
*/
function fixIndexFile(filePath) {
const fullPath = path.join(__dirname, '..', '..', filePath);
const correctContent = `${LICENSE_HEADER}
// ** This file is automatically generated by synthtool. **
// ** https://github.com/googleapis/synthtool **
// ** All changes to this file may be overwritten. **
import * as v2 from './v2';
import {StorageControlClient} from './storage_control_client';
export {v2, StorageControlClient};
export default {v2, StorageControlClient};
import * as protos from '../protos/protos';
export {protos};
`;
try {
fs.writeFileSync(fullPath, correctContent, 'utf8');
console.log(`Successfully fixed: ${fullPath}`);
}
catch (err) {
console.error(`Error writing to file ${fullPath}:`, err);
}
}
/**
* Fixes the v2 index file by ensuring the `StorageClient` is exported.
* If the export statement is missing, it appends it to the file.
*
* @param filePath The path to the v2 index file to fix, relative to the current directory.
*/
function fixV2Index(filePath) {
const fullPath = path.join(__dirname, '..', filePath);
const correctContent = `${LICENSE_HEADER}
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **
export {StorageControlClient} from './storage_control_client';
export {StorageClient} from './storage_client';
`;
try {
fs.writeFileSync(fullPath, correctContent, 'utf8');
console.log(`Successfully fixed: ${fullPath}`);
}
catch (err) {
console.error(`Error writing to file ${fullPath}:`, err);
}
}
//# sourceMappingURL=index_fix_utils.js.map