Skip to content

Creating or Importing Projects

Creating a Project from Scratch

Serein provides the init or i command to help you initialize a project managed by Serein from scratch.

If you wish to create a ScriptAPI resource pack from the beginning, this method of creating a project is recommended because projects created by Serein are quite standard and easy to maintain!

Here's how to use it:

bash
serein init

After executing the command, Serein will ask you interactively about the project information (such as name, version, dependencies, etc.), and then it will generate a set of project templates and build tools for you.

Using Default Settings

You can also use the default settings to quickly generate a project. Projects generated this way will include the project structure and also come with the latest version of the @minecraft/server dependency:

bash
serein init -y

Project Structure

The newly created project will contain the following files:

├── node_modules
├── behavior_packs
│   ├── manifest.json
│   └── pack_icon.png (randomly generated based on the hash of the resource pack name)
├── resource_packs (optional)
│   ├── manifest.json
│   └── pack_icon.png (randomly generated based on the hash of the resource pack name)
├── scripts
│   └── main.js/ts (or the entry file specified by the user)
├── package.json
├── gulpfile.js (related to the automatic build process)
├── tsconfig.json (only if TypeScript is selected)
├── .serein.json (Serein's information file)
└── .mcattributes (to disable warnings from the official vscode plugin)

Importing from an Existing Project

WARNING

This feature is currently under-tested. ScriptAPI developers are welcome to test with their own projects and provide feedback!

Serein offers the adapt and a commands to adapt to an existing project.

Prerequisites

Here are a few reminders for importing projects into Serein:

  • ❯ The project's behavior pack folder (as referred to in the official documentation as behavior_packs) should not act as the top level of the resource pack. This layout is considered for adaptation by packaging tools!

    For example, this file layout is not valid (at the top level of the resource pack):

    ├── manifest.json
    ├── package.json
    └── scripts

    If you don't want your final packaged product to include a whole set of node_modules and package.json, it's best to abandon such chaotic layouts.

    A more ideal resource pack layout would look like this:

    ├── behavior_packs
    │   ├── manifest.json
    │   └── scripts
    └── package.json
  • ❯ Do not have a self-written gulpfile

    If you have read Microsoft's official starter article, you might have learned to use the gulp tool and added some content to it according to your needs (if you used gulp but haven't modified gulpfile.js, it's fine, our gulpfile.js is much more robust XD). In this case, be aware that the new gulpfile.js generated by Serein may overwrite your previously written file.

    Fortunately, if there's an existing gulpfile.js, Serein will ask whether to overwrite it and can help you backup, allowing you to add your previous functionalities into the new gulpfile.js (our gulpfile.js is more editable than the official one).

Importing Process

Execute the following command:

bash
serein adapt

Just follow the interactive process to provide your package information. If paths need to be filled in, make sure to provide relative paths based on the current path.

After the process is completed, Serein will generate a .serein.json file in the directory, indicating that the project can now be used with Serein!

Behavior Explanation

Serein might also perform the following actions when adapting a project, please be aware of these actions as they might affect you:

  • ❯ Change the type property in package.json to module.
  • ❯ Move existing @minecraft prefixed dependencies and auto-packaging related dependencies from dependencies to devDependencies in package.json.
  • ❯ Remove comments from the manifest.json file in your behavior pack directory.