@c6fc/spellcraft 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Brad Woodward
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # SpellCraft for JSonnet workflows
2
+
3
+ Spellcraft is an opinionated approach to manifesting and applying configurations for various tools. SpellCraft is the core engine which can accept plugins like @c6fc/spellcraft-packer for Hashicorp Packer configurations, or @c6fc/spellcraft-aws for interacting with Amazon Web Services
4
+
5
+ ## Installation
6
+
7
+ Install spellcraft with `npm install` and add plugins with `npx spellcraft importModule`
8
+
9
+ ```sh
10
+ $ npm i -p spellcraft
11
+ $ npx spellcraft importModule @c6fc/spellcraft-packer packer
12
+ ```
13
+
14
+ The importModule command above will expose the methods from `@c6fc/spellcraft-packer` with `local packer = require "packer"`
15
+
16
+
17
+ ## More details to be added soon
@@ -0,0 +1,146 @@
1
+ #! /usr/bin/env node
2
+
3
+ /**
4
+ * @fileOverview SpellCraft CLI tool.
5
+ * This script provides a command-line interface for interacting with the SpellFrame
6
+ * rendering engine. It allows users to generate configurations from Jsonnet files
7
+ * and manage SpellCraft modules.
8
+ * @module spellcraft-cli
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ const yargs = require('yargs');
14
+ const { hideBin } = require('yargs/helpers');
15
+ const { SpellFrame } = require('../src/index.js');
16
+
17
+ const spellframe = new SpellFrame();
18
+
19
+ // --- JSDoc Blocks for CLI Commands ---
20
+ // These blocks define the commands for JSDoc.
21
+ // They are not directly attached to yargs code but describe the CLI's public interface.
22
+
23
+ /**
24
+ * Generates files from a Jsonnet configuration.
25
+ * This command processes a specified Jsonnet configuration file using the SpellFrame engine,
26
+ * renders the output, and writes the resulting files to the configured directory.
27
+ *
28
+ * **Usage:** `spellcraft generate <filename>`
29
+ *
30
+ * @function generate
31
+ * @name module:spellcraft-cli.generate
32
+ * @param {object} argv - The arguments object provided by yargs.
33
+ * @param {string} argv.filename The path to the Jsonnet configuration file to consume. (Required)
34
+ *
35
+ * @example
36
+ * spellcraft generate ./myconfig.jsonnet
37
+ */
38
+
39
+ /**
40
+ * Links an npm package as a SpellCraft module for the current project.
41
+ * This command installs the specified npm package (if not already present) and
42
+ * registers it within the project's SpellCraft module configuration, making its
43
+ * functionalities available during the rendering process.
44
+ *
45
+ * **Usage:** `spellcraft importModule <npmPackage> [name]`
46
+ *
47
+ * @function importModule
48
+ * @name module:spellcraft-cli.importModule
49
+ * @param {object} argv - The arguments object provided by yargs.
50
+ * @param {string} argv.npmPackage The NPM package name of the SpellCraft Plugin to import. (Required)
51
+ * @param {string} [argv.name] An optional alias name to use for this module within SpellCraft.
52
+ * If not provided, a default name from the package may be used.
53
+ *
54
+ * @example
55
+ * spellcraft importModule my-spellcraft-enhancer
56
+ * @example
57
+ * spellcraft importModule @my-scope/spellcraft-utils customUtils
58
+ */
59
+
60
+ // --- End of JSDoc Blocks for CLI Commands ---
61
+
62
+ (async () => {
63
+ // No JSDoc for setupCli as it's an internal helper
64
+ function setupCli(sfInstance) {
65
+ let cli = yargs(hideBin(process.argv))
66
+ .usage("Syntax: $0 <command> [options]")
67
+ .scriptName("spellcraft")
68
+
69
+ .command("*", false, (yargsInstance) => { // 'false' for no yargs description
70
+ return yargsInstance;
71
+ }, (argv) => {
72
+ console.log("[~] That's too arcane. (Unrecognized command)");
73
+ })
74
+
75
+ .command("generate <filename>", "Generates files from a configuration", (yargsInstance) => {
76
+ return yargsInstance.positional('filename', {
77
+ describe: 'Jsonnet configuration file to consume',
78
+ type: 'string',
79
+ demandOption: true,
80
+ });
81
+ },
82
+ async (argv) => { // No JSDoc for internal handler
83
+ try {
84
+ await sfInstance.init();
85
+ console.log(`[+] Rendering configuration from: ${argv.filename}`);
86
+ await sfInstance.render(argv.filename);
87
+ await sfInstance.write();
88
+ console.log("[+] Generation complete.");
89
+ } catch (error) {
90
+ console.error(`[!] Error during generation: ${error.message}`);
91
+ process.exit(1);
92
+ }
93
+ })
94
+
95
+ .command("importModule <npmPackage> [name]", "Configures the current project to use a SpellCraft plugin as an import", (yargsInstance) => {
96
+ return yargsInstance
97
+ .positional('npmPackage', {
98
+ describe: 'The NPM package name of a SpellCraft Plugin to import',
99
+ type: 'string',
100
+ demandOption: true,
101
+ })
102
+ .positional('name', {
103
+ describe: 'Optional alias name for the module in SpellCraft',
104
+ type: 'string',
105
+ default: undefined,
106
+ });
107
+ },
108
+ async (argv) => { // No JSDoc for internal handler
109
+ try {
110
+ await sfInstance.importSpellCraftModuleFromNpm(argv.npmPackage, argv.name);
111
+ console.log(`[+] Module '${argv.npmPackage}' ${argv.name ? `(aliased as ${argv.name}) ` : ''}linked successfully.`);
112
+ } catch (error) {
113
+ console.error(`[!] Error importing module: ${error.message}`);
114
+ process.exit(1);
115
+ }
116
+ });
117
+
118
+ // No JSDoc for CLI extensions loop if considered internal detail
119
+ if (sfInstance.cliExtensions && sfInstance.cliExtensions.length > 0) {
120
+ sfInstance.cliExtensions.forEach((extensionFn) => {
121
+ if (typeof extensionFn === 'function') {
122
+ extensionFn(cli, sfInstance);
123
+ }
124
+ });
125
+ }
126
+
127
+ cli
128
+ .demandCommand(1, 'You need to specify a command.')
129
+ .recommendCommands()
130
+ .strict()
131
+ .showHelpOnFail(true)
132
+ .help("help")
133
+ .alias('h', 'help')
134
+ .version()
135
+ .alias('v', 'version')
136
+ .epilogue('For more information, consult the SpellCraft documentation.')
137
+ .argv;
138
+ }
139
+
140
+ try {
141
+ setupCli(spellframe);
142
+ } catch (error) {
143
+ console.error(`[!] A critical error occurred: ${error.message}`);
144
+ process.exit(1);
145
+ }
146
+ })();
@@ -0,0 +1,47 @@
1
+ #! /usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const yargs = require('yargs')
5
+ const { SpellFrame } = require('../src/index.js');
6
+
7
+ const spellframe = new SpellFrame();
8
+
9
+ (async () => {
10
+
11
+ yargs
12
+ .usage("Syntax: $0 <command> [options]")
13
+ .command("*", "That's too arcane", (yargs) => {
14
+ yargs
15
+ }, (argv) => {
16
+ console.log("[~] That's too arcane. (Unrecognized command)");
17
+ })
18
+ .command("generate <filename>", "Generates files from a configuration", (yargs) => {
19
+ return yargs.positional('filename', {
20
+ describe: 'Jsonnet configuration file to consume'
21
+ })
22
+ }, async (argv) => {
23
+
24
+ await spellframe.init();
25
+ await spellframe.render(argv.filename);
26
+ await spellframe.write();
27
+
28
+ })
29
+ .command("importModule <npmPackage> [name]", "Configures the current project to use a SpellCraft plugin as an import", (yargs) => {
30
+ return yargs.positional('npmPackage', {
31
+ describe: 'The NPM package name of a SpellCraft Plugin to import'
32
+ }).positional('name', {
33
+ describe: 'What name to use as the import namespace for this plugin'
34
+ })
35
+ }, async (argv) => {
36
+
37
+ await spellframe.importSpellCraftModuleFromNpm(argv['npmPackage'], argv['name']);
38
+
39
+ });
40
+
41
+ spellframe.cliExtensions.forEach((e, i) => e(yargs, spellframe));
42
+
43
+ yargs
44
+ .showHelpOnFail(false)
45
+ .help("help")
46
+ .argv;
47
+ })();
package/jsdoc.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "tags": {
3
+ "allowUnknownTags": true
4
+ },
5
+ "plugins": ["plugins/markdown"],
6
+ "opts": {
7
+ "destination": "./docs"
8
+ },
9
+ "source": {
10
+ "include": [
11
+ "src/",
12
+ "bin/",
13
+ "lib/"
14
+ ],
15
+ "includePattern": ".",
16
+ "excludePattern": "\\.bak$"
17
+ },
18
+ "opts": {
19
+ "destination": "./docs/",
20
+ "encoding": "utf8",
21
+ "private": true,
22
+ "recurse": false,
23
+ "readme": "README.md",
24
+ "template": "node_modules/clean-jsdoc-theme"
25
+ },
26
+ "markdown": {
27
+ "hardwrap": false,
28
+ "idInHeadings": true
29
+ },
30
+ "theme_opts": {
31
+ "default_theme": "dark"
32
+ }
33
+ }
package/lib/spellcraft ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ local sonnetry = self,
3
+
4
+ envvar(name):: std.native("envvar")(name),
5
+ path():: std.native("path")()
6
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "dependencies": {
3
+ "@hanazuki/node-jsonnet": "^0.4.2",
4
+ "ini": "^5.0.0",
5
+ "js-yaml": "^4.1.0",
6
+ "yargs": "^17.2.1"
7
+ },
8
+ "name": "@c6fc/spellcraft",
9
+ "description": "Extensible JSonnet CLI platform",
10
+ "version": "0.0.1",
11
+ "main": "src/index.js",
12
+ "directories": {
13
+ "lib": "lib"
14
+ },
15
+ "bin": {
16
+ "spellcraft": "bin/spellcraft.js"
17
+ },
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1",
20
+ "doc": "jsdoc -c jsdoc.json --verbose"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/c6fc/spellcraft.git"
25
+ },
26
+ "keywords": [
27
+ "jsonnet"
28
+ ],
29
+ "author": "Brad Woodward (brad@bradwoodward.io)",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/c6fc/spellcraft/issues"
33
+ },
34
+ "homepage": "https://github.com/c6fc/spellcraft#readme",
35
+ "devDependencies": {
36
+ "clean-jsdoc-theme": "^4.3.0",
37
+ "jsdoc": "^4.0.4"
38
+ }
39
+ }