tech

[English] [Japanese]

29. Recommended directory structure for projects using LuneScript

LuneScript supports transcompiling to lua and go.

On the other hand, lua and go have different directory management methods.

This section describes the recommended directory structure that can be used without problems in directory management for either language.

premise

Here, we will explain on the assumption that you will develop with the following github repositories.

github.com/HOGE/PROJ
  • HOGE is any github account name.
  • PROJ is any repository name.

Also, the explanation assumes that the following modules are defined.

foo.bar.lib

Basic configuration

Shows the basic structure of the directory.

PROJ/
 +-- go.mod
 +-- lune.js
 +-- foo/
   +-- bar/
      +-- lib.lns

Place go.mod, lune.js, foo/ directly under the PROJ directory.

lune.js

Create lune.js with the following contents.

{}

go.mod

Here is the configuration of go.mod at this time. Note that go.mod is unnecessary if you don't want to transcompile to go.

module github.com/HOGE/PROJ

go 1.16

main and submodule

There are cases where the repository manages the main program and cases where it manages the submodules used by the main program.

When managed as a submodule, the restrictions on the above basic structure are relaxed slightly.

Specifically, the following will be relaxed:

  • Go.mod, lune.js, foo do not have to be directly under PROJ.
  • No need to register go.sum on github.

For example, it can be placed under src as follows.

PROJ/
 +-- src/  <--- ※任意のディレクトリ以下に配置可能
   +-- go.mod
   +-- lune.js
   +-- foo/
     +-- bar/
        +-- lib.lns

In this case go.mod has different module path as below.

module github.com/HOGE/PROJ/src

go 1.16

environment variable GOPATH

When transcompiling to go, the above PROJ directory should be placed in:

${GOPATH}/src/github.com/HOGE/PROJ

If GOPATH is not set, ${HOME}/go will be used.