tools: remove the src subdir from projects, created by v new (#24236)

This commit is contained in:
JalonSolov 2025-04-15 23:37:51 -04:00 committed by GitHub
parent e972860fc9
commit c3d6858bf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 27 deletions

View file

@ -5,7 +5,7 @@ import os
fn (mut c Create) set_bin_project_files() {
base := if c.new_dir { c.name } else { '' }
c.files << ProjectFiles{
path: os.join_path(base, 'src', 'main.v')
path: os.join_path(base, 'main.v')
content: "module main
fn main() {

View file

@ -5,7 +5,7 @@ import os
fn (mut c Create) set_lib_project_files() {
base := if c.new_dir { c.name } else { '' }
c.files << ProjectFiles{
path: os.join_path(base, 'src', c.name + '.v')
path: os.join_path(base, c.name + '.v')
content: 'module ${c.name}
// square calculates the second power of `x`

View file

@ -5,7 +5,7 @@ import os { join_path }
fn (mut c Create) set_web_project_files() {
base := if c.new_dir { c.name } else { '' }
c.files << ProjectFiles{
path: join_path(base, 'src', 'databases', 'config_databases_sqlite.v')
path: join_path(base, 'databases', 'config_databases_sqlite.v')
content: "module databases
import db.sqlite // can change to 'db.mysql', 'db.pg'
@ -17,14 +17,14 @@ pub fn create_db_connection() !sqlite.DB {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'templates', 'header_component.html')
path: join_path(base, 'templates', 'header_component.html')
content: "<nav>
<div class='nav-wrapper'>
<a href='javascript:window.history.back();' class='left'>
<i class='material-icons'>arrow_back_ios_new</i>
</a>
<a href='/'>
<img src='src/assets/veasel.png' alt='logo' style='max-height: 100%' />
<img src='assets/veasel.png' alt='logo' style='max-height: 100%' />
</a>
<ul id='nav-mobile' class='right'>
<li><a href='https://github.com/vlang/v'>github</a></li>
@ -36,7 +36,7 @@ pub fn create_db_connection() !sqlite.DB {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'templates', 'products.css')
path: join_path(base, 'templates', 'products.css')
content: 'h1.title {
font-family: Arial, Helvetica, sans-serif;
color: #3b7bbf;
@ -50,7 +50,7 @@ div.products-table {
}'
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'templates', 'products.html')
path: join_path(base, 'templates', 'products.html')
content: "<!DOCTYPE html>
<html>
<head>
@ -67,7 +67,7 @@ div.products-table {
<link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'>
<title>Login</title>
@css 'src/templates/products.css'
@css 'templates/products.css'
</head>
<body>
<div>@include 'header_component.html'</div>
@ -147,7 +147,7 @@ div.products-table {
</html>"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'auth_controllers.v')
path: join_path(base, 'auth_controllers.v')
content: "module main
import vweb
@ -164,7 +164,7 @@ pub fn (mut app App) controller_auth(username string, password string) vweb.Resu
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'auth_dto.v')
path: join_path(base, 'auth_dto.v')
content: 'module main
struct AuthRequestDto {
@ -174,7 +174,7 @@ struct AuthRequestDto {
'
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'auth_services.v')
path: join_path(base, 'auth_services.v')
content: "module main
import crypto.hmac
@ -269,7 +269,7 @@ fn auth_verify(token string) bool {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'index.html')
path: join_path(base, 'index.html')
content: "<!DOCTYPE html>
<html>
<head>
@ -348,7 +348,7 @@ fn auth_verify(token string) bool {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'main.v')
path: join_path(base, 'main.v')
content: "module main
import vweb
@ -376,7 +376,7 @@ fn main() {
db.close() or { panic(err) }
mut app := &App{}
app.serve_static('/favicon.ico', 'src/assets/favicon.ico')
app.serve_static('/favicon.ico', 'assets/favicon.ico')
// makes all static files available.
app.mount_static_folder_at(os.resource_abs_path('.'), '/')
@ -391,7 +391,7 @@ pub fn (mut app App) index() vweb.Result {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'product_controller.v')
path: join_path(base, 'product_controller.v')
content: "module main
import vweb
@ -457,7 +457,7 @@ pub fn (mut app App) controller_create_product(product_name string) vweb.Result
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'product_entities.v')
path: join_path(base, 'product_entities.v')
content: "module main
@[table: 'products']
@ -470,7 +470,7 @@ struct Product {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'product_service.v')
path: join_path(base, 'product_service.v')
content: "module main
import databases
@ -517,7 +517,7 @@ fn (mut app App) service_get_all_products_from(user_id int) ![]Product {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'product_view_api.v')
path: join_path(base, 'product_view_api.v')
content: "module main
import json
@ -556,7 +556,7 @@ pub fn get_product(token string) ![]User {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'product_view.v')
path: join_path(base, 'product_view.v')
content: "module main
import vweb
@ -578,7 +578,7 @@ pub fn (mut app App) products() !vweb.Result {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'user_controllers.v')
path: join_path(base, 'user_controllers.v')
content: "module main
import vweb
@ -648,7 +648,7 @@ pub fn (mut app App) controller_create_user(username string, password string) vw
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'user_entities.v')
path: join_path(base, 'user_entities.v')
content: "module main
@[table: 'users']
@ -663,7 +663,7 @@ mut:
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'user_services.v')
path: join_path(base, 'user_services.v')
content: "module main
import crypto.bcrypt
@ -732,7 +732,7 @@ fn (mut app App) service_get_user(id int) !User {
"
}
c.files << ProjectFiles{
path: join_path(base, 'src', 'user_view_api.v')
path: join_path(base, 'user_view_api.v')
content: "module main
import json

View file

@ -24,8 +24,8 @@ fn init_and_check() ! {
os.chdir(test_path)!
// Keep track of the last modified time of the main file to ensure it is not modified if it already exists.
main_exists := os.exists('src/main.v')
main_last_modified := if main_exists { os.file_last_mod_unix('src/main.v') } else { 0 }
main_exists := os.exists('main.v')
main_last_modified := if main_exists { os.file_last_mod_unix('main.v') } else { 0 }
// Initialize project.
os.execute_or_exit('${expect_exe} ${os.join_path(expect_tests_path, 'init.expect')} ${vroot}')
@ -34,9 +34,9 @@ fn init_and_check() ! {
assert x.output.trim_space() == 'Hello World!'
if main_exists {
assert main_last_modified == os.file_last_mod_unix('src/main.v')
assert main_last_modified == os.file_last_mod_unix('main.v')
} else {
assert os.read_file('src/main.v')! == [
assert os.read_file('main.v')! == [
'module main\n',
'fn main() {',
" println('Hello World!')",