Skip to content

Commit 35ebb09

Browse files
committed
Added an npm script to run the sample apps more easily
1 parent 9c9f8f0 commit 35ebb09

10 files changed

+581
-442
lines changed

package-lock.json

Lines changed: 504 additions & 435 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"test": "jest",
88
"tdd": "jest --watch",
99
"dev": "rollup -c -w --o samples/app/nativescript-vue.js",
10+
"samples": "node sample-runner.js",
1011
"build": "rollup -c",
1112
"precommit": "lint-staged"
1213
},
@@ -46,6 +47,8 @@
4647
"devDependencies": {
4748
"babel-jest": "^19.0.0",
4849
"babel-preset-env": "^1.4.0",
50+
"chalk": "^2.1.0",
51+
"inquirer": "^3.3.0",
4952
"jest": "^19.0.2",
5053
"jest-junit": "^1.5.1",
5154
"prettier": "^1.6.1",

sample-runner.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const inquirer = require('inquirer')
2+
const chalk = require('chalk')
3+
const fs = require('fs')
4+
const { spawn } = require('child_process')
5+
const samplePackage = require('./samples/app/package.json')
6+
const originalMain = samplePackage.main
7+
8+
let tns
9+
10+
const files = fs.readdirSync('./samples/app')
11+
.filter((file) => file.endsWith('.js'))
12+
.filter((file) => !file.startsWith('nativescript-vue'))
13+
14+
inquirer.prompt([{
15+
type: 'list',
16+
message: 'Choose a sample to run',
17+
name: 'sample',
18+
choices: files,
19+
}, {
20+
type: 'list',
21+
message: 'Choose a platform to run on',
22+
name: 'platform',
23+
choices: [
24+
'Android',
25+
'iOS'
26+
],
27+
}]).then((res) => {
28+
setMain(res.sample)
29+
tns = spawn('tns', ['run', res.platform], {
30+
cwd: './samples',
31+
})
32+
33+
34+
tns.on('error', (err) => {
35+
console.log(err)
36+
})
37+
38+
tns.stdout.on('data', (chunk) => {
39+
const line = chunk.toString().trim()
40+
41+
const [prefix, message] = line.split(' {NSVue} -> ')
42+
if (prefix && message) {
43+
console.log(`${prefix} ${chalk.keyword('gray')('{')}${chalk.keyword('yellow')('NSVue')}${chalk.keyword('gray')('}')} -> ${message}`)
44+
} else {
45+
console.log(line)
46+
}
47+
})
48+
})
49+
50+
function shutDown() {
51+
if (tns) {
52+
tns.stdin.pause()
53+
tns.kill()
54+
setMain(originalMain)
55+
}
56+
57+
console.log('\n\nHave a nice day! :)')
58+
59+
process.exit()
60+
}
61+
62+
function setMain(file) {
63+
samplePackage.main = file
64+
fs.writeFileSync('./samples/app/package.json', JSON.stringify(samplePackage, null, 2))
65+
}
66+
67+
process.on('SIGTERM', shutDown)
68+
process.on('SIGINT', shutDown)

samples/app/app-with-list-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Vue = require('nativescript-vue/dist/index')
1+
const Vue = require('./nativescript-vue')
22
const http = require('http')
33
const Page = require('ui/page').Page
44
const StackLayout = require('ui/layouts/stack-layout').StackLayout

samples/app/app-with-router-pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Vue = require('nativescript-vue/dist/index')
1+
const Vue = require('./nativescript-vue')
22
const VueRouter = require('vue-router')
33
Vue.use(VueRouter)
44
global.process = { env: {} } // hack! a build process should replace process.env's with static strings.

samples/app/app-with-router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Vue = require('../dist/index')
1+
const Vue = require('./nativescript-vue')
22
const VueRouter = require('vue-router')
33
Vue.use(VueRouter)
44
global.process = { env: {} } // hack! a build process should replace process.env's with static strings.

samples/app/app-with-tab-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Vue = require('../dist/index')
1+
const Vue = require('./nativescript-vue')
22

33
let app = new Vue({
44
data: {

samples/app/app-with-vmodel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Vue = require('../dist/index')
1+
const Vue = require('./nativescript-vue')
22
new Vue({
33
data: {
44
test: 'testing',

samples/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Vue = require('../dist/index')
1+
const Vue = require('./nativescript-vue')
22

33
Vue.component('image-viewer', {
44
props: ['imgSrc'],

samples/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"dependencies": {
1616
"nativescript-gradient": "^2.0.0",
1717
"nativescript-theme-core": "~1.0.2",
18-
"nativescript-vue": "^0.1.3",
1918
"tns-core-modules": "^3.0.0",
2019
"vue-router": "^2.4.0"
2120
},

0 commit comments

Comments
 (0)