@xaidenlabs/uso 1.0.2 ā 1.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/README.md +89 -53
- package/bin/index.js +7 -1
- package/my-test-project/Anchor.toml +18 -0
- package/my-test-project/README.md +36 -0
- package/my-test-project/package-lock.json +2102 -0
- package/my-test-project/package.json +17 -0
- package/my-test-project/programs/my_test_project/Cargo.toml +19 -0
- package/my-test-project/programs/my_test_project/src/lib.rs +16 -0
- package/my-test-project/tests/my-test-project.ts +16 -0
- package/my-test-project/tsconfig.json +17 -0
- package/package.json +1 -1
- package/src/commands/create.js +115 -0
- package/templates/default/Anchor.toml +18 -0
- package/templates/default/README.md +36 -0
- package/templates/default/package.json +19 -0
- package/templates/default/programs/my-project/Cargo.lock +1471 -0
- package/templates/default/programs/my-project/Cargo.toml +19 -0
- package/templates/default/programs/my-project/src/lib.rs +16 -0
- package/templates/default/tests/my-project.ts +17 -0
- package/templates/default/tsconfig.json +18 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
|
|
4
|
+
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
|
|
5
|
+
},
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@coral-xyz/anchor": "^0.30.1"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"chai": "^4.3.7",
|
|
11
|
+
"mocha": "^9.0.3",
|
|
12
|
+
"ts-mocha": "^10.0.0",
|
|
13
|
+
"@types/mocha": "^9.0.0",
|
|
14
|
+
"typescript": "^4.3.5",
|
|
15
|
+
"prettier": "^2.6.2"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "my-test-project"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Created with USO"
|
|
5
|
+
edition = "2021"
|
|
6
|
+
|
|
7
|
+
[lib]
|
|
8
|
+
crate-type = ["cdylib", "lib"]
|
|
9
|
+
name = "my_test_project"
|
|
10
|
+
|
|
11
|
+
[features]
|
|
12
|
+
no-entrypoint = []
|
|
13
|
+
no-idl = []
|
|
14
|
+
no-log-ix-name = []
|
|
15
|
+
cpi = ["no-entrypoint"]
|
|
16
|
+
default = []
|
|
17
|
+
|
|
18
|
+
[dependencies]
|
|
19
|
+
anchor-lang = "0.30.1"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
use anchor_lang::prelude::*;
|
|
2
|
+
|
|
3
|
+
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
|
|
4
|
+
|
|
5
|
+
#[program]
|
|
6
|
+
pub mod my_test_project {
|
|
7
|
+
use super::*;
|
|
8
|
+
|
|
9
|
+
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
|
|
10
|
+
msg!("Greetings from USO! Your project is initialized.");
|
|
11
|
+
Ok(())
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[derive(Accounts)]
|
|
16
|
+
pub struct Initialize {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import { Program } from "@coral-xyz/anchor";
|
|
3
|
+
import { MyTestProject } from "../target/types/my_test_project";
|
|
4
|
+
|
|
5
|
+
describe("my-test-project", () => {
|
|
6
|
+
// Configure the client to use the local cluster.
|
|
7
|
+
anchor.setProvider(anchor.AnchorProvider.env());
|
|
8
|
+
|
|
9
|
+
const program = anchor.workspace.MyTestProject as Program<MyTestProject>;
|
|
10
|
+
|
|
11
|
+
it("Is initialized!", async () => {
|
|
12
|
+
// Add your test here.
|
|
13
|
+
const tx = await program.methods.initialize().rpc();
|
|
14
|
+
console.log("Your transaction signature", tx);
|
|
15
|
+
});
|
|
16
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const shell = require('shelljs');
|
|
4
|
+
const { log, spinner } = require('../utils/logger');
|
|
5
|
+
const { getCargoBinPath } = require('../utils/paths');
|
|
6
|
+
|
|
7
|
+
const create = async (projectName) => {
|
|
8
|
+
if (!projectName) {
|
|
9
|
+
log.error("ā Please provide a project name: uso create <project-name>");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Validate project name (basic check for valid folder name)
|
|
14
|
+
if (!/^[a-z0-9-_]+$/.test(projectName)) {
|
|
15
|
+
log.error("ā Project name can only contain lowercase letters, numbers, hyphens, and underscores.");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
20
|
+
if (fs.existsSync(targetDir)) {
|
|
21
|
+
log.error(`ā Directory '${projectName}' already exists.`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log.header(`šļø Scaffolding new project: ${projectName}`);
|
|
26
|
+
|
|
27
|
+
// 1. Copy Template
|
|
28
|
+
const templateDir = path.resolve(__dirname, '../../templates/default');
|
|
29
|
+
const spin = spinner('Copying template files...').start();
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
shell.cp('-R', templateDir, targetDir);
|
|
33
|
+
spin.succeed('Template copied.');
|
|
34
|
+
} catch (e) {
|
|
35
|
+
spin.fail('Failed to copy template.');
|
|
36
|
+
log.error(e.message);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2. Customize Project (Rename files and content)
|
|
41
|
+
log.info("āļø Customizing project details...");
|
|
42
|
+
|
|
43
|
+
// Rename programs/my-project to programs/<project-name>
|
|
44
|
+
// Note: Rust crate names typically use underscores, not hyphens.
|
|
45
|
+
const crateName = projectName.replace(/-/g, '_');
|
|
46
|
+
|
|
47
|
+
const oldProgramDir = path.join(targetDir, 'programs', 'my-project');
|
|
48
|
+
const newProgramDir = path.join(targetDir, 'programs', crateName);
|
|
49
|
+
|
|
50
|
+
// Rename tests/my-project.ts to tests/<project-name>.ts
|
|
51
|
+
const oldTestFile = path.join(targetDir, 'tests', 'my-project.ts');
|
|
52
|
+
const newTestFile = path.join(targetDir, 'tests', `${projectName}.ts`);
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
if (fs.existsSync(oldProgramDir)) {
|
|
56
|
+
fs.renameSync(oldProgramDir, newProgramDir);
|
|
57
|
+
}
|
|
58
|
+
if (fs.existsSync(oldTestFile)) {
|
|
59
|
+
fs.renameSync(oldTestFile, newTestFile);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Replace placeholders in files
|
|
63
|
+
const replaceInFile = (filePath, searchValue, replaceValue) => {
|
|
64
|
+
if (fs.existsSync(filePath)) {
|
|
65
|
+
let content = fs.readFileSync(filePath, 'utf8');
|
|
66
|
+
// Global replace
|
|
67
|
+
const regex = new RegExp(searchValue, 'g');
|
|
68
|
+
content = content.replace(regex, replaceValue);
|
|
69
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Update Anchor.toml
|
|
74
|
+
replaceInFile(path.join(targetDir, 'Anchor.toml'), 'my_project', crateName);
|
|
75
|
+
|
|
76
|
+
// Update Cargo.toml
|
|
77
|
+
replaceInFile(path.join(newProgramDir, 'Cargo.toml'), 'my-project', projectName);
|
|
78
|
+
replaceInFile(path.join(newProgramDir, 'Cargo.toml'), 'my_project', crateName);
|
|
79
|
+
|
|
80
|
+
// Update lib.rs (if specific project name usage exists beyond mod name which is file-based in lib.rs typically, but here we defined inside lib.rs)
|
|
81
|
+
// Actually, in lib.rs: pub mod my_project -> pub mod crate_name
|
|
82
|
+
replaceInFile(path.join(newProgramDir, 'src', 'lib.rs'), 'my_project', crateName);
|
|
83
|
+
|
|
84
|
+
// Update test file
|
|
85
|
+
replaceInFile(newTestFile, 'my-project', projectName); // describe("my-project")
|
|
86
|
+
replaceInFile(newTestFile, 'my_project', crateName); // import ... "../target/types/my_project"
|
|
87
|
+
|
|
88
|
+
// Update class name in test file (MyProject -> ProjectNamePascalCase)
|
|
89
|
+
const toPascalCase = (str) => {
|
|
90
|
+
return str.match(/[a-z0-9]+/gi)
|
|
91
|
+
.map(word => word.charAt(0).toUpperCase() + word.substr(1).toLowerCase())
|
|
92
|
+
.join('');
|
|
93
|
+
};
|
|
94
|
+
const pascalName = toPascalCase(projectName);
|
|
95
|
+
replaceInFile(newTestFile, 'MyProject', pascalName);
|
|
96
|
+
|
|
97
|
+
} catch (e) {
|
|
98
|
+
log.error(`ā Failed during customization: ${e.message}`);
|
|
99
|
+
// clean up? maybe not, let user see what happened
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 4. Generate Keypair if needed?
|
|
104
|
+
// Anchor usually handles this on first build, but let's check if they have a wallet.
|
|
105
|
+
// We won't force it here, "uso init" or "uso verify" handles wallet creation.
|
|
106
|
+
|
|
107
|
+
log.header("\nš Project Created Successfully!");
|
|
108
|
+
log.info(`\nš Next steps:\n`);
|
|
109
|
+
log.info(` cd ${projectName}`);
|
|
110
|
+
log.info(` npm install`);
|
|
111
|
+
log.info(` uso test`);
|
|
112
|
+
log.info(`\nHappy building! š`);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
module.exports = { create };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[toolchain]
|
|
2
|
+
|
|
3
|
+
[features]
|
|
4
|
+
seeds = false
|
|
5
|
+
skip-lint = false
|
|
6
|
+
|
|
7
|
+
[programs.localnet]
|
|
8
|
+
my_project = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
|
|
9
|
+
|
|
10
|
+
[registry]
|
|
11
|
+
url = "https://api.apr.dev"
|
|
12
|
+
|
|
13
|
+
[provider]
|
|
14
|
+
cluster = "Localnet"
|
|
15
|
+
wallet = "~/.config/solana/id.json"
|
|
16
|
+
|
|
17
|
+
[scripts]
|
|
18
|
+
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Welcome to Your USO Project š
|
|
2
|
+
|
|
3
|
+
Congratulations! You've just scaffolded a professional Solana workspace using the **Universal Solana Orchestrator (USO)**.
|
|
4
|
+
|
|
5
|
+
This isn't just a folder with files. It's a battle-tested setup ready for serious development.
|
|
6
|
+
|
|
7
|
+
## š Structure
|
|
8
|
+
- `programs/`: Your Rust smart contracts live here.
|
|
9
|
+
- `tests/`: Robust TypeScript tests using Anchor.
|
|
10
|
+
- `Anchor.toml`: Your project configuration.
|
|
11
|
+
|
|
12
|
+
## ā” Quick Start
|
|
13
|
+
|
|
14
|
+
### 1. Build
|
|
15
|
+
Compile your smart contract:
|
|
16
|
+
```bash
|
|
17
|
+
uso build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 2. Test
|
|
21
|
+
Run your test suite against a local validator:
|
|
22
|
+
```bash
|
|
23
|
+
uso test
|
|
24
|
+
```
|
|
25
|
+
*Note: This automatically spins up a local validator, deploys your program, runs tests, and shuts down.*
|
|
26
|
+
|
|
27
|
+
### 3. Deploy (Devnet)
|
|
28
|
+
When you're ready to go public:
|
|
29
|
+
1. Switch to devnet: `solana config set --url devnet`
|
|
30
|
+
2. Airdrop SOL: `solana airdrop 2`
|
|
31
|
+
3. Deploy: `uso deploy`
|
|
32
|
+
|
|
33
|
+
## š§ Need Help?
|
|
34
|
+
Run `uso doctor` if your environment feels weird. Usage instructions are also available via `uso help`.
|
|
35
|
+
|
|
36
|
+
Happy coding!
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
|
|
4
|
+
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
|
|
5
|
+
},
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@coral-xyz/anchor": "^0.32.1"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"chai": "^4.3.7",
|
|
11
|
+
"mocha": "^9.0.3",
|
|
12
|
+
"ts-mocha": "^10.0.0",
|
|
13
|
+
"@types/mocha": "^9.0.0",
|
|
14
|
+
"@types/chai": "^4.3.0",
|
|
15
|
+
"@types/node": "^16.0.0",
|
|
16
|
+
"typescript": "^4.3.5",
|
|
17
|
+
"prettier": "^2.6.2"
|
|
18
|
+
}
|
|
19
|
+
}
|