Skip to content

Commit

Permalink
Updated ejectIntegration to eject the same local configuration as the…
Browse files Browse the repository at this point in the history
… ejectConfig does.
  • Loading branch information
DomagojGojak committed Jun 5, 2024
1 parent 7506970 commit 8f66045
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
9 changes: 6 additions & 3 deletions dist/cli/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ exports.ejectConfig = ejectConfig;
* @param handoff
*/
var ejectIntegration = function (handoff) { return __awaiter(void 0, void 0, void 0, function () {
var config, integration, workingPath, integrationPath, localConfigPath, _a;
var config, integration, workingPath, integrationPath, localConfigPath, _a, localConfigBuffer, localConfig;
var _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
config = handoff.config;
if (!config.integration) {
console.log(chalk_1.default.red("Unable to eject integration as it is not defined."));
return [2 /*return*/, handoff];
}
integration = config.integration.name;
// is the custom integration already being used?
Expand All @@ -104,8 +105,10 @@ var ejectIntegration = function (handoff) { return __awaiter(void 0, void 0, voi
_d.label = 2;
case 2:
_a;
config.integration = { name: 'custom', version: '' };
fs_extra_1.default.writeFileSync(localConfigPath, "".concat(JSON.stringify(config, null, 2)));
localConfigBuffer = fs_extra_1.default.readFileSync(localConfigPath);
localConfig = JSON.parse(localConfigBuffer.toString());
localConfig.integration = { name: 'custom', version: '' };
fs_extra_1.default.writeFileSync(localConfigPath, "".concat(JSON.stringify(localConfig, null, 2)));
return [2 /*return*/, handoff];
}
});
Expand Down
4 changes: 2 additions & 2 deletions dist/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from './types/config';
import { ClientConfig, Config } from './types/config';
export interface ImageStyle {
name: string;
style: string;
Expand All @@ -11,4 +11,4 @@ export declare const defaultConfig: () => Config;
* Get the configuration formatted for the client, either from the root of the project or from the default config.
* @returns Promise<Config>
*/
export declare const getClientConfig: (configOverride?: any) => any;
export declare const getClientConfig: (configOverride?: any) => ClientConfig;
5 changes: 3 additions & 2 deletions dist/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ var getClientConfig = function (configOverride) {
if (configOverride) {
config = __assign(__assign({}, config), configOverride);
}
var _a = __assign(__assign({}, (0, exports.defaultConfig)()), config), app = _a.app, figma = _a.figma, exportsOutputDirectory = _a.exportsOutputDirectory, sitesOutputDirectory = _a.sitesOutputDirectory, assets_zip_links = _a.assets_zip_links, use_legacy_definitions = _a.use_legacy_definitions;
var _a = __assign(__assign({}, (0, exports.defaultConfig)()), config), app = _a.app, figma = _a.figma, integration = _a.integration, exportsOutputDirectory = _a.exportsOutputDirectory, sitesOutputDirectory = _a.sitesOutputDirectory, assets_zip_links = _a.assets_zip_links, use_legacy_definitions = _a.use_legacy_definitions;
return {
app: app,
figma: figma,
integration: integration,
exportsOutputDirectory: exportsOutputDirectory,
sitesOutputDirectory: sitesOutputDirectory,
assets_zip_links: assets_zip_links !== null && assets_zip_links !== void 0 ? assets_zip_links : { icons: null, logos: null },
use_legacy_definitions: use_legacy_definitions
use_legacy_definitions: use_legacy_definitions,
};
};
exports.getClientConfig = getClientConfig;
10 changes: 8 additions & 2 deletions src/cli/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs-extra';
import chalk from 'chalk';
import { getPathToIntegration } from '../transformers/integration';
import { getClientConfig } from '../config';
import { ClientConfig } from 'handoff/types/config';

/**
* Eject the config to the working directory
Expand Down Expand Up @@ -31,6 +32,7 @@ export const ejectIntegration = async (handoff: Handoff) => {

if (!config.integration) {
console.log(chalk.red(`Unable to eject integration as it is not defined.`));
return handoff;
}

const integration = config.integration.name;
Expand Down Expand Up @@ -58,8 +60,12 @@ export const ejectIntegration = async (handoff: Handoff) => {
// ensure local configuration is set up to support the ejected integration
const localConfigPath = path.join(handoff.workingPath, 'handoff.config.json');
!fs.existsSync(localConfigPath) && (await ejectConfig(handoff));
config.integration = { name: 'custom', version: '' };
fs.writeFileSync(localConfigPath, `${JSON.stringify(config, null, 2)}`);

// update (and re-write) the ejected configuration with custom integration
const localConfigBuffer = fs.readFileSync(localConfigPath);
const localConfig = JSON.parse(localConfigBuffer.toString()) as ClientConfig;
localConfig.integration = { name: 'custom', version: '' };
fs.writeFileSync(localConfigPath, `${JSON.stringify(localConfig, null, 2)}`);

return handoff;
};
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,18 @@ export const getClientConfig = (configOverride?: any): ClientConfig => {
config = { ...config, ...configOverride };
}

const { app, figma, exportsOutputDirectory, sitesOutputDirectory, assets_zip_links, use_legacy_definitions } = {
const { app, figma, integration, exportsOutputDirectory, sitesOutputDirectory, assets_zip_links, use_legacy_definitions } = {
...defaultConfig(),
...config,
} as unknown as Config;

return {
app,
figma,
integration,
exportsOutputDirectory,
sitesOutputDirectory,
assets_zip_links: assets_zip_links ?? { icons: null, logos: null },
use_legacy_definitions
use_legacy_definitions,
};
};
5 changes: 4 additions & 1 deletion src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export interface Config {
use_legacy_definitions?: boolean | null | undefined;
}

export type ClientConfig = Pick<Config, "app" | "figma" | "assets_zip_links", "use_legacy_definitions">;
export type ClientConfig = Pick<
Config,
'app' | 'figma' | 'integration' | 'exportsOutputDirectory' | 'sitesOutputDirectory' | 'assets_zip_links' | 'use_legacy_definitions'
>;

declare const config: Config;

Expand Down

0 comments on commit 8f66045

Please sign in to comment.