cli: add prettier to new project js/ts template (#1741)
This commit is contained in:
parent
c66a06e5ba
commit
ce884066e0
|
@ -317,7 +317,7 @@ jobs:
|
||||||
name: anchor-binary
|
name: anchor-binary
|
||||||
path: ~/.cargo/bin/
|
path: ~/.cargo/bin/
|
||||||
|
|
||||||
- run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && anchor test
|
- run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && anchor test && yarn lint:fix
|
||||||
- uses: ./.github/actions/git-diff/
|
- uses: ./.github/actions/git-diff/
|
||||||
|
|
||||||
test-programs:
|
test-programs:
|
||||||
|
|
|
@ -17,6 +17,7 @@ The minor version will be incremented upon a breaking change and the patch versi
|
||||||
* ts: Add view functions ([#1695](https://github.com/project-serum/anchor/pull/1695)).
|
* ts: Add view functions ([#1695](https://github.com/project-serum/anchor/pull/1695)).
|
||||||
* avm: New `avm update` command to update the Anchor CLI to the latest version ([#1670](https://github.com/project-serum/anchor/pull/1670)).
|
* avm: New `avm update` command to update the Anchor CLI to the latest version ([#1670](https://github.com/project-serum/anchor/pull/1670)).
|
||||||
* cli: Update js/ts templates to use new `program.methods` syntax ([#1732](https://github.com/project-serum/anchor/pull/1732)).
|
* cli: Update js/ts templates to use new `program.methods` syntax ([#1732](https://github.com/project-serum/anchor/pull/1732)).
|
||||||
|
* cli: Workspaces created with `anchor init` now come with the `prettier` formatter and scripts included ([#1741](https://github.com/project-serum/anchor/pull/1741)).
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
|
|
|
@ -521,16 +521,16 @@ fn init(cfg_override: &ConfigOverride, name: String, javascript: bool, no_git: b
|
||||||
);
|
);
|
||||||
cfg.programs.insert(Cluster::Localnet, localnet);
|
cfg.programs.insert(Cluster::Localnet, localnet);
|
||||||
let toml = cfg.to_string();
|
let toml = cfg.to_string();
|
||||||
let mut file = File::create("Anchor.toml")?;
|
fs::write("Anchor.toml", toml)?;
|
||||||
file.write_all(toml.as_bytes())?;
|
|
||||||
|
|
||||||
// Build virtual manifest.
|
// Build virtual manifest.
|
||||||
let mut virt_manifest = File::create("Cargo.toml")?;
|
fs::write("Cargo.toml", template::virtual_manifest())?;
|
||||||
virt_manifest.write_all(template::virtual_manifest().as_bytes())?;
|
|
||||||
|
|
||||||
// Initialize .gitignore file
|
// Initialize .gitignore file
|
||||||
let mut virt_manifest = File::create(".gitignore")?;
|
fs::write(".gitignore", template::git_ignore())?;
|
||||||
virt_manifest.write_all(template::git_ignore().as_bytes())?;
|
|
||||||
|
// Initialize .prettierignore file
|
||||||
|
fs::write(".prettierignore", template::prettier_ignore())?;
|
||||||
|
|
||||||
// Build the program.
|
// Build the program.
|
||||||
fs::create_dir("programs")?;
|
fs::create_dir("programs")?;
|
||||||
|
|
|
@ -214,12 +214,17 @@ describe("{}", () => {{
|
||||||
pub fn package_json() -> String {
|
pub fn package_json() -> String {
|
||||||
format!(
|
format!(
|
||||||
r#"{{
|
r#"{{
|
||||||
|
"scripts": {{
|
||||||
|
"lint:fix": "prettier */*.js \"*/**/*{{.js,.ts}}\" -w",
|
||||||
|
"lint": "prettier */*.js \"*/**/*{{.js,.ts}}\" --check"
|
||||||
|
}},
|
||||||
"dependencies": {{
|
"dependencies": {{
|
||||||
"@project-serum/anchor": "^{0}"
|
"@project-serum/anchor": "^{0}"
|
||||||
}},
|
}},
|
||||||
"devDependencies": {{
|
"devDependencies": {{
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"mocha": "^9.0.3"
|
"mocha": "^9.0.3",
|
||||||
|
"prettier": "^2.6.2"
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
"#,
|
"#,
|
||||||
|
@ -230,6 +235,10 @@ pub fn package_json() -> String {
|
||||||
pub fn ts_package_json() -> String {
|
pub fn ts_package_json() -> String {
|
||||||
format!(
|
format!(
|
||||||
r#"{{
|
r#"{{
|
||||||
|
"scripts": {{
|
||||||
|
"lint:fix": "prettier */*.js \"*/**/*{{.js,.ts}}\" -w",
|
||||||
|
"lint": "prettier */*.js \"*/**/*{{.js,.ts}}\" --check"
|
||||||
|
}},
|
||||||
"dependencies": {{
|
"dependencies": {{
|
||||||
"@project-serum/anchor": "^{0}"
|
"@project-serum/anchor": "^{0}"
|
||||||
}},
|
}},
|
||||||
|
@ -240,7 +249,8 @@ pub fn ts_package_json() -> String {
|
||||||
"@types/bn.js": "^5.1.0",
|
"@types/bn.js": "^5.1.0",
|
||||||
"@types/chai": "^4.3.0",
|
"@types/chai": "^4.3.0",
|
||||||
"@types/mocha": "^9.0.0",
|
"@types/mocha": "^9.0.0",
|
||||||
"typescript": "^4.3.5"
|
"typescript": "^4.3.5",
|
||||||
|
"prettier": "^2.6.2"
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
"#,
|
"#,
|
||||||
|
@ -300,6 +310,18 @@ test-ledger
|
||||||
"#
|
"#
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn prettier_ignore() -> &'static str {
|
||||||
|
r#"
|
||||||
|
.anchor
|
||||||
|
.DS_Store
|
||||||
|
target
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
test-ledger
|
||||||
|
"#
|
||||||
|
}
|
||||||
|
|
||||||
pub fn node_shell(
|
pub fn node_shell(
|
||||||
cluster_url: &str,
|
cluster_url: &str,
|
||||||
wallet_path: &str,
|
wallet_path: &str,
|
||||||
|
|
Loading…
Reference in New Issue