fragment-tools 0.1.18 → 0.1.19
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/bin/index.js +3 -0
- package/package.json +1 -1
- package/src/cli/build.js +2 -1
- package/src/cli/createConfig.js +99 -52
- package/src/cli/run.js +2 -1
package/bin/index.js
CHANGED
|
@@ -28,6 +28,7 @@ prog.command('run [entry]', '', { default: true })
|
|
|
28
28
|
.option('--outDir', 'Build output directory')
|
|
29
29
|
.option('--emptyOutDir', 'Empty outDir before static build')
|
|
30
30
|
.option('--base', 'Base public path when served in production', undefined)
|
|
31
|
+
.option('--config', 'Path to Fragment config file')
|
|
31
32
|
.option('--prompts', 'Enable interactive prompts', true)
|
|
32
33
|
.action((entry, options) => {
|
|
33
34
|
if (options.new) {
|
|
@@ -43,6 +44,7 @@ prog.command('run [entry]', '', { default: true })
|
|
|
43
44
|
emptyOutDir: options.emptyOutDir,
|
|
44
45
|
base: options.base,
|
|
45
46
|
prompts: options.prompts,
|
|
47
|
+
configFilepath: options.config,
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -50,6 +52,7 @@ prog.command('run [entry]', '', { default: true })
|
|
|
50
52
|
development: options.development,
|
|
51
53
|
exportDir: options.exportDir,
|
|
52
54
|
port: options.port,
|
|
55
|
+
configFilepath: options.config,
|
|
53
56
|
});
|
|
54
57
|
});
|
|
55
58
|
|
package/package.json
CHANGED
package/src/cli/build.js
CHANGED
|
@@ -95,13 +95,14 @@ export async function build(entry, options) {
|
|
|
95
95
|
);
|
|
96
96
|
|
|
97
97
|
const fragmentFilepath = await createFragmentFile(entries, cwd);
|
|
98
|
-
const config = createConfig(
|
|
98
|
+
const config = await createConfig(
|
|
99
99
|
entries,
|
|
100
100
|
fragmentFilepath,
|
|
101
101
|
{
|
|
102
102
|
dev: options.development,
|
|
103
103
|
build: true,
|
|
104
104
|
},
|
|
105
|
+
options.configFilepath,
|
|
105
106
|
cwd,
|
|
106
107
|
);
|
|
107
108
|
|
package/src/cli/createConfig.js
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { defineConfig, loadConfigFromFile, mergeConfig } from 'vite';
|
|
3
4
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
4
5
|
|
|
5
6
|
import checkDependencies from './plugins/check-dependencies.js';
|
|
6
7
|
import { file } from './utils.js';
|
|
7
8
|
import { log } from './log.js';
|
|
8
9
|
|
|
10
|
+
export async function loadConfig({ cwd, filepath }) {
|
|
11
|
+
try {
|
|
12
|
+
let filename = `fragment.config.js`;
|
|
13
|
+
let configFile = filepath ? filepath : filename;
|
|
14
|
+
let configRoot = cwd;
|
|
15
|
+
let resolvedPath = path.resolve(cwd, configFile);
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
18
|
+
if (filepath) {
|
|
19
|
+
log.error(`Config file not found: ${resolvedPath}`);
|
|
20
|
+
}
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
log.info(`Extending configuration from ${resolvedPath}`);
|
|
25
|
+
|
|
26
|
+
const { config } = await loadConfigFromFile(
|
|
27
|
+
{
|
|
28
|
+
command: 'build',
|
|
29
|
+
mode: 'dev',
|
|
30
|
+
},
|
|
31
|
+
configFile,
|
|
32
|
+
configRoot,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return config;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
log.error(error);
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
9
42
|
/**
|
|
10
43
|
* Create Vite config from entries
|
|
11
44
|
* @param {string[]} entries
|
|
@@ -16,10 +49,11 @@ import { log } from './log.js';
|
|
|
16
49
|
* @param {string} [cwd=process.cwd()]
|
|
17
50
|
* @returns {import('vite').UserConfig}
|
|
18
51
|
*/
|
|
19
|
-
export function createConfig(
|
|
52
|
+
export async function createConfig(
|
|
20
53
|
entries,
|
|
21
54
|
fragmentFilepath,
|
|
22
55
|
{ dev = false, build = false } = {},
|
|
56
|
+
configFilepath,
|
|
23
57
|
cwd = process.cwd(),
|
|
24
58
|
) {
|
|
25
59
|
const entriesPaths = entries.map((entry) => path.join(cwd, entry));
|
|
@@ -28,55 +62,68 @@ export function createConfig(
|
|
|
28
62
|
|
|
29
63
|
log.info(`Creating Vite configuration...`);
|
|
30
64
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
logLevel: dev ? 'info' : 'silent',
|
|
35
|
-
resolve: {
|
|
36
|
-
alias: [
|
|
37
|
-
{ find: '@fragment/sketches', replacement: fragmentFilepath },
|
|
38
|
-
{ find: '@fragment', replacement: app },
|
|
39
|
-
{
|
|
40
|
-
find: 'three',
|
|
41
|
-
replacement: path.join(cwd, 'node_modules/three'),
|
|
42
|
-
},
|
|
43
|
-
{ find: 'p5', replacement: path.join(cwd, 'node_modules/p5') },
|
|
44
|
-
{
|
|
45
|
-
find: 'ogl',
|
|
46
|
-
replacement: path.join(cwd, 'node_modules/ogl'),
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
plugins: [
|
|
51
|
-
svelte({
|
|
52
|
-
configFile: false,
|
|
53
|
-
onwarn: (warning, handler) => {
|
|
54
|
-
if (dev) {
|
|
55
|
-
handler(warning);
|
|
56
|
-
} else {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
}),
|
|
61
|
-
checkDependencies({
|
|
62
|
-
cwd,
|
|
63
|
-
app,
|
|
64
|
-
entriesPaths,
|
|
65
|
-
build,
|
|
66
|
-
}),
|
|
67
|
-
],
|
|
68
|
-
|
|
69
|
-
define: {
|
|
70
|
-
__CWD__: `${JSON.stringify(cwd)}`,
|
|
71
|
-
__FRAGMENT_PORT__: undefined,
|
|
72
|
-
__START_TIME__: Date.now(),
|
|
73
|
-
__SEED__: Date.now(),
|
|
74
|
-
__BUILD__: build,
|
|
75
|
-
__DEV__: !build,
|
|
76
|
-
},
|
|
77
|
-
optimizeDeps: {
|
|
78
|
-
include: ['convert-length', 'webm-writer', 'changedpi'],
|
|
79
|
-
exclude: ['@fragment/sketches', ...entriesPaths],
|
|
80
|
-
},
|
|
65
|
+
const config = await loadConfig({
|
|
66
|
+
filepath: configFilepath,
|
|
67
|
+
cwd,
|
|
81
68
|
});
|
|
69
|
+
|
|
70
|
+
return mergeConfig(
|
|
71
|
+
defineConfig({
|
|
72
|
+
configFile: false,
|
|
73
|
+
root,
|
|
74
|
+
logLevel: dev ? 'info' : 'silent',
|
|
75
|
+
resolve: {
|
|
76
|
+
alias: [
|
|
77
|
+
{
|
|
78
|
+
find: '@fragment/sketches',
|
|
79
|
+
replacement: fragmentFilepath,
|
|
80
|
+
},
|
|
81
|
+
{ find: '@fragment', replacement: app },
|
|
82
|
+
{
|
|
83
|
+
find: 'three',
|
|
84
|
+
replacement: path.join(cwd, 'node_modules/three'),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
find: 'p5',
|
|
88
|
+
replacement: path.join(cwd, 'node_modules/p5'),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
find: 'ogl',
|
|
92
|
+
replacement: path.join(cwd, 'node_modules/ogl'),
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
plugins: [
|
|
97
|
+
svelte({
|
|
98
|
+
configFile: false,
|
|
99
|
+
onwarn: (warning, handler) => {
|
|
100
|
+
if (dev) {
|
|
101
|
+
handler(warning);
|
|
102
|
+
} else {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
checkDependencies({
|
|
108
|
+
cwd,
|
|
109
|
+
app,
|
|
110
|
+
entriesPaths,
|
|
111
|
+
build,
|
|
112
|
+
}),
|
|
113
|
+
],
|
|
114
|
+
define: {
|
|
115
|
+
__CWD__: `${JSON.stringify(cwd)}`,
|
|
116
|
+
__FRAGMENT_PORT__: undefined,
|
|
117
|
+
__START_TIME__: Date.now(),
|
|
118
|
+
__SEED__: Date.now(),
|
|
119
|
+
__BUILD__: build,
|
|
120
|
+
__DEV__: !build,
|
|
121
|
+
},
|
|
122
|
+
optimizeDeps: {
|
|
123
|
+
include: ['convert-length', 'webm-writer', 'changedpi'],
|
|
124
|
+
exclude: ['@fragment/sketches', ...entriesPaths],
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
config.vite ?? {},
|
|
128
|
+
);
|
|
82
129
|
}
|
package/src/cli/run.js
CHANGED
|
@@ -62,13 +62,14 @@ export async function run(entry, options = {}) {
|
|
|
62
62
|
cwd,
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
const config = createConfig(
|
|
65
|
+
const config = await createConfig(
|
|
66
66
|
entries,
|
|
67
67
|
fragmentFilepath,
|
|
68
68
|
{
|
|
69
69
|
dev: options.development,
|
|
70
70
|
build: false,
|
|
71
71
|
},
|
|
72
|
+
options.configFilepath,
|
|
72
73
|
cwd,
|
|
73
74
|
);
|
|
74
75
|
|