Skip to content

Commit ef2bb47

Browse files
committed
feat: add correct tns template
1 parent 481d4d0 commit ef2bb47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+876
-19
lines changed

meta.js

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,106 @@
1+
const path = require('path')
2+
const fs = require('fs')
3+
const spawn = require('child_process').spawn
4+
5+
/**
6+
* Spawns a child process and runs the specified command
7+
* By default, runs in the CWD and inherits stdio
8+
* Options are the same as node's child_process.spawn
9+
* @param {string} cmd
10+
* @param {array<string>} args
11+
* @param {object} options
12+
*/
13+
function runCommand(cmd, args, options) {
14+
const command = `${cmd} ${args.join(' ')}`;
15+
console.log('\nExecuting: ${command}\n')
16+
return new Promise((resolve, reject) => {
17+
const spwan = spawn(
18+
cmd,
19+
args,
20+
Object.assign(
21+
{
22+
cwd: process.cwd(),
23+
stdio: 'inherit',
24+
shell: true,
25+
},
26+
options
27+
)
28+
)
29+
30+
spwan.on('exit', () => {
31+
resolve()
32+
})
33+
})
34+
}
35+
136
module.exports = {
237
prompts: {
338
name: {
4-
type: "string",
39+
type: 'string',
540
required: true,
6-
message: "Project name (kebab-case only)"
41+
message: 'Project name (kebab-case only)'
742
},
843
description: {
9-
type: "string",
44+
type: 'string',
1045
required: true,
11-
message: "Project description",
12-
default: "A Nativescript + Vue.js 2.0 project"
46+
message: 'Project description',
47+
default: 'A Nativescript + Vue.js 2.0 project'
1348
},
1449
author: {
15-
type: "string",
16-
message: "Author"
50+
type: 'string',
51+
message: 'Author'
1752
},
1853
repos: {
19-
type: "string",
54+
type: 'string',
2055
required: true,
21-
message: "Github repository URL",
22-
default: "user/repository"
56+
message: 'Github repository URL',
57+
default: 'user/repository'
2358
},
2459
semanticRelease: {
25-
type: "confirm",
26-
message: "Do you want to use semantic release?",
60+
type: 'confirm',
61+
message: 'Do you want to use semantic release?',
62+
default: true
63+
},
64+
autoInstall: {
65+
type: 'confirm',
66+
message: 'Do you want to auto-install everything with npm?',
2767
default: true
2868
}
2969
},
3070
filters: {
31-
".commitlintrc.json": "semanticRelease"
71+
'.commitlintrc.json': 'semanticRelease'
3272
},
33-
skipInterpolation: "src/**/*.{html,vue}",
73+
skipInterpolation: 'src/**/*.{html,vue}',
3474
complete (data) {
35-
console.log(data)
36-
// cd dir
37-
// npm install -g nativescript semantic-release-cli && npm install && tns init && semantic-release-cli setup
75+
const cwd = path.join(process.cwd(), data.inPlace ? '' : data.destDirName)
76+
const instructions = `please execute:\n\n$ cd ${data.destDirName} && npm run dev\n\nAnd in another shell:\n\n$ tns run [platform]`;
77+
78+
// init global install params
79+
const params = ['install', '-g', 'nativescript']
80+
if (data.semanticRelease) {
81+
// add semantic release
82+
params.push('semantic-release-cli')
83+
}
84+
85+
if (data.autoInstall) {
86+
// install global packages
87+
runCommand('npm', params, {cwd})
88+
// install project local packages
89+
.then(() => runCommand('npm', ['install'], {cwd}))
90+
// init project folder as nativescript project
91+
.then(() => runCommand('tns', ['init'], {cwd}))
92+
// install nativescript dependencies and init template
93+
.then(() => runCommand('tns', ['install'], {cwd}))
94+
// run semantic release setup if needed
95+
.then(() => (data.semanticRelease ? runCommand('semantic-release-cli', ['setup'], {cwd}) : Promise.resolve()))
96+
.then(() => console.log(`Install completed. To get started, ${instructions}`))
97+
.catch(() => console.error('Something went wrong. Please see the log above.'))
98+
} else {
99+
// print instructions
100+
const npmParams = params.join(' ')
101+
const semanticReleaseCommand = data.semanticRelease ? '&& semantic-release-cli setup' : '';
102+
console.log(`\nPlease execute the following script to finish the setup process :\n$ cd ${data.destDirName}\n$ npm ${npmParams} && npm install && tns init ${semanticReleaseCommand}\n\n`);
103+
console.log(`After installation completed, ${instructions}`)
104+
}
38105
}
39106
}

template/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/app
1+
/app/app.*
22
/node_modules
33
/platforms
44

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="__PACKAGE__"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
7+
<supports-screens
8+
android:smallScreens="true"
9+
android:normalScreens="true"
10+
android:largeScreens="true"
11+
android:xlargeScreens="true"/>
12+
13+
<uses-sdk
14+
android:minSdkVersion="17"
15+
android:targetSdkVersion="__APILEVEL__"/>
16+
17+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
19+
<uses-permission android:name="android.permission.INTERNET"/>
20+
21+
<application
22+
android:name="com.tns.NativeScriptApplication"
23+
android:allowBackup="true"
24+
android:icon="@drawable/icon"
25+
android:label="@string/app_name"
26+
android:theme="@style/AppTheme">
27+
28+
<activity
29+
android:name="com.tns.NativeScriptActivity"
30+
android:label="@string/title_activity_kimera"
31+
android:configChanges="keyboardHidden|orientation|screenSize"
32+
android:theme="@style/LaunchScreenTheme">
33+
34+
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
35+
36+
<intent-filter>
37+
<action android:name="android.intent.action.MAIN" />
38+
<category android:name="android.intent.category.LAUNCHER" />
39+
</intent-filter>
40+
</activity>
41+
<activity android:name="com.tns.ErrorReportActivity"/>
42+
</application>
43+
</manifest>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Add your native dependencies here:
2+
3+
// Uncomment to add recyclerview-v7 dependency
4+
//dependencies {
5+
// compile 'com.android.support:recyclerview-v7:+'
6+
//}
7+
8+
android {
9+
defaultConfig {
10+
generatedDensities = []
11+
applicationId = "__PACKAGE__"
12+
13+
//override supported platforms
14+
// ndk {
15+
// abiFilters.clear()
16+
// abiFilters "armeabi-v7a"
17+
// }
18+
19+
}
20+
aaptOptions {
21+
additionalParameters "--no-version-vectors"
22+
}
23+
}
3.42 KB
Loading
6.8 KB
Loading
32.4 KB
Loading
1.31 KB
Loading
3.23 KB
Loading
9.95 KB
Loading

0 commit comments

Comments
 (0)