1 | # Quick Start: Texel CLI
|
2 |
|
3 | This is a quick-start guide for using Texel through its command-line interface. There are three core tasks that Texel provides:
|
4 |
|
5 | - `texel create` – Used to create a new project or code sketch
|
6 | - `texel start` – Runs a development server so you can live code
|
7 | - `texel bundle` – Bundles your JavaScript & CSS so you can publish your website
|
8 |
|
9 | ### Preface: Install Node.js and npm
|
10 |
|
11 | First, you must install the latest version of Node.js and npm. If you need help, see [How to Install Node.js and npm](#) for details.
|
12 |
|
13 | ## `create` – Project Setup
|
14 |
|
15 | After you install Node/npm, open your Terminal (command-line) application. Navigate to a new folder that will hold your project, like so:
|
16 |
|
17 | ```sh
|
18 | # Create a new folder for your app
|
19 | mkdir my-cool-app
|
20 |
|
21 | # Move into that new folder
|
22 | cd my-cool-app
|
23 | ```
|
24 |
|
25 | Now, we will run the [npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) command, which comes with npm, to quick start a new project.
|
26 |
|
27 | ```sh
|
28 | npx texel create
|
29 | ```
|
30 |
|
31 | This will automatically install and run the latest version of `texel`, creating a new project based on your current working directory (`my-cool-app`).
|
32 |
|
33 | Texel will also install any dependencies associated with the project, and stub out all the files needed for your application.
|
34 |
|
35 | > :bulb: See Also: [Installing Texel Globally](#installing-texel-globally)
|
36 |
|
37 | ### Folder Structure
|
38 |
|
39 | After everything installs, you'll notice some new files/folders were created. Mostly, you can just focus on the following three, which defines the source code for our application:
|
40 |
|
41 | - `src/index.js` (code in JavaScript)
|
42 | - `src/style.css` (style sheet in CSS)
|
43 | - `app/index.html` (website markup in HTML)
|
44 |
|
45 | > :bulb: See Also: [Folder Structure Details](#folder-structure-details)
|
46 |
|
47 | ## `start` – Development
|
48 |
|
49 | To start coding, you can run the following command:
|
50 |
|
51 | ```sh
|
52 | npm run start
|
53 | ```
|
54 |
|
55 | This will open the browser to [localhost:9966](#) and start a development server. Now, when you edit and save the `index.js`, `style.css` and `index.html` files, the page will reload the changes automatically.
|
56 |
|
57 | You will notice that the `src/index.js` already contains some initial code. Thanks to Texel, you can `import` a style sheet from JavaScript, and it will be included in the production CSS file. The initial code looks like this:
|
58 |
|
59 | ```js
|
60 | // Helps to normalize CSS consistently across browsers
|
61 | import 'normalize.css';
|
62 |
|
63 | // You can import local CSS files like so
|
64 | import './style.css';
|
65 |
|
66 | // Here you can define any logic for your application
|
67 | // ...
|
68 | ```
|
69 |
|
70 | ## `bundle` – Building your Website
|
71 |
|
72 | When you are ready to release your site, simply run the following command to generate a static web page:
|
73 |
|
74 | ```sh
|
75 | npm run bundle
|
76 | ```
|
77 |
|
78 | This will write `bundle.js` (all your JavaScript) and `main.css` (all your CSS) into the `app/` folder. It will be optimized, transpiled and compressed for faster loading and cross-browser support.
|
79 |
|
80 | Now you can ZIP the `app/` folder and upload it to your favourite hosting service, such as [Neocities](https://neocities.org/). For other ways of publishing a web page, see the [Publishing your first website](#) guide.
|
81 |
|
82 | # More Details
|
83 |
|
84 | ### How to Install Node.js and npm
|
85 |
|
86 | TODO.
|
87 |
|
88 | ### Folder Structure Details
|
89 |
|
90 | The default `texel create` command generates the following folder structure:
|
91 |
|
92 | ```sh
|
93 | my-cool-app/ # Project folder
|
94 | app/ # Static site folder
|
95 | index.html # Your HTML
|
96 | src/ # Source code
|
97 | index.js # JavaScript code
|
98 | style.css # Main style sheet
|
99 | node_modules/ # 3rd party dependencies
|
100 | package.json # npm config
|
101 | package-lock.json # npm config
|
102 | .gitignore # git config
|
103 | ```
|
104 |
|
105 | This is just one flavour of a _project template_ that Texel supports. Texel can also generate projects that are better suited for GitHub Pages or specific libraries like React.
|
106 |
|
107 | > :bulb: Generally, it's best practice to use lower case and dash-spacing for project names.
|
108 |
|
109 | ### Installing Texel Globally
|
110 |
|
111 | If you use Texel a lot, you might want to install it globally rather than relying on `npx`. This way, you can create new projects without re-installing texel.
|
112 |
|
113 | To do this, use `npm install` with a `--global` flag:
|
114 |
|
115 | ```sh
|
116 | npm install texel --global
|
117 | ```
|
118 |
|
119 | Now you should be able to run `texel` globally.
|
120 |
|
121 | ```sh
|
122 | # Start another project
|
123 | texel create
|
124 | ```
|
125 |
|
126 | Make sure to re-install it occasionally to keep up to date with the latest version.
|
127 |
|
128 | ### Using Texel without `create`
|
129 |
|
130 | In some cases you might already have a project set up, or you may want to use your own folder structure and dependencies instead of relying on a template from Texel.
|
131 |
|
132 | You can do this by installing `texel` locally in your project folder.
|
133 |
|
134 | ```sh
|
135 | # if you don't have package.json, generate one
|
136 | npm init
|
137 |
|
138 | # now you can install texel locally
|
139 | # and save it as a development dependency
|
140 | npm install texel --save-dev
|
141 | ```
|
142 |
|
143 | Next, you will need to add `npm run` scripts. Edit your `package.json` and ensure it has a "scripts" field like so:
|
144 |
|
145 | ```js
|
146 | {
|
147 | "scripts": {
|
148 | "start": "texel start --dir app/ --clean",
|
149 | "bundle": "texel bundle --dir app/"
|
150 | }
|
151 | }
|
152 | ```
|
153 |
|
154 | By default, `texel` will look for your JavaScript source file in the `package.json` "main" field, so ensure it points to your application entry point:
|
155 |
|
156 | ```js
|
157 | {
|
158 | "main": "./src/index.js"
|
159 | }
|
160 | ```
|
161 |
|
162 | If you'd like, you can also adjust the settings and flags for the texel commands, such as running it in the current folder, using a different entry point, and ignoring CSS. For example:
|
163 |
|
164 | ```js
|
165 | {
|
166 | "scripts": {
|
167 | "start": "texel start index.js --no-css",
|
168 | "bundle": "texel bundle index.js --no-css"
|
169 | }
|
170 | }
|
171 | ```
|
172 |
|
173 | For more command-line variations, see the full [Command-Line Docs](#). |
\ | No newline at end of file |