Skip to content

Commit

Permalink
Feature: inject vue & angular config (BuilderIO#748)
Browse files Browse the repository at this point in the history
* inject vue config

* add config injector to angular

* fix overrides path

* release
  • Loading branch information
samijaber authored Sep 22, 2022
1 parent 1ecf47c commit b7d126a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/mitosis-cli",
"version": "0.0.22",
"version": "0.0.23",
"description": "mitosis CLI",
"types": "build/types/types.d.ts",
"bin": {
Expand Down
20 changes: 13 additions & 7 deletions packages/cli/src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ export async function build(config?: MitosisConfig) {
// each generator also clones the JSON before manipulating it, but this is an extra safety measure.
const files = fastClone(mitosisComponents);

const targetContextWithConfig: TargetContextWithConfig = { ...targetContext, options };

await Promise.all([
buildAndOutputNonComponentFiles(targetContextWithConfig),
buildAndOutputComponentFiles({ ...targetContextWithConfig, files }),
buildAndOutputNonComponentFiles({ ...targetContext, options }),
buildAndOutputComponentFiles({ ...targetContext, options, files }),
]);
}),
);
Expand Down Expand Up @@ -325,6 +323,9 @@ async function buildAndOutputComponentFiles({
await Promise.all(output);
}

/**
* This provides the default path for a target's contents, both in the input and output directories.
*/
const getTargetPath = ({ target }: { target: Target }): string => {
switch (target) {
case 'vue2':
Expand Down Expand Up @@ -392,15 +393,20 @@ async function buildContextFile({
* Transpiles all non-component files, including Context files.
*/
async function buildNonComponentFiles(args: TargetContextWithConfig) {
const { target, options, outputPath } = args;
const { target, options } = args;
const nonComponentFiles = (await glob(options.files, { cwd })).filter(
(file) => file.endsWith('.ts') || file.endsWith('.js'),
);

return await Promise.all(
nonComponentFiles.map(async (path): Promise<{ path: string; output: string }> => {
// try to find override file
const overrideFilePath = `${options.overridesDir}/${outputPath}/${path}`;
/**
* Try to find override file.
* NOTE: we use the default `getTargetPath` even if a user-provided alternative is given. That's because the
* user-provided alternative is only for the output path, not the override input path.
*/
const overrideFilePath = `${options.overridesDir}/${getTargetPath({ target })}/${path}`;

const overrideFile = (await pathExists(overrideFilePath))
? await readFile(overrideFilePath, 'utf8')
: null;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"engines": {
"npm": "99999999.9.9"
},
"version": "0.0.61",
"version": "0.0.62",
"homepage": "https://github.com/BuilderIO/mitosis",
"main": "./dist/src/index.js",
"exports": {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/generators/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ export const componentToAngular: TranspilerGenerator<ToAngularOptions> =
],`
: ''
}
${Object.entries(json.meta.angularConfig || {})
.map(([k, v]) => `${k}: ${v}`)
.join(',')}
})
export default class ${json.name} {
${localExportVars.join('\n')}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/generators/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,9 @@ function generateOptionsApiScript(
methods: ${functionsString},
`
}
${Object.entries(component.meta.vueConfig || {})
.map(([k, v]) => `${k}: ${v}`)
.join(',')}
}`;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/eslint-plugin-mitosis",
"version": "0.0.6",
"version": "0.0.7",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
Expand Down

0 comments on commit b7d126a

Please sign in to comment.