mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
tools: remove the src
subdir from projects, created by v new
(#24236)
This commit is contained in:
parent
e972860fc9
commit
c3d6858bf3
4 changed files with 27 additions and 27 deletions
|
@ -5,7 +5,7 @@ import os
|
||||||
fn (mut c Create) set_bin_project_files() {
|
fn (mut c Create) set_bin_project_files() {
|
||||||
base := if c.new_dir { c.name } else { '' }
|
base := if c.new_dir { c.name } else { '' }
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: os.join_path(base, 'src', 'main.v')
|
path: os.join_path(base, 'main.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os
|
||||||
fn (mut c Create) set_lib_project_files() {
|
fn (mut c Create) set_lib_project_files() {
|
||||||
base := if c.new_dir { c.name } else { '' }
|
base := if c.new_dir { c.name } else { '' }
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: os.join_path(base, 'src', c.name + '.v')
|
path: os.join_path(base, c.name + '.v')
|
||||||
content: 'module ${c.name}
|
content: 'module ${c.name}
|
||||||
|
|
||||||
// square calculates the second power of `x`
|
// square calculates the second power of `x`
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os { join_path }
|
||||||
fn (mut c Create) set_web_project_files() {
|
fn (mut c Create) set_web_project_files() {
|
||||||
base := if c.new_dir { c.name } else { '' }
|
base := if c.new_dir { c.name } else { '' }
|
||||||
c.files << ProjectFiles{
|
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
|
content: "module databases
|
||||||
|
|
||||||
import db.sqlite // can change to 'db.mysql', 'db.pg'
|
import db.sqlite // can change to 'db.mysql', 'db.pg'
|
||||||
|
@ -17,14 +17,14 @@ pub fn create_db_connection() !sqlite.DB {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'templates', 'header_component.html')
|
path: join_path(base, 'templates', 'header_component.html')
|
||||||
content: "<nav>
|
content: "<nav>
|
||||||
<div class='nav-wrapper'>
|
<div class='nav-wrapper'>
|
||||||
<a href='javascript:window.history.back();' class='left'>
|
<a href='javascript:window.history.back();' class='left'>
|
||||||
<i class='material-icons'>arrow_back_ios_new</i>
|
<i class='material-icons'>arrow_back_ios_new</i>
|
||||||
</a>
|
</a>
|
||||||
<a href='/'>
|
<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>
|
</a>
|
||||||
<ul id='nav-mobile' class='right'>
|
<ul id='nav-mobile' class='right'>
|
||||||
<li><a href='https://github.com/vlang/v'>github</a></li>
|
<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{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'templates', 'products.css')
|
path: join_path(base, 'templates', 'products.css')
|
||||||
content: 'h1.title {
|
content: 'h1.title {
|
||||||
font-family: Arial, Helvetica, sans-serif;
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
color: #3b7bbf;
|
color: #3b7bbf;
|
||||||
|
@ -50,7 +50,7 @@ div.products-table {
|
||||||
}'
|
}'
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'templates', 'products.html')
|
path: join_path(base, 'templates', 'products.html')
|
||||||
content: "<!DOCTYPE html>
|
content: "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -67,7 +67,7 @@ div.products-table {
|
||||||
<link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'>
|
<link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'>
|
||||||
|
|
||||||
<title>Login</title>
|
<title>Login</title>
|
||||||
@css 'src/templates/products.css'
|
@css 'templates/products.css'
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>@include 'header_component.html'</div>
|
<div>@include 'header_component.html'</div>
|
||||||
|
@ -147,7 +147,7 @@ div.products-table {
|
||||||
</html>"
|
</html>"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'auth_controllers.v')
|
path: join_path(base, 'auth_controllers.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -164,7 +164,7 @@ pub fn (mut app App) controller_auth(username string, password string) vweb.Resu
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'auth_dto.v')
|
path: join_path(base, 'auth_dto.v')
|
||||||
content: 'module main
|
content: 'module main
|
||||||
|
|
||||||
struct AuthRequestDto {
|
struct AuthRequestDto {
|
||||||
|
@ -174,7 +174,7 @@ struct AuthRequestDto {
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'auth_services.v')
|
path: join_path(base, 'auth_services.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import crypto.hmac
|
import crypto.hmac
|
||||||
|
@ -269,7 +269,7 @@ fn auth_verify(token string) bool {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'index.html')
|
path: join_path(base, 'index.html')
|
||||||
content: "<!DOCTYPE html>
|
content: "<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -348,7 +348,7 @@ fn auth_verify(token string) bool {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'main.v')
|
path: join_path(base, 'main.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -376,7 +376,7 @@ fn main() {
|
||||||
db.close() or { panic(err) }
|
db.close() or { panic(err) }
|
||||||
|
|
||||||
mut app := &App{}
|
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.
|
// makes all static files available.
|
||||||
app.mount_static_folder_at(os.resource_abs_path('.'), '/')
|
app.mount_static_folder_at(os.resource_abs_path('.'), '/')
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ pub fn (mut app App) index() vweb.Result {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_controller.v')
|
path: join_path(base, 'product_controller.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -457,7 +457,7 @@ pub fn (mut app App) controller_create_product(product_name string) vweb.Result
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_entities.v')
|
path: join_path(base, 'product_entities.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
@[table: 'products']
|
@[table: 'products']
|
||||||
|
@ -470,7 +470,7 @@ struct Product {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_service.v')
|
path: join_path(base, 'product_service.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import databases
|
import databases
|
||||||
|
@ -517,7 +517,7 @@ fn (mut app App) service_get_all_products_from(user_id int) ![]Product {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_view_api.v')
|
path: join_path(base, 'product_view_api.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -556,7 +556,7 @@ pub fn get_product(token string) ![]User {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'product_view.v')
|
path: join_path(base, 'product_view.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -578,7 +578,7 @@ pub fn (mut app App) products() !vweb.Result {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_controllers.v')
|
path: join_path(base, 'user_controllers.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
@ -648,7 +648,7 @@ pub fn (mut app App) controller_create_user(username string, password string) vw
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_entities.v')
|
path: join_path(base, 'user_entities.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
@[table: 'users']
|
@[table: 'users']
|
||||||
|
@ -663,7 +663,7 @@ mut:
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_services.v')
|
path: join_path(base, 'user_services.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import crypto.bcrypt
|
import crypto.bcrypt
|
||||||
|
@ -732,7 +732,7 @@ fn (mut app App) service_get_user(id int) !User {
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
c.files << ProjectFiles{
|
c.files << ProjectFiles{
|
||||||
path: join_path(base, 'src', 'user_view_api.v')
|
path: join_path(base, 'user_view_api.v')
|
||||||
content: "module main
|
content: "module main
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
|
@ -24,8 +24,8 @@ fn init_and_check() ! {
|
||||||
os.chdir(test_path)!
|
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.
|
// 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_exists := os.exists('main.v')
|
||||||
main_last_modified := if main_exists { os.file_last_mod_unix('src/main.v') } else { 0 }
|
main_last_modified := if main_exists { os.file_last_mod_unix('main.v') } else { 0 }
|
||||||
|
|
||||||
// Initialize project.
|
// Initialize project.
|
||||||
os.execute_or_exit('${expect_exe} ${os.join_path(expect_tests_path, 'init.expect')} ${vroot}')
|
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!'
|
assert x.output.trim_space() == 'Hello World!'
|
||||||
|
|
||||||
if main_exists {
|
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 {
|
} else {
|
||||||
assert os.read_file('src/main.v')! == [
|
assert os.read_file('main.v')! == [
|
||||||
'module main\n',
|
'module main\n',
|
||||||
'fn main() {',
|
'fn main() {',
|
||||||
" println('Hello World!')",
|
" println('Hello World!')",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue