Comparing version 1.0.4 to 1.0.5
const { Command } = require('commander'); | ||
const { downloadRepository } = require('../git'); | ||
const path = require('node:path'); | ||
const { execSync } = require('node:child_process'); | ||
const { slugify } = require('../strings'); | ||
@@ -10,2 +12,5 @@ const initCommand = new Command('init') | ||
const installationPath = path.join(process.cwd(), name); | ||
const sanitizedName = slugify(name) | ||
const functionId = `bless-function_${sanitizedName}-1.0.0`; | ||
console.log(`Initializing a new project at ${installationPath}...`); | ||
@@ -17,2 +22,9 @@ try { | ||
}); | ||
console.log("Initializing dependencies..."); | ||
execSync(`cd ${installationPath}; npm pkg set name=${sanitizedName}`) | ||
execSync(`cd ${installationPath}; npm pkg set bls.functionId=${functionId}`) | ||
execSync(`cd ${installationPath}; npm install`, { stdio: 'ignore' }) | ||
console.log('Project initialized successfully.'); | ||
@@ -19,0 +31,0 @@ } catch (error) { |
const fs = require('node:fs'); | ||
const { stringify, parse } = require('@iarna/toml'); | ||
/** | ||
* Generate a base BLS function config | ||
* | ||
*/ | ||
function generateBaseConfig({ framework, name, version, isPrivate }) { | ||
const defaultConfig = { | ||
name, | ||
version, | ||
deployment: { | ||
nodes: 1 | ||
} | ||
}; | ||
if (framework === 'site') { | ||
defaultConfig.type = 'site'; | ||
defaultConfig.content_type = 'html'; | ||
defaultConfig.build = { | ||
dir: '.bls', | ||
public_dir: 'out', | ||
entry: `${name}_debug.wasm`, | ||
command: 'npm run build && npm run export' | ||
}; | ||
defaultConfig.build_release = { | ||
dir: '.bls', | ||
public_dir: 'out', | ||
entry: `${name}.wasm`, | ||
command: 'npm run build && npm run export' | ||
}; | ||
} else if (framework === 'assemblyscript') { | ||
defaultConfig.build = { | ||
dir: 'build', | ||
entry: `${name}_debug.wasm`, | ||
command: 'npm run build:debug' | ||
}; | ||
defaultConfig.build_release = { | ||
dir: 'build', | ||
entry: `${name}.wasm`, | ||
command: 'npm run build:release' | ||
}; | ||
} else if (framework === 'rust') { | ||
defaultConfig.build = { | ||
dir: 'target/wasm32-wasi/debug', | ||
entry: `${name}.wasm`, | ||
command: 'cargo build --target wasm32-wasi' | ||
}; | ||
defaultConfig.build_release = { | ||
dir: 'target/wasm32-wasi/release', | ||
entry: `${name}.wasm`, | ||
command: 'cargo build --target wasm32-wasi --release' | ||
}; | ||
} else if (framework === 'typescript') { | ||
defaultConfig.build = { | ||
dir: 'build', | ||
entry: `${name}_debug.wasm`, | ||
command: 'npm run build:debug' | ||
}; | ||
defaultConfig.build_release = { | ||
dir: 'build', | ||
entry: `${name}.wasm`, | ||
command: 'npm run build:release' | ||
}; | ||
} | ||
return defaultConfig; | ||
} | ||
/** | ||
@@ -105,3 +40,3 @@ * Helper function to parse a BLS config file | ||
try { | ||
const configPath = filePath + '/' + fileName; | ||
const configPath = `${filePath}/${fileName}`; | ||
return parse(fs.readFileSync(configPath, 'utf-8')); | ||
@@ -123,3 +58,3 @@ } catch (error) { | ||
const configData = stringify(json); | ||
const configPath = filePath + '/' + fileName; | ||
const configPath = `${filePath}/${fileName}`; | ||
return fs.writeFileSync(configPath, configData, { flag: "w" }); | ||
@@ -129,7 +64,4 @@ } | ||
module.exports = { | ||
generateBaseConfig, | ||
parseBlsConfig, | ||
saveBlsConfig, | ||
parseTomlConfig, | ||
saveTomlConfig | ||
saveBlsConfig | ||
}; |
42
index.js
@@ -10,20 +10,42 @@ #!/usr/bin/env node | ||
// Check if the package is unpublished and running linked | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
const { getRuntime } = require('./bins'); | ||
// checks | ||
const isLinked = require('node:fs').existsSync(require('node:path').join(__dirname, 'node_modules', '.bin')); | ||
const version = isLinked ? `${packageJson.version}-dev` : packageJson.version; | ||
const blessnetDir = path.join(require('node:os').homedir(), '.blessnet'); | ||
const runtimePath = path.join(blessnetDir, 'bin', 'bls-runtime'); | ||
// Import commands | ||
// commands | ||
const initCommand = require('./commands/init'); | ||
const walletCommand = require('./commands/wallet'); | ||
const buildCommand = require('./commands/build'); | ||
program | ||
.name(packageJson.name) | ||
.description(packageJson.description) | ||
.version(version); | ||
async function main() { | ||
// Register commands | ||
program.addCommand(initCommand); | ||
program.addCommand(walletCommand); | ||
if (!fs.existsSync(runtimePath)) { | ||
console.log('bls-runtime not found, downloading...'); | ||
await getRuntime().catch(err => { | ||
console.error('Failed to download bls-runtime:', err); | ||
process.exit(1); | ||
}); | ||
process.exit(0); | ||
} | ||
program.parse(process.argv); | ||
program | ||
.name(packageJson.name) | ||
.description(packageJson.description) | ||
.version(version); | ||
// Register commands | ||
program.addCommand(initCommand); | ||
program.addCommand(walletCommand); | ||
program.addCommand(buildCommand); | ||
program.parse(process.argv); | ||
} | ||
main() |
{ | ||
"name": "blessnet", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "The CLI tool for interacting with blessnet", | ||
@@ -20,4 +20,6 @@ "main": "index.js", | ||
"commander": "12.1.0", | ||
"simple-git": "^3.27.0" | ||
"follow-redirects": "^1.15.9", | ||
"simple-git": "^3.27.0", | ||
"unique-names-generator": "^4.7.1" | ||
} | ||
} |
@@ -7,17 +7,30 @@ # blessnet | ||
Create a new project with the name `foo` | ||
Create a new project with the name `foo`, the project will have a folder created called `foo` | ||
```bash | ||
npx blessnet init foo | ||
cd foo | ||
``` | ||
### project structure | ||
```text | ||
. | ||
├── bls.toml # project config | ||
├── index.ts # entry | ||
├── package.json # javascript packages | ||
├── tsconfig.base.json # typescript configs | ||
├── tsconfig.debug.json # typescript configs | ||
└── tsconfig.release.json # typescript configs | ||
``` | ||
## other things | ||
Install `blessnet` globally for use without npx. | ||
```bash | ||
npm i -g blessnet | ||
``` | ||
## other things | ||
```bash | ||
npx blessnet wallet list | ||
``` |
18417
15
449
35
8
+ Addedfollow-redirects@^1.15.9
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedunique-names-generator@4.7.1(transitive)