@citestyle/styles 0.0.2 → 0.1.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/build.js ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Build script for @citestyle/styles
5
+ *
6
+ * Compiles CSL XML source files into JavaScript modules using the
7
+ * @citestyle/compiler. The CSL sources live in test/fixtures/ at the
8
+ * monorepo root — these are the canonical CSL style definitions.
9
+ *
10
+ * Each compiled style is a self-contained ES module (~3-50KB) that
11
+ * exports { meta, bibliography, citation, bibliographySort }.
12
+ *
13
+ * Usage:
14
+ * node build.js # Compile all styles listed in STYLES
15
+ * node build.js --clean # Remove compiled files first
16
+ */
17
+
18
+ import { execSync } from 'node:child_process'
19
+ import { existsSync, unlinkSync, readdirSync } from 'node:fs'
20
+ import { join, dirname } from 'node:path'
21
+ import { fileURLToPath } from 'node:url'
22
+
23
+ const __dirname = dirname(fileURLToPath(import.meta.url))
24
+ const ROOT = join(__dirname, '../..')
25
+ const FIXTURES = join(ROOT, 'test/fixtures')
26
+ const CLI = join(ROOT, 'packages/compiler/src/cli.js')
27
+
28
+ /**
29
+ * Styles to compile.
30
+ *
31
+ * Each entry maps a CSL filename (in test/fixtures/) to its output name.
32
+ * The output name must match the exports map in package.json.
33
+ *
34
+ * To add a new style:
35
+ * 1. Add the .csl file to test/fixtures/
36
+ * 2. Add an entry here
37
+ * 3. Add the export to package.json: "./name": "./name.js"
38
+ */
39
+ const STYLES = [
40
+ // Core academic styles
41
+ 'apa',
42
+ 'mla',
43
+ 'chicago-author-date',
44
+ 'ieee',
45
+ 'vancouver',
46
+ 'harvard',
47
+
48
+ // Additional popular styles
49
+ 'ama',
50
+ 'nature',
51
+ 'science',
52
+ ]
53
+
54
+ // Parse args
55
+ const args = process.argv.slice(2)
56
+ const clean = args.includes('--clean')
57
+
58
+ if (clean) {
59
+ console.log('Cleaning compiled styles...')
60
+ for (const file of readdirSync(__dirname)) {
61
+ if (file.endsWith('.js') && file !== 'build.js') {
62
+ unlinkSync(join(__dirname, file))
63
+ console.log(` Removed ${file}`)
64
+ }
65
+ }
66
+ }
67
+
68
+ console.log(`Compiling ${STYLES.length} styles...\n`)
69
+
70
+ let failed = 0
71
+
72
+ for (const style of STYLES) {
73
+ const input = join(FIXTURES, `${style}.csl`)
74
+ const output = join(__dirname, `${style}.js`)
75
+
76
+ if (!existsSync(input)) {
77
+ console.error(`✗ ${style}: source not found at ${input}`)
78
+ failed++
79
+ continue
80
+ }
81
+
82
+ try {
83
+ execSync(`node ${CLI} compile ${input} -o ${output}`, {
84
+ cwd: ROOT,
85
+ stdio: 'inherit',
86
+ })
87
+ } catch {
88
+ console.error(`✗ ${style}: compilation failed`)
89
+ failed++
90
+ }
91
+ }
92
+
93
+ console.log(`\nDone. ${STYLES.length - failed}/${STYLES.length} styles compiled.`)
94
+
95
+ if (failed > 0) {
96
+ process.exit(1)
97
+ }