vitrify 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app-urls.js CHANGED
@@ -7,17 +7,18 @@ export const getPkgJsonDir = (dir) => {
7
7
  }
8
8
  return getPkgJsonDir(new URL('..', dir));
9
9
  };
10
- export const appDir = getPkgJsonDir(new URL(`file://${process.cwd()}/`));
11
- export const cliDir = getPkgJsonDir(new URL('./', import.meta.url));
12
- export const cliViteDir = new URL('src/vite/', cliDir);
13
- export const srcDir = new URL('src/', appDir);
10
+ export const getAppDir = () => getPkgJsonDir(new URL(`file://${process.cwd()}/`));
11
+ export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url));
12
+ export const getCliViteDir = (cliDir) => new URL('src/vite/', cliDir);
13
+ export const getSrcDir = (appDir) => new URL('src/', appDir);
14
+ export const getCwd = () => new URL(`file://${process.cwd()}/`);
14
15
  // export const quasarDir = getPkgJsonDir(new URL('./', await resolve('quasar', appDir.href)))
15
- export const parsePath = (path) => {
16
+ export const parsePath = (path, basePath) => {
16
17
  if (path) {
17
18
  if (path.slice(-1) !== '/')
18
19
  path += '/';
19
20
  if (path.startsWith('.')) {
20
- return new URL(path, appDir);
21
+ return new URL(path, basePath);
21
22
  }
22
23
  else if (path) {
23
24
  return new URL(`file://${path}`);
@@ -25,8 +26,11 @@ export const parsePath = (path) => {
25
26
  }
26
27
  return;
27
28
  };
28
- export const projectURLs = {
29
- src: (path) => new URL(path, srcDir),
30
- app: (path) => new URL(path, appDir),
31
- cli: (path) => new URL(path, cliDir)
29
+ export const getProjectURLs = (appDir, cliDir) => {
30
+ const srcDir = getSrcDir(appDir);
31
+ return {
32
+ src: (path) => new URL(path, srcDir),
33
+ app: (path) => new URL(path, appDir),
34
+ cli: (path) => new URL(path, cliDir)
35
+ };
32
36
  };
package/dist/bin/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import cac from 'cac';
3
- import { appDir as defaultAppDir, parsePath } from '../app-urls.js';
3
+ import { getAppDir, parsePath } from '../app-urls.js';
4
4
  import { printHttpServerUrls } from '../helpers/logger.js';
5
5
  const cli = cac('vitrify');
6
6
  cli
@@ -21,13 +21,13 @@ cli
21
21
  appDir = new URL(`file://${options.appDir}`);
22
22
  }
23
23
  else {
24
- appDir = defaultAppDir;
24
+ appDir = getAppDir();
25
25
  }
26
- const baseOutDir = parsePath(options.outDir) || new URL('dist/', appDir);
26
+ const baseOutDir = parsePath(options.outDir, appDir) || new URL('dist/', appDir);
27
27
  const args = {
28
28
  base: options.base,
29
29
  appDir,
30
- publicDir: parsePath(options.publicDir)
30
+ publicDir: parsePath(options.publicDir, appDir)
31
31
  };
32
32
  switch (options.mode) {
33
33
  case 'csr':
@@ -87,22 +87,23 @@ cli
87
87
  options.host = '0.0.0.0';
88
88
  }
89
89
  const { createServer } = await import('./dev.js');
90
+ const cwd = (await import('../app-urls.js')).getCwd();
90
91
  switch (options.mode) {
91
92
  case 'ssr':
92
93
  ;
93
94
  ({ server, vite } = await createServer({
94
95
  mode: 'ssr',
95
96
  host: options.host,
96
- appDir: parsePath(options.appDir),
97
- publicDir: parsePath(options.publicDir)
97
+ appDir: parsePath(options.appDir, cwd),
98
+ publicDir: parsePath(options.publicDir, cwd)
98
99
  }));
99
100
  break;
100
101
  default:
101
102
  ;
102
103
  ({ server, vite } = await createServer({
103
104
  host: options.host,
104
- appDir: parsePath(options.appDir),
105
- publicDir: parsePath(options.publicDir)
105
+ appDir: parsePath(options.appDir, cwd),
106
+ publicDir: parsePath(options.publicDir, cwd)
106
107
  }));
107
108
  break;
108
109
  }
@@ -118,7 +119,7 @@ cli.command('test').action(async (options) => {
118
119
  appDir = new URL(`file://${options.appDir}`);
119
120
  }
120
121
  else {
121
- appDir = defaultAppDir;
122
+ appDir = getAppDir();
122
123
  }
123
124
  await test({
124
125
  appDir
package/dist/bin/dev.js CHANGED
@@ -3,10 +3,11 @@ import { baseConfig } from '../index.js';
3
3
  import fastify from 'fastify';
4
4
  import { readFileSync } from 'fs';
5
5
  export async function createServer({ port = 3000, logLevel = 'info', mode = 'csr', framework = 'vue', host, appDir, publicDir }) {
6
- const { appDir: tempAppDir, cliDir } = await import('../app-urls.js');
7
- const cwd = appDir || tempAppDir;
6
+ const { getAppDir, getCliDir, getCwd } = await import('../app-urls.js');
7
+ const cwd = getCwd();
8
+ const cliDir = getCliDir();
8
9
  if (!appDir)
9
- appDir = tempAppDir;
10
+ appDir = getAppDir();
10
11
  const { fastifySsrPlugin } = await import(`../${framework}/fastify-ssr-plugin.js`);
11
12
  /**
12
13
  * @type {import('vite').ViteDevServer}
@@ -25,6 +26,7 @@ export async function createServer({ port = 3000, logLevel = 'info', mode = 'csr
25
26
  fs: {
26
27
  allow: [
27
28
  searchForWorkspaceRoot(process.cwd()),
29
+ searchForWorkspaceRoot(appDir.pathname),
28
30
  searchForWorkspaceRoot(cliDir.pathname)
29
31
  // appDir.pathname,
30
32
  ]
package/dist/bin/run.js CHANGED
@@ -1,13 +1,16 @@
1
- import { projectURLs } from '../app-urls.js';
2
1
  import { promises as fs } from 'fs';
3
2
  import readline from 'readline';
4
- const pkg = JSON.parse((await fs.readFile(projectURLs.cli('package.json'), 'utf-8')).toString());
3
+ import { getAppDir, getCliDir, getProjectURLs } from '../app-urls.js';
5
4
  const rl = readline.createInterface({
6
5
  input: process.stdin,
7
6
  output: process.stdout
8
7
  });
9
8
  export async function run(filePath) {
10
9
  const { run } = await import(filePath);
10
+ const appDir = getAppDir();
11
+ const cliDir = getCliDir();
12
+ const projectURLs = getProjectURLs(appDir, cliDir);
13
+ const pkg = JSON.parse((await fs.readFile(projectURLs.cli('package.json'), 'utf-8')).toString());
11
14
  if (!run)
12
15
  throw new Error(`${filePath} does not have an export named run. Aborting...`);
13
16
  rl.question(`
package/dist/index.js CHANGED
@@ -17,11 +17,22 @@ export const VIRTUAL_MODULES = [
17
17
  'virtual:static-imports'
18
18
  ];
19
19
  export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
20
- const { appDir: tempAppDir, cliDir, cliViteDir, srcDir } = await import('./app-urls.js');
21
- const cwd = appDir || tempAppDir;
20
+ const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
21
+ if (!appDir) {
22
+ appDir = getAppDir();
23
+ }
24
+ const srcDir = getSrcDir(appDir);
25
+ const cwd = getCwd();
26
+ const cliDir = getCliDir();
27
+ const cliViteDir = getCliViteDir(cliDir);
28
+ // const {
29
+ // appDir: tempAppDir,
30
+ // cliDir,
31
+ // cliViteDir,
32
+ // srcDir
33
+ // } = await import('./app-urls.js')
34
+ // const cwd = appDir || tempAppDir
22
35
  const frameworkDir = new URL(`${framework}/`, cliViteDir);
23
- if (!appDir)
24
- appDir = tempAppDir;
25
36
  // const localPackages = ['vue', 'vue-router', 'quasar']
26
37
  const localPackages = ['vue', 'vue-router'];
27
38
  const cliPackages = ['vitest'];
@@ -61,17 +72,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
61
72
  console.log('No vitrify.config.js file found, using defaults');
62
73
  vitrifyConfig = {};
63
74
  }
64
- const { productName = 'Product name' } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
75
+ let { productName = 'Product name' } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
65
76
  encoding: 'utf-8'
66
77
  }));
67
78
  const fastifySetup = vitrifyConfig.vitrify?.fastify?.setup || ((fastify) => { });
68
- const sass = [];
69
- const sassVariables = vitrifyConfig.vitrify?.sassVariables;
70
- if (sassVariables) {
71
- for (const variable in sassVariables) {
72
- sass.push(`${variable}: ${sassVariables[variable]}`);
73
- }
74
- }
75
79
  const ssrTransformCustomDir = () => {
76
80
  return {
77
81
  props: [],
@@ -93,6 +97,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
93
97
  let onMountedHooks;
94
98
  let globalCss;
95
99
  let staticImports;
100
+ let sassVariables;
101
+ let additionalData;
96
102
  const plugins = [
97
103
  vuePlugin({
98
104
  template: {
@@ -121,7 +127,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
121
127
  // // quasarDir: packageUrls.quasar
122
128
  // }),
123
129
  {
124
- name: 'vitrify-virtual-modules',
130
+ name: 'vitrify-setup',
125
131
  enforce: 'post',
126
132
  config: async (config, env) => {
127
133
  bootFunctions = config.vitrify?.bootFunctions || [];
@@ -129,6 +135,27 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
129
135
  onMountedHooks = config.vitrify?.hooks?.onMounted || [];
130
136
  globalCss = config.vitrify?.globalCss || [];
131
137
  staticImports = config.vitrify?.staticImports || {};
138
+ sassVariables = config.vitrify?.sass?.variables || {};
139
+ additionalData = config.vitrify?.sass?.additionalData || [];
140
+ return {
141
+ css: {
142
+ preprocessorOptions: {
143
+ sass: {
144
+ additionalData: [
145
+ ...Object.entries(sassVariables).map(([key, value]) => `${key}: ${value}`),
146
+ ...additionalData
147
+ // config.css?.preprocessorOptions?.sass.additionalData
148
+ ].join('\n')
149
+ }
150
+ }
151
+ }
152
+ };
153
+ },
154
+ configResolved: (config) => {
155
+ if (process.env.DEBUG) {
156
+ console.log(config.css?.preprocessorOptions?.sass.additionalData);
157
+ console.log(config.optimizeDeps);
158
+ }
132
159
  },
133
160
  resolveId(id) {
134
161
  if (VIRTUAL_MODULES.includes(id))
@@ -170,6 +197,20 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
170
197
  plugins.unshift({
171
198
  name: 'html-transform',
172
199
  enforce: 'pre',
200
+ config: (config, env) => {
201
+ if (config.vitrify?.productName)
202
+ productName = config.vitrify?.productName;
203
+ },
204
+ transform: (code, id) => {
205
+ if (id.endsWith('App.vue')) {
206
+ code =
207
+ code +
208
+ `<style lang="sass">
209
+ // do not remove, required for additionalData import
210
+ </style>`;
211
+ }
212
+ return code;
213
+ },
173
214
  transformIndexHtml: {
174
215
  enforce: 'pre',
175
216
  transform: (html) => {
@@ -267,13 +308,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
267
308
  }
268
309
  }
269
310
  },
270
- css: {
271
- preprocessorOptions: {
272
- sass: {
273
- additionalData: [...sass].join('\n') + '\n'
274
- }
275
- }
276
- },
311
+ // css: {
312
+ // preprocessorOptions: {
313
+ // sass: {
314
+ // additionalData: sass ? [...sass].join('\n') : undefined
315
+ // }
316
+ // }
317
+ // },
277
318
  ssr: {
278
319
  // Create a SSR bundle
279
320
  noExternal: [
@@ -91,7 +91,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
91
91
  // @ts-ignore
92
92
  const quasarPlugins = await import('virtual:quasar-plugins');
93
93
  // @ts-ignore
94
- const directives = await import('quasar/directives');
94
+ const directives = await import('quasar/src/directives.js');
95
95
  app.use(staticImports.Quasar, {
96
96
  plugins: quasarPlugins,
97
97
  directives
@@ -109,6 +109,9 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
109
109
  },
110
110
  hooks: {
111
111
  onMounted: onMountedHooks
112
+ },
113
+ sass: {
114
+ additionalData: [`@import 'quasar/src/css/index.sass'`]
112
115
  }
113
116
  }
114
117
  };
@@ -237,18 +240,19 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
237
240
  __QUASAR_SSR_CLIENT__: ssr === 'client',
238
241
  __QUASAR_SSR_PWA__: ssr === 'client' && pwa
239
242
  },
240
- css: {
241
- preprocessorOptions: {
242
- sass: {
243
- additionalData: [
244
- // ...extras.map(extra => `@import "@quasar/extras/${extra}/${extra}.css"`),
245
- // ...extras.map(extra => `@import ${new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname}`) || [],
246
- config.css?.preprocessorOptions?.sass?.additionalData,
247
- `@import 'quasar/src/css/index.sass'`
248
- ].join('\n') + '\n'
249
- }
250
- }
251
- },
243
+ // css: {
244
+ // preprocessorOptions: {
245
+ // sass: {
246
+ // additionalData: `@import 'quasar/src/css/index.sass'`
247
+ // // [
248
+ // // // ...extras.map(extra => `@import "@quasar/extras/${extra}/${extra}.css"`),
249
+ // // // ...extras.map(extra => `@import ${new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname}`) || [],
250
+ // // // config.css?.preprocessorOptions?.sass?.additionalData,
251
+ // // `@import 'quasar/src/css/index.sass'`
252
+ // // ].join('\n')
253
+ // }
254
+ // }
255
+ // },
252
256
  ssr: {
253
257
  noExternal: ['quasar']
254
258
  }
@@ -284,6 +288,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
284
288
  export * from 'quasar/src/components.js';
285
289
  export * from 'quasar/src/composables.js';
286
290
  export * from 'quasar/src/directives.js';
291
+ export * from 'quasar/src/utils.js';
287
292
  export { default as Quasar } from 'quasar/src/vue-plugin.js'`;
288
293
  }
289
294
  return null;
@@ -1,10 +1,11 @@
1
1
  export declare const getPkgJsonDir: (dir: URL) => URL;
2
- export declare const appDir: URL;
3
- export declare const cliDir: URL;
4
- export declare const cliViteDir: URL;
5
- export declare const srcDir: URL;
6
- export declare const parsePath: (path: string) => URL | undefined;
7
- export declare const projectURLs: {
2
+ export declare const getAppDir: () => URL;
3
+ export declare const getCliDir: () => URL;
4
+ export declare const getCliViteDir: (cliDir: URL) => URL;
5
+ export declare const getSrcDir: (appDir: URL) => URL;
6
+ export declare const getCwd: () => URL;
7
+ export declare const parsePath: (path: string, basePath: URL) => URL | undefined;
8
+ export declare const getProjectURLs: (appDir: URL, cliDir: URL) => {
8
9
  src: (path: string) => URL;
9
10
  app: (path: string) => URL;
10
11
  cli: (path: string) => URL;
@@ -1,8 +1,8 @@
1
- import { projectURLs } from '../app-urls.js';
1
+ import { getProjectURLs } from '../app-urls.js';
2
2
  export interface VitrifyContext {
3
3
  vitrify: {
4
4
  version: string;
5
5
  };
6
- projectURLs: typeof projectURLs;
6
+ projectURLs: ReturnType<typeof getProjectURLs>;
7
7
  }
8
8
  export declare function run(filePath: string): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { InlineConfig } from 'vite';
2
- import type { VitrifyConfig } from './vitrify-config.js';
2
+ import type { BootFunction, VitrifyConfig } from './vitrify-config.js';
3
3
  import type { VitrifyContext } from './bin/run.js';
4
4
  import type { VitrifyPlugin } from './plugins/index.js';
5
5
  export declare const VIRTUAL_MODULES: string[];
@@ -12,4 +12,4 @@ export declare const baseConfig: ({ ssr, appDir, publicDir, command, mode, frame
12
12
  framework?: "vue" | undefined;
13
13
  pwa?: boolean | undefined;
14
14
  }) => Promise<InlineConfig>;
15
- export type { VitrifyConfig, VitrifyPlugin, VitrifyContext };
15
+ export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction };
@@ -37,7 +37,10 @@ export interface VitrifyConfig extends UserConfig {
37
37
  /**
38
38
  * Global SASS variables
39
39
  */
40
- sassVariables?: Record<string, string>;
40
+ sass?: {
41
+ variables?: Record<string, string>;
42
+ additionalData?: string[];
43
+ };
41
44
  fastify?: {
42
45
  /**
43
46
  * setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Pre-configured Vite CLI for your framework",
@@ -25,18 +25,18 @@
25
25
  "./dist/types/helpers/*.d.ts"
26
26
  ],
27
27
  "build": [
28
- "./dist/types/node/build.d.ts"
28
+ "./dist/types/bin/build.d.ts"
29
29
  ],
30
30
  "dev": [
31
- "./dist/types/node/dev.d.ts"
31
+ "./dist/types/bin/dev.d.ts"
32
32
  ],
33
33
  "help": [
34
- "./dist/types/node/help.d.ts"
34
+ "./dist/types/bin/help.d.ts"
35
35
  ]
36
36
  }
37
37
  },
38
38
  "engines": {
39
- "node": ">=12.2.0"
39
+ "node": ">=16.0.0"
40
40
  },
41
41
  "repository": {
42
42
  "type": "git",
@@ -54,15 +54,15 @@
54
54
  "dependencies": {
55
55
  "@quasar/extras": "^1.13.5",
56
56
  "@vitejs/plugin-vue": "^2.3.1",
57
- "@vue/compiler-sfc": "^3.2.31",
58
- "@vue/server-renderer": "^3.2.31",
57
+ "@vue/compiler-sfc": "^3.2.33",
58
+ "@vue/server-renderer": "^3.2.33",
59
59
  "builtin-modules": "^3.2.0",
60
60
  "cac": "^6.7.12",
61
61
  "chalk": "^5.0.1",
62
62
  "cross-env": "^7.0.3",
63
63
  "fastify": "^3.28.0",
64
64
  "fastify-static": "^4.6.1",
65
- "glob": "^7.2.0",
65
+ "glob": "^8.0.1",
66
66
  "happy-dom": "^2.55.0",
67
67
  "import-meta-resolve": "^1.1.1",
68
68
  "local-pkg": "^0.4.1",
@@ -71,22 +71,21 @@
71
71
  "middie": "^6.0.0",
72
72
  "readline": "^1.3.0",
73
73
  "sass": "1.50.0",
74
- "vite": "^2.9.1",
74
+ "vite": "^2.9.5",
75
75
  "vitest": "^0.9.3"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/glob": "^7.2.0",
79
79
  "@types/merge-deep": "^3.0.0",
80
- "@types/node": "^17.0.23",
80
+ "@types/node": "^17.0.24",
81
81
  "@types/ws": "^8.5.3",
82
- "@vue/runtime-core": "^3.2.31",
82
+ "@vue/runtime-core": "^3.2.33",
83
83
  "quasar": "^2.6.6",
84
84
  "rollup": "^2.70.1",
85
85
  "typescript": "^4.6.3",
86
- "unplugin-vue-components": "^0.19.2",
87
- "vite": "^2.9.1",
88
- "vitrify": "^0.1.1",
89
- "vue": "^3.2.31",
86
+ "unplugin-vue-components": "^0.19.3",
87
+ "vite": "^2.9.5",
88
+ "vue": "^3.2.33",
90
89
  "vue-router": "^4.0.14"
91
90
  },
92
91
  "peerDependencies": {
@@ -95,7 +94,7 @@
95
94
  "fastify-sensible": "^3.1.2",
96
95
  "fastify-static": "^4.6.1",
97
96
  "quasar": "^2.6.6",
98
- "vue": "^3.2.31",
97
+ "vue": "^3.2.33",
99
98
  "vue-router": "^4.0.14"
100
99
  },
101
100
  "publishConfig": {
@@ -1,25 +0,0 @@
1
- // generated by unplugin-vue-components
2
- // We suggest you to commit this file into source control
3
- // Read more: https://github.com/vuejs/vue-next/pull/3399
4
-
5
- declare module '@vue/runtime-core' {
6
- export interface GlobalComponents {
7
- QAvatar: typeof import('quasar')['QAvatar']
8
- QBtn: typeof import('quasar')['QBtn']
9
- QCard: typeof import('quasar')['QCard']
10
- QCardSection: typeof import('quasar')['QCardSection']
11
- QDrawer: typeof import('quasar')['QDrawer']
12
- QHeader: typeof import('quasar')['QHeader']
13
- QItemLabel: typeof import('quasar')['QItemLabel']
14
- QLayout: typeof import('quasar')['QLayout']
15
- QList: typeof import('quasar')['QList']
16
- QPage: typeof import('quasar')['QPage']
17
- QPageContainer: typeof import('quasar')['QPageContainer']
18
- QToolbar: typeof import('quasar')['QToolbar']
19
- QToolbarTitle: typeof import('quasar')['QToolbarTitle']
20
- RouterLink: typeof import('vue-router')['RouterLink']
21
- RouterView: typeof import('vue-router')['RouterView']
22
- }
23
- }
24
-
25
- export {}