Skip to content

Commit

Permalink
fix: export plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
callqh committed May 1, 2024
1 parent 439e170 commit adcc92a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
23 changes: 19 additions & 4 deletions packages/create-farm-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,15 @@ async function copyTemplate(targetDir: string, options: IResultType) {
// Modify package.json to add dependencies
const packageJsonPath = path.join(`${dest}/playground`, 'package.json');
if (fs.existsSync(packageJsonPath)) {
const packageJsonContent = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const packageJsonContent = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf-8')
);
// Modify the dependencies object as needed
packageJsonContent.dependencies[options.pluginName] = 'workspace:*'; // Modify this line with your dependency and version
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonContent, null, 2));
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJsonContent, null, 2)
);
}

const runText = options.type === 'js' ? 'pnpm dev' : 'pnpm build';
Expand Down Expand Up @@ -165,8 +170,8 @@ function replaceNamePlaceholders(
replace: () => options.pluginName
},
{
name: '<FARM-RUST-PLUGIN-NPM-NAME>',
replace: () => options.pluginName
name: '<FARM-RUST-PLUGIN-EXPORT-NAME>',
replace: () => toCamelCase(options.pluginName)
},
{
name: '<FARM-RUST-PLUGIN-CARGO-NAME>',
Expand Down Expand Up @@ -227,6 +232,16 @@ function copyDir(srcDir: string, destDir: string, options: IResultType) {
}
}

function toCamelCase(str: string) {
// remove scope
const index = str.indexOf('/');
const trimmedStr = index !== -1 ? str.slice(index + 1) : str;

return trimmedStr.replace(/-([a-z])/g, function (_, letter) {
return letter.toUpperCase();
});
}

function welcome() {
console.log(colors.BrandText('⚡ Welcome To Farm ! '));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IPluginOptions } from '../options.d';
declare const binPath: (options?: IPluginOptions) => [string, IPluginOptions];
declare const binPath: string;
export const <FARM-RUST-PLUGIN-EXPORT-NAME>: (options?: IPluginOptions) => [string, IPluginOptions];
export default binPath;
3 changes: 2 additions & 1 deletion packages/create-farm-plugin/templates/rust/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ switch (platform) {
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
}

export default (options)=> [binPath, options];
export const <FARM-RUST-PLUGIN-EXPORT-NAME> = (options) => [binPath, options];
export default binPath;
3 changes: 2 additions & 1 deletion rust-plugins/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export interface ReactConfig {
*/
importSource?: string;
}
declare const binPath:(options?: ReactConfig)=>[string,typeof options] ;
declare const binPath: string;
export const farmPluginReact:(options?: ReactConfig)=>[string,typeof options] ;
export default binPath;
3 changes: 2 additions & 1 deletion rust-plugins/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ switch (platform) {
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
}

export default (options)=>[binPath,options];
export const farmPluginReact = (options)=>[binPath,options];
export default binPath;
4 changes: 2 additions & 2 deletions rust-plugins/sass/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export interface SassOptions {
additionalData?: string;
}


declare const binPath: (options?:SassOptions)=>[string,SassOptions];
declare const binPath: string;
export const farmPluginSass: (options?:SassOptions)=>[string,SassOptions];
export default binPath;
3 changes: 2 additions & 1 deletion rust-plugins/sass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ switch (platform) {
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
}

export default (options)=>[binPath, options];
export const farmPluginSass = (options)=>[binPath, options];
export default binPath;

0 comments on commit adcc92a

Please sign in to comment.