Skip to content

Commit

Permalink
Merge pull request #292 from ojvribeiro/feat/configurable-src-directory
Browse files Browse the repository at this point in the history
feat: configurable `src` directory
  • Loading branch information
ojvribeiro authored Sep 9, 2024
2 parents e666c64 + a7641f6 commit f930b25
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 53 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"vue": "3.4.21",
"vue-loader": "17.4.2",
"vue-router": "4.4.0",
"vulxi": "0.0.12",
"vulxi": "0.1.0",
"yargs": "17.7.1",
"yarpm": "1.2.0"
},
Expand Down
43 changes: 22 additions & 21 deletions src/config/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@ const { absoluteVulmixPaths } = require('./paths')
const VulmixAliases = () => {
const ABSOLUTE_ROOT_PATH = absoluteVulmixPaths().absoluteRootPath
const ABSOLUTE_PACKAGE_PATH = absoluteVulmixPaths().absolutePackagePath
const ABSOLUTE_SRC_PATH = absoluteVulmixPaths().absoluteSrcPath

return {
'~': ABSOLUTE_ROOT_PATH,
'@': ABSOLUTE_ROOT_PATH,
'@': ABSOLUTE_SRC_PATH,
'@@': `${ABSOLUTE_PACKAGE_PATH}/src`,
'@appFile': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/app.vue`)
? `${ABSOLUTE_ROOT_PATH}/app.vue`
: fs.existsSync(`${ABSOLUTE_ROOT_PATH}/pages/index.vue`) &&
!fs.existsSync(`${ABSOLUTE_ROOT_PATH}/app.vue`)
'@appFile': fs.existsSync(`${ABSOLUTE_SRC_PATH}/app.vue`)
? `${ABSOLUTE_SRC_PATH}/app.vue`
: fs.existsSync(`${ABSOLUTE_SRC_PATH}/pages/index.vue`) &&
!fs.existsSync(`${ABSOLUTE_SRC_PATH}/app.vue`)
? `${ABSOLUTE_PACKAGE_PATH}/src/vue/pages/app.vue`
: `${ABSOLUTE_PACKAGE_PATH}/src/vue/pages/404.vue`,
'@assets': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/assets`)
? `${ABSOLUTE_ROOT_PATH}/assets`
'@assets': fs.existsSync(`${ABSOLUTE_SRC_PATH}/assets`)
? `${ABSOLUTE_SRC_PATH}/assets`
: false,
'@icons': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/assets/icons`)
? `${ABSOLUTE_ROOT_PATH}/assets/icons`
'@icons': fs.existsSync(`${ABSOLUTE_SRC_PATH}/assets/icons`)
? `${ABSOLUTE_SRC_PATH}/assets/icons`
: false,
'@components': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/components`)
? `${ABSOLUTE_ROOT_PATH}/components`
'@components': fs.existsSync(`${ABSOLUTE_SRC_PATH}/components`)
? `${ABSOLUTE_SRC_PATH}/components`
: false,
'@composables': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/composables`)
? `${ABSOLUTE_ROOT_PATH}/composables`
'@composables': fs.existsSync(`${ABSOLUTE_SRC_PATH}/composables`)
? `${ABSOLUTE_SRC_PATH}/composables`
: false,
'@layouts': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/layouts`)
? `${ABSOLUTE_ROOT_PATH}/layouts`
'@layouts': fs.existsSync(`${ABSOLUTE_SRC_PATH}/layouts`)
? `${ABSOLUTE_SRC_PATH}/layouts`
: false,
'@pages': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/pages`)
? `${ABSOLUTE_ROOT_PATH}/pages`
'@pages': fs.existsSync(`${ABSOLUTE_SRC_PATH}/pages`)
? `${ABSOLUTE_SRC_PATH}/pages`
: false,
'@plugins': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/plugins`)
? `${ABSOLUTE_ROOT_PATH}/plugins`
'@plugins': fs.existsSync(`${ABSOLUTE_SRC_PATH}/plugins`)
? `${ABSOLUTE_SRC_PATH}/plugins`
: false,
'@404': fs.existsSync(`${ABSOLUTE_ROOT_PATH}/404.vue`)
? `${ABSOLUTE_ROOT_PATH}/404.vue`
'@404': fs.existsSync(`${ABSOLUTE_SRC_PATH}/404.vue`)
? `${ABSOLUTE_SRC_PATH}/404.vue`
: `${ABSOLUTE_PACKAGE_PATH}/src/vue/pages/404.vue`,
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/config/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { absoluteVulmixPaths, relativeVulmixPaths } = require('./paths.js')
module.exports.UnpluginAutoImports = () => {
const ABSOLUTE_ROOT_PATH = absoluteVulmixPaths().absoluteRootPath
const ABSOLUTE_PACKAGE_PATH = absoluteVulmixPaths().absolutePackagePath
const RELATIVE_ROOT_PATH = relativeVulmixPaths().relativeRootPath
const RELATIVE_SRC_PATH = relativeVulmixPaths().relativeSrcPath

const VULMIX_CONFIG_PATH = `${ABSOLUTE_ROOT_PATH}/.vulmix/vulmix.config.js`
const VulmixConfig = require(VULMIX_CONFIG_PATH).default
Expand All @@ -13,8 +13,8 @@ module.exports.UnpluginAutoImports = () => {
require('unplugin-vue-components/webpack').default({
version: 3,
dirs: [
`${RELATIVE_ROOT_PATH}/.vulmix/runtime/components`,
`${RELATIVE_ROOT_PATH}/components`,
`${RELATIVE_SRC_PATH}/.vulmix/runtime/components`,
`${RELATIVE_SRC_PATH}/components`,
],
extensions: ['vue', 'ts', 'js'],
directoryAsNamespace: true,
Expand All @@ -41,7 +41,7 @@ module.exports.UnpluginAutoImports = () => {
...(VulmixConfig.imports?.dirs || []),
`${ABSOLUTE_PACKAGE_PATH}/src/vue/composables/**`,
`${ABSOLUTE_PACKAGE_PATH}/src/vue/utils/**`,
`${ABSOLUTE_ROOT_PATH}/composables/**`,
`${RELATIVE_SRC_PATH}/composables/**`,
`${ABSOLUTE_PACKAGE_PATH}/src/vue/composables/**`,
],
dts: `${ABSOLUTE_ROOT_PATH}/.vulmix/types/auto-imports.d.ts`,
Expand Down
55 changes: 37 additions & 18 deletions src/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,53 @@ const normalizePath = originalPath => {
}

const absoluteVulmixPaths = () => {
return {
absoluteRootPath: normalizePath(path.resolve(__dirname, '../../../..')),

absolutePackagePath: normalizePath(path.resolve(__dirname, '../..')),
const absoluteRootPath = normalizePath(path.resolve(__dirname, '../../../..'))
const VULMIX_CONFIG_PATH = `${absoluteRootPath}/.vulmix/vulmix.config.js`
const VulmixConfig = require(VULMIX_CONFIG_PATH).default
const absolutePackagePath = normalizePath(path.resolve(__dirname, '../..'))
const absolutePublicPath = normalizePath(
path.resolve(__dirname, `${absoluteRootPath}/_dist`)
)
const absoluteSrcPath = normalizePath(
path.resolve(
__dirname,
`${absoluteRootPath}/${VulmixConfig?.dirs?.src || ''}`
)
)

absolutePublicPath: normalizePath(
path.resolve(__dirname, '../../../../_dist')
),
return {
absoluteRootPath,
absolutePackagePath,
absolutePublicPath,
absoluteSrcPath,
}
}

const relativeVulmixPaths = () => {
const ABSOLUTE_ROOT_PATH = absoluteVulmixPaths().absoluteRootPath
const ABSOLUTE_PACKAGE_PATH = absoluteVulmixPaths().absolutePackagePath
const ABSOLUTE_PUBLIC_PATH = absoluteVulmixPaths().absolutePublicPath
const ABSOLUTE_SRC_PATH = absoluteVulmixPaths().absoluteSrcPath

const relativePackagePath = getRelativePath(
ABSOLUTE_ROOT_PATH,
ABSOLUTE_PACKAGE_PATH
)
const relativePublicPath = getRelativePath(
ABSOLUTE_ROOT_PATH,
ABSOLUTE_PUBLIC_PATH
)
const relativeRootPath = getRelativePath(
ABSOLUTE_ROOT_PATH,
ABSOLUTE_ROOT_PATH
)
const relativeSrcPath = getRelativePath(ABSOLUTE_ROOT_PATH, ABSOLUTE_SRC_PATH)

return {
relativePackagePath: getRelativePath(
ABSOLUTE_ROOT_PATH,
ABSOLUTE_PACKAGE_PATH
),

relativePublicPath: getRelativePath(
ABSOLUTE_ROOT_PATH,
ABSOLUTE_PUBLIC_PATH
),

relativeRootPath: getRelativePath(ABSOLUTE_ROOT_PATH, ABSOLUTE_ROOT_PATH),
relativePackagePath,
relativePublicPath,
relativeRootPath,
relativeSrcPath,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class VulmixInit {
register() {
const VULMIX_CONFIG_PATH = `${ABSOLUTE_ROOT_PATH}/.vulmix/vulmix.config.js`

/**
* @type {import('../types/vulmix-config').VulmixConfig}
*/
const VulmixConfig = require(VULMIX_CONFIG_PATH).default
const APP_PUBLIC_PATH = VulmixConfig.dirs?.public
? `${ABSOLUTE_ROOT_PATH}/${VulmixConfig.dirs?.public?.replace('/', '')}/`
Expand Down
1 change: 1 addition & 0 deletions types/vulmix-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface VulmixConfig {

dirs?: {
public?: string
src?: string
},

head?: {
Expand Down
9 changes: 0 additions & 9 deletions utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
"noImplicitAny": false,
"outDir": "../../.vulmix/client",
"baseUrl": "../..",
"paths": {
"~/*": ["./*"],
"@/*": ["./*"],
"@assets/*": ["./assets/*"],
"@components/*": ["./components/*"],
"@composables/*": ["./composables/*"],
"@layouts/*": ["./layouts/*"],
"@pages/*": ["./pages/*"]
}
},
"include": [
"../../**/*",
Expand Down

0 comments on commit f930b25

Please sign in to comment.