Skip to content

Commit

Permalink
Inject process env on build
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Dec 14, 2022
1 parent 388b108 commit d9305c9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
54 changes: 40 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@
"gettext-extractor": "^3.6.0",
"gettext-parser": "^6.0.0",
"jsdom": "^20.0.3",
"rollup-plugin-inject-process-env": "^1.3.1",
"rollup-plugin-baked-env": "^1.0.0",
"rollup-plugin-node-externals": "^5.0.2",
"sanitize-filename": "^1.6.3",
"sass": "^1.56.2",
"vite": "^4.0.0",
"vitest": "^0.25.7",
"vitepress": "^1.0.0-alpha.31",
"vitest": "^0.25.7",
"vue-docgen-cli": "^4.56.1",
"vue-eslint-parser": "^9.1.0",
"vue-live": "^2.3.2"
Expand Down
5 changes: 3 additions & 2 deletions src/components/NcMultiselect/NcMultiselect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ import NcListItemIcon from '../NcListItemIcon/index.js'
import NcLoadingIcon from '../NcLoadingIcon/index.js'
import Tooltip from '../../directives/Tooltip/index.js'
import l10n from '../../mixins/l10n.js'
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
import { SCOPE_VERSION } from 'process.env'
import { Multiselect as VueMultiselect } from 'vue-multiselect'
export default {
Expand Down Expand Up @@ -364,7 +365,7 @@ export default {
return {
elWidth: 0,
ariaExpanded: false,
scoping: { [`data-v-${process.env.SCOPE_VERSION}`]: '' },
scoping: { [`data-v-${SCOPE_VERSION}`]: '' },
}
},
computed: {
Expand Down
6 changes: 4 additions & 2 deletions src/l10n.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getGettextBuilder } from '@nextcloud/l10n/dist/gettext.js'
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
import { TRANSLATIONS } from 'process.env'

const gtBuilder = getGettextBuilder()
.detectLocale()

// Decompress Translations to gettext format and add to gtBuilder
if (Array.isArray(process.env.TRANSLATIONS)) {
process.env.TRANSLATIONS.forEach((lang) => {
if (Array.isArray(TRANSLATIONS)) {
TRANSLATIONS.forEach((lang) => {
const translations = {}

for (const key in lang.translations) {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/ScopeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
import { SCOPE_VERSION } from 'process.env'

const ScopeComponent = (Component) => {
// Init mounted vue if none
Expand All @@ -30,7 +32,7 @@ const ScopeComponent = (Component) => {

// Inject root scoping function
Component.mounted.push(function() {
this.$el.setAttribute(`data-v-${process.env.SCOPE_VERSION}`, '')
this.$el.setAttribute(`data-v-${SCOPE_VERSION}`, '')
})
}

Expand Down
6 changes: 3 additions & 3 deletions vite.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import md5 from 'md5'
import vue from '@vitejs/plugin-vue'
import { externals } from 'rollup-plugin-node-externals'
import browserslistToEsbuild from 'browserslist-to-esbuild'
import injectProcessEnv from 'rollup-plugin-inject-process-env'
import bakedEnv from 'rollup-plugin-baked-env'
import { externals } from 'rollup-plugin-node-externals'
import { loadTranslations } from './resources/translations.mjs'
import { fileURLToPath, URL } from 'url'
import { dirname, resolve } from 'path'
Expand Down Expand Up @@ -66,7 +66,7 @@ export default defineConfig({
rollupOptions: {
plugins: [
externals(),
injectProcessEnv(processEnvironment),
bakedEnv(processEnvironment),
],
external: [
...Object.keys(loadJSON('./package.json').peerDependencies),
Expand Down

0 comments on commit d9305c9

Please sign in to comment.