Skip to content

Commit 9564428

Browse files
Merge pull request #8 from jawa-the-hutt/dev
Readme's updated and Prompt changes
2 parents 26ba92e + d9590ed commit 9564428

File tree

6 files changed

+175
-41
lines changed

6 files changed

+175
-41
lines changed

Diff for: README.md

+95-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,95 @@
1-
# nativescript-vue-cli-plugin
1+
# nativescript-vue-cli-plugin
2+
3+
Nativescript-Vue Plugin for [[email protected]](https://github.com/vuejs/vue-cli)
4+
5+
This plugin will integrate [Nativescript-Vue](https://nativescript-vue.org/) into new and existing Vue projects. Additionally, it will allow for the choice of developing for Native only environments or Native __and__ Web environments under a single project structure. In addition, choosing to integrate [Nativescript-Vue-Web](https://github.com/Nativescript-Vue-Web/Nativescript-Vue-Web), will allow for the development of Web components with a NativeScript-Vue like syntax that has the benefit of allowing for the sharing of components between the Native and Web sides of the project. This helps reduce the amount of code, maintenence needs, and the amount of time needed for development activities.
6+
7+
## Install
8+
9+
If vue-cli 3 is not yet installed, first follow the instructions here: https://github.com/vuejs/vue-cli
10+
11+
**Tip**: If you don't want to overwrite your current vue-cli 2 setup because you still need `vue init`, [then try this](https://cli.vuejs.org/guide/creating-a-project.html#pulling-2-x-templates-legacy).
12+
13+
Generate a project using vue-cli 3.0
14+
```
15+
vue create my-app
16+
```
17+
18+
Before installing the Nativescript-Vue CLI 3 Plugin, make sure to commit or stash changes in case you need to revert.
19+
20+
To install the Nativescript-Vue CLI 3 Plugin...
21+
```
22+
cd my-app
23+
npm install --save-dev vue-cli-plugin-nativescript-vue
24+
vue invoke vue-cli-plugin-nativescript-vue
25+
```
26+
27+
## Invocation Prompts
28+
1. Enter a unique application identifier
29+
* Accpeting the default is fine for testing
30+
2. Use HTML5 history mode? (Default: hash mode)
31+
* Required parameter for the cli core generator when vue-router is used
32+
3. Is this a brand new project? (Default: No)
33+
* By choosing `No`, which is the default, the plugin will try and be as non-destructive as possible to an existing project. It will do this by adding a folder into root named `ns-example` and add files into there to provide examples of how a project would change.
34+
* These changes will factor in answers to the other questions and adjust accordingly. Regardless of the answer, the plugin will install packages and adjust `package.json` as necessary to prep the project.
35+
4. Dual Native AND Web development experience or a Native only? (Default: Dual)
36+
* By default, the plugin will assume you want to develop for the Web and Native environments within the same project. As such, there will be two sides to the project where web environments will be actively developed within `/src` and Native environments will be developed within `/app`.
37+
* Warning: Choosing to develop for Native only will move the main entry point of the project and development folder to `/app`, copy necessary files and then delete `/src`.
38+
* By choosing `Dual`, you will be able to bring your own component framework into the web portion of the project. `NativeScript-Vue` [cannot use vue-router](https://nativescript-vue.org/en/docs/routing/vue-router/) currently, so you will have to provide your own manual routing. The templated options deployed with the plugin will show how to do basic manual routing.
39+
5. Use [Nativescript-Vue-Web](https://github.com/Nativescript-Vue-Web/Nativescript-Vue-Web) to develop web components with `Nativescript-Vue` syntax? (Default: No)
40+
* This prompt should only appear if you have chosen to develop in the Dual Web and Native environments.
41+
* By chosing `Use Nativescript-Vue-Web component framework`, it will effecively integrate a web component framework that will allow you to develop components that can be used in the Web and Native side of the project. It uses `NativeScript-Vue` like syntax on components which will allow for the sharing of components between NativeScript and Web.
42+
6. What type of template do you want to start with? (Default: Simple)
43+
* Simple is just a simple setup with a header and basic routing.
44+
* Sidebar (currently disabled), will allow you to start with a project that includes a fixed header and pop-out sidebar menu.
45+
* We expect to add more templates in the future as use cases come up.
46+
47+
## Running the project
48+
You will have several options in serving and building the project:
49+
1. `npm run serve:web`
50+
2. `npm run serve:android`
51+
3. `npm run serve:ios`
52+
4. `npm run build:web`
53+
5. `npm run build:android`
54+
6. `npm run build:ios`
55+
56+
The basic `serve` and `build` options should be similar to what is in a CLI 3 project except the added options to dictate which kind of environment you are using: `web`, `android` or `ios`. Please note that when building web projects, they will output to `dist` and when building native projects, they will output to `platforms\android` or `platforms\ios` depending on which you are building at the time.
57+
58+
#Webpack related information
59+
The options passes in at `npm run` will dictate what webpack config is provided. The first choice webpack will make is if this is a `web` or `native` environment. Then, if it's a `native` environment, it will determine choices to be made between `ios` and `android`.
60+
61+
Each time the project is built or served, the plugin will copy the latest webpack config from the cli to the root of your project. When you build a project, it will clean-up this file at the end, but just serving the project will not. This is an issue with [nativescript-dev-webpack](https://github.com/NativeScript/nativescript-dev-webpack) and cannot be overcome at this time.
62+
63+
#### Inspecting the Webpack config
64+
If you'd like to see what the webpack config is doing then you can run the following:
65+
`vue inspect --mode development.web > output.js` and the `output.js` file in root will show you what's going on. Subtitute `development.android` or `production.ios`, etc to see the different configs based on the environmental variables.
66+
67+
#### Aliases
68+
Prebuilt in the webpack config are several aliases that you can use. Here is a table listing out the various alias and the folder they use based on the environment chosen:
69+
70+
| Alias | Native | Web |
71+
| ---------- | --------------- | --------------- |
72+
| ~ | /app | /src |
73+
| @ | /app | /src |
74+
| src | /src | /src |
75+
| assets | /src/assets | /src/assets |
76+
| components | /src/components | /src/components |
77+
| fonts | /src/fonts | /src/fonts |
78+
| root | / | / |
79+
80+
81+
## For TypeScript enabled projects
82+
If your CLI 3 project has TypeScript enabled, then the plugin will attempt to give you a very basic TypeScript version of the template you choose. When you invoke the plugin and the template generator makes changes, you will notice the `*.d.ts` files that are usually in `src` will be moved to root so that they can be referenced inside of `src` and `app`. The plugin's webpack integration will ensure these files are referenced correctly at compile and runtimes.
83+
84+
## For Native environment development
85+
It should be noted that the plugin will give you the ability to develop generic SFC's (\*.native.vue) to be used in Android and IOS, or if you need to differentiate between Android (\*.android.vue) and IOS (\*.ios.vue) then you can change the SFC's extension to map to the environment you choose.
86+
87+
At `serve` or `build` in conjunction with the mode such as `android` or `ios`, it will filter which files are looked at. For instance, if you do `npm run serve:android`, then it will look for `*.native.vue` and `*.android.vue` files and ignore `*.ios.vue` files entirely. Conversely, it will do the same when your are doing the same for `ios` and will ignore `*.android.vue` files.
88+
89+
This will allow you to develop generic native components under the `*.native.vue` file extension, but in special cases, it may require you to do platform specific components. Use the corrosponding file extension to allow this to happen.
90+
91+
## Sharing components and assets between environments
92+
If you want to use common components and assets between `web`, `android` and `ios`, you can do that. Based on directory structures and webpack aliases setup by the plugin, it is __highly__ suggested you place these common items in the `src` folder directory structure. For `assets`, place them in `src/assets` and for components, place them in `src/components`. At compile time, assets will be copied to the output directory's `assets` folder and can be universally accessed across environments via something like `~/assets/logo.png`. For components, they can be universally accessed via something similar to `components/HelloWorld`.
93+
94+
95+

Diff for: generator/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# nativescript-vue-cli-plugin - Generator Readme
2+
3+
It is __highly suggested__ that you copy/paste the `simple` template in its entirety and then rename the copied directory. It will make it much easier for you to get starting using the existing logic in the generator. Modifications to the existing generator logic will be considered for PR, but __rarely approved__ as the changes could break all pre-existing templates.
4+
5+
If you want to add additional templates to the plugin, then here's the information on how to do it:
6+
7+
1. Create a new option to the prompt question #6 concerning which template you'd like to deploy.
8+
* The value for the template should be kept simple and easy.
9+
2. Create a new directory under `/generator/templates`.
10+
* The directory name should __exactly match__ the value from #1. For example if the value from #1 is `sidebar`, then the directory structure would be `/generator/templates/sidebar`
11+
* Add a `globals.d.ts` file. This can be copied from the `simple` template directory
12+
3. The new template directory must have a `src` and an `app` directory within it.
13+
4. Inside the `src` directory, you should add the following in an effort to give the template feature consistancy to the other templates:
14+
* tsconfig.json
15+
* router.js
16+
* main.js
17+
* App.vue
18+
* views/About.vue (optional)
19+
* views/Home.vue (optional)
20+
* components/HelloWorld.vue (optional)
21+
* assets/logo.png (optional, but highly encouraged to prove images are loading)
22+
5. Inside the `app` directory, you should add the following in an effort to give the template feature consistancy to the other templates:
23+
* tsconfig.json
24+
* package.json
25+
* main.js
26+
* App.native.vue
27+
* App.ios.vue
28+
* App.android.vue
29+
* views/About.native.vue (optional)
30+
* views/About.ios.vue (optional)
31+
* views/About.android.vue (optional)
32+
* views/Home.native.vue (optional)
33+
* views/Home.ios.vue (optional)
34+
* views/Home.android.vue (optional)
35+
* components/HelloWorld.native.vue (optional)
36+
* components/HelloWorld.ios.vue (optional)
37+
* components/HelloWorld.android.vue (optional)
38+
* assets/logo.png (optional, but highly encouraged to prove images are loading)
39+
40+
Concerning the `tsconfig.json` files. These are necessary to ensure TypeScript enabled projects will work correctly. If your directory structure within your template is different than what is in the `simple` template, then you will need to adjust your `tsconfig.json` files to account for those differences. Again, it is __highly suggested__ that you don't deviate from the directory structure provided by the `simple` template.
41+
42+
Within the \*.vue files you will find [ejs](https://github.com/mde/ejs) syntax that will enable you to differentiate between TypeScript and non-TypeScript projects as well as projects that use Nativesript-Vue-Web and those that don't. Any new templates added to the project __must__ demonstrate they work across these options or the PR to add the template will be rejected. For the Native side of the template in the `app` directory, you won't have to wory about the Nativescript-Vue-Web option as that is only for the web side of the template in `src`. However, you will have to account for TypeScript/non-Typescript in `app` and `src` template files.
43+
44+
If you add any of the optional files within the `app` directory structure, then you should make sure you have a \*.native.vue, \*.android.vue and \*.ios.vue example for each SFC. It would also be beneficial within each of those to have a way to identify to the developer which file is being used at compile time. Take a look at the `simple` template's `app\views\about.*.vue` examples to see a basic example of this.

Diff for: generator/index.js

-30
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,6 @@ module.exports = async (api, options, rootOptions) => {
3737
const templateTypePathModifer = options.templateType;
3838

3939

40-
// // // const srcfiles = [
41-
// // // 'router.js',
42-
// // // 'main.js',
43-
// // // api.hasPlugin('typescript') ? 'tsconfig.json' : '',
44-
// // // 'App.vue',
45-
// // // 'views/About.vue',
46-
// // // 'views/Home.vue',
47-
// // // 'components/HelloWorld.vue',
48-
// // // 'assets/logo.png'
49-
// // // ]
50-
51-
// // // const appfiles = [
52-
// // // 'package.json',
53-
// // // 'main.js',
54-
// // // api.hasPlugin('typescript') ? 'tsconfig.json' : '',
55-
// // // 'App.native.vue',
56-
// // // 'App.ios.vue',
57-
// // // 'App.android.vue',
58-
// // // 'views/About.native.vue',
59-
// // // 'views/About.ios.vue',
60-
// // // 'views/About.android.vue',
61-
// // // 'views/Home.native.vue',
62-
// // // 'views/Home.ios.vue',
63-
// // // 'views/Home.android.vue',
64-
// // // 'components/HelloWorld.native.vue',
65-
// // // 'components/HelloWorld.ios.vue',
66-
// // // 'components/HelloWorld.android.vue',
67-
// // // ]
68-
69-
7040
// New Project & Native Only -- should never be able to use Nativescript-Vue-Web
7141
if (options.isNativeOnly === 'native' && options.isNVW) {
7242
throw Error('Invalid options chosen. You cannot have a Native only project and use Nativescript-Vue-Web')

Diff for: generator/templates/simple/without-nvw/src/App.vue

+14-2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@
238238
}"`
239239
: ``
240240
%>>
241-
.w-navbar {
241+
<%_ if (!usingNVW) { _%>
242+
.w-navbar {
242243
color: #42b983;
243244
}
244245

@@ -297,10 +298,16 @@
297298
}
298299

299300
}
300-
301+
<%_ } else { _%>
302+
<%# Is using NVW %>
303+
ActionBar {
304+
color: #42b983;
305+
}
306+
<%_ } _%>
301307
</style>
302308
<%_ } else { _%>
303309
<style lang="stylus">
310+
<%_ if (!usingNVW) { _%>
304311
.w-navbar
305312
color: #42b983
306313
.w-page
@@ -345,5 +352,10 @@
345352
border-width: 0px
346353
font-weight: 600
347354
border-radius: 3px
355+
<%_ } else { _%>
356+
<%# Is using NVW %>
357+
ActionBar
358+
color #42b983
359+
<%_ } _%>
348360
</style>
349361
<%_ } _%>

Diff for: generator/templates/simple/without-nvw/src/views/About.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// ActionBar,
4545
GridLayout,
4646
// eslint-disable-next-line
47-
Label
47+
Label,
4848
},
4949
data() {
5050
return {
@@ -71,7 +71,7 @@
7171
// ActionBar,
7272
GridLayout,
7373
// eslint-disable-next-line
74-
Label
74+
Label,
7575
},
7676
data() {
7777
return {

Diff for: prompts.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,37 @@ Example: com.company.app`
3333
{
3434
name: 'isNativeOnly',
3535
type: 'list',
36-
message: 'Do you want a dual Native and Web setup or a Native only setup?',
36+
message: 'Dual Native AND Web development experience or a Native only? (Default: Dual)',
3737
choices: [{
38-
name: 'Dual Native and Web setup',
38+
name: 'Dual Native AND Web',
3939
value: 'dual'
4040
},
4141
{
42-
name: 'Native only setup',
42+
name: 'Native only',
4343
value: 'native'
4444
}
4545
],
4646
default: 'dual'
4747
},
4848
{
4949
name: 'isNVW',
50-
type: 'confirm',
51-
message: 'Do you want to develop dual-use Web & Native components via Nativescript-Vue-Web? (Default: No)',
52-
default: false
50+
type: 'list',
51+
message: 'Use Nativescript-Vue-Web to develop web components with Nativescript-Vue like syntax? (Default: No)',
52+
choices: [
53+
{
54+
name: 'I\'ll bring my own web component framework',
55+
value: false
56+
},
57+
{
58+
name: 'Use Nativescript-Vue-Web component framework',
59+
value: true
60+
}
61+
],
62+
default: false,
63+
when: (answers) => {
64+
// prompt will only show up if isNativeOnly === 'dual'
65+
return answers.isNativeOnly === 'dual';
66+
}
5367
},
5468
{
5569
name: 'templateType',

0 commit comments

Comments
 (0)