Skip to content
This repository has been archived by the owner on Mar 4, 2025. It is now read-only.

Feat: Generate typescript package types and tests #449

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4a05248
typescript support using typescript-build
ChangJoo-Park Aug 21, 2019
4bd4f08
Remove trailing comma
ChangJoo-Park Aug 21, 2019
8dbe5ea
Merge branch 'master' into typescript
ChangJoo-Park Aug 28, 2019
e244e81
remove @types/node
ChangJoo-Park Aug 29, 2019
bf7e77c
Add default / ts-runtime for none server + ts
ChangJoo-Park Aug 29, 2019
bf36d5d
set lang="ts" when using typescript
ChangJoo-Park Aug 29, 2019
764cfdb
Remove ts-node
ChangJoo-Park Aug 29, 2019
f06ceea
@nuxt/typescript-build version to 0.1.11
ChangJoo-Park Aug 30, 2019
6d9431d
Update ts script tag
ChangJoo-Park Aug 30, 2019
a28343e
Add typescript nuxt cookbook when completed
ChangJoo-Park Aug 30, 2019
b5df795
Using tsconfig.json using always when selected ts
ChangJoo-Park Aug 30, 2019
9c28d89
only suggestion jsconfig.json when js users
ChangJoo-Park Aug 30, 2019
0f16c8e
fix typo
ChangJoo-Park Aug 30, 2019
abf30c7
using js by default
ChangJoo-Park Aug 30, 2019
4d62b71
tsconfig / jsconfig settings
ChangJoo-Park Aug 30, 2019
4f498f7
add closing tag for ts
ChangJoo-Park Aug 30, 2019
b68b79f
Delete package-lock.json
ChangJoo-Park Aug 30, 2019
d3df5d4
Update template/nuxt/pages/index.vue
ChangJoo-Park Aug 30, 2019
2da1f54
support eslint when TypeScript.
ChangJoo-Park Aug 30, 2019
97a6afd
set false tsRuntime when select TypeScript
ChangJoo-Park Aug 30, 2019
309662c
support jest with typescript
ChangJoo-Park Aug 30, 2019
ffacdd1
Update saofile.js
ChangJoo-Park Sep 2, 2019
8a81cad
Update template/tsconfig.json
ChangJoo-Park Sep 4, 2019
4476bab
Merge branch 'master' into typescript
ChangJoo-Park Oct 23, 2019
55c482a
Add language and runtime to prompts.js
ChangJoo-Park Oct 23, 2019
fa611c6
Update TypeScript relative package versions
ChangJoo-Park Oct 23, 2019
c26e961
@nuxt/core needs eslint-module
ChangJoo-Park Oct 23, 2019
ab8be4a
Update tsconfig.json
ChangJoo-Park Oct 24, 2019
57461b2
Update README for TypeScript
ChangJoo-Park Oct 24, 2019
f2e66a7
Merge branch 'typescript' of https://github.com/ChangJoo-Park/create-…
ChangJoo-Park Oct 24, 2019
aaa09be
standardize generating typescript components
NickBolles Oct 25, 2019
fafe31b
generate nuxt.config.ts instead of nuxt.config.js if typescript runti…
NickBolles Oct 25, 2019
1a428b6
Add ts files to lint-staged if typescript is on
NickBolles Nov 14, 2019
1b4d80e
Remove unused imports
NickBolles Nov 14, 2019
34ecbfd
remove unused imports
NickBolles Nov 14, 2019
403abfd
standardize generating typescript components
NickBolles Oct 25, 2019
e0fd272
generate nuxt.config.ts instead of nuxt.config.js if typescript runti…
NickBolles Oct 25, 2019
5935b7f
Add ts files to lint-staged if typescript is on
NickBolles Nov 14, 2019
9d5a65e
Remove unused imports
NickBolles Nov 14, 2019
8449d54
remove unused imports
NickBolles Nov 14, 2019
c266cbb
fix: only prompt for jsconfig.json if language is js
NickBolles Mar 28, 2020
c67001d
feat(typescript): add vue-shims.d.ts
NickBolles Mar 28, 2020
e67766d
fix: use _ to indicate unused vars and avoid lint issue
NickBolles Mar 28, 2020
76dc688
feat(typescript): add jest typings if typescript is enabled
NickBolles Mar 28, 2020
0f60127
fix: fix typescript generation for framevuerk, vuesax and vuetify
NickBolles Mar 29, 2020
0ffd829
feat(typescript): add typescript files to eslint
NickBolles Mar 29, 2020
84ed1a8
fix: always show jsconfig, but add hint for typescript
NickBolles Mar 29, 2020
4568528
fix: sync up nuxt.config for js and ts
NickBolles Mar 29, 2020
73a814b
test: fix typescript runtime test, reset snapshots
NickBolles Mar 29, 2020
9a44125
style: fix linting issues
NickBolles Mar 29, 2020
c55e86d
fix: disable vue/no-parsing-error
NickBolles Apr 7, 2020
b7edfbe
fix: code stye for PR comments
NickBolles Apr 14, 2020
0cc044a
Merge branch 'master' into typescript
NickBolles Apr 14, 2020
0e0cc70
test: remove old snapshot file
NickBolles Apr 14, 2020
109dc39
test: update snapshots and code style
NickBolles Apr 14, 2020
2cf51a4
style: fix duplicate line break
NickBolles Apr 23, 2020
430be0b
Merge branch 'master' of https://github.com/nuxt/create-nuxt-app into…
NickBolles Apr 23, 2020
5dbe0e5
fix: merge to package.js instead of package.json
NickBolles Apr 23, 2020
2c337d5
fix: merge issues
NickBolles Apr 23, 2020
2dc48dd
update test snapshots
NickBolles Apr 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module.exports = [
message: 'Choose development tools',
type: 'checkbox',
choices: [
{ name: 'jsconfig.json (Recommended for VS Code)', value: 'jsconfig.json' },
{ name: 'jsconfig.json (Recommended for VS Code if you\'re not using typescript)', value: 'jsconfig.json' },
{ name: 'Semantic Pull Requests', value: 'semantic-pull-requests' }
],
default: []
Expand Down
63 changes: 43 additions & 20 deletions saofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const rootDir = __dirname

module.exports = {
prompts: require('./prompts'),
templateData () {
templateData() {
const typescript = this.answers.language.includes('ts')
const tsRuntime = this.answers.runtime && this.answers.runtime.includes('ts-runtime')
const tsRuntime =
this.answers.runtime && this.answers.runtime.includes('ts-runtime')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO Unnecessary change

const pwa = this.answers.features.includes('pwa')
const eslint = this.answers.linter.includes('eslint')
const prettier = this.answers.linter.includes('prettier')
Expand All @@ -24,7 +25,18 @@ module.exports = {
const { cliOptions = {} } = this.sao.opts
const edge = cliOptions.edge ? '-edge' : ''

const ifTrue = (condition, content, elseContent) => condition ? content : elseContent || ''
const generateComponent = (imports, componentOptions) => {
return `
<script ${ifTrue(typescript, `lang="ts"`)}>
${ifTrue(typescript, `import Vue from 'vue'`)}
${ifTrue(!!imports, imports)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is there are imports, a carriage return should be ensured between imports and export.

export default ${ifTrue(typescript, 'Vue.extend(' + componentOptions + ')', componentOptions)}
</script>`
}

return {
generateComponent,
typescript,
tsRuntime,
pwa,
Expand All @@ -40,24 +52,30 @@ module.exports = {
dotenv
}
},
actions () {
actions() {
const validation = validate(this.answers.name)
validation.warnings && validation.warnings.forEach((warn) => {
console.warn('Warning:', warn)
})
validation.errors && validation.errors.forEach((err) => {
console.error('Error:', err)
})
validation.warnings &&
validation.warnings.forEach((warn) => {
console.warn('Warning:', warn)
})
validation.errors &&
validation.errors.forEach((err) => {
console.error('Error:', err)
})
validation.errors && validation.errors.length && process.exit(1)

const actions = [{
type: 'add',
files: '**',
templateDir: 'template/nuxt',
filters: {
'static/icon.png': 'features.includes("pwa")'
const actions = [
{
type: 'add',
files: '**',
templateDir: 'template/nuxt',
filters: {
'static/icon.png': 'features.includes("pwa")',
'nuxt.config.ts': 'runtime && runtime.includes("ts-runtime")',
'nuxt.config.js': '!runtime || !runtime.includes("ts-runtime")'
}
}
}]
]

if (this.answers.ui !== 'none') {
actions.push({
Expand Down Expand Up @@ -107,6 +125,7 @@ module.exports = {
'_.prettierrc': 'linter.includes("prettier")',
'_jsconfig.json': 'devTools.includes("jsconfig.json")',
'tsconfig.json': 'language.includes("ts")',
'vue-shims.d.ts': 'language.includes("ts")',
'semantic.yml': 'devTools.includes("semantic-pull-requests")',
'.env': 'features.includes("dotenv")',
'_stylelint.config.js': 'linter.includes("stylelint")'
Expand All @@ -129,7 +148,7 @@ module.exports = {
actions.push({
type: 'modify',
files: 'package.json',
handler (data) {
handler(data) {
delete data.scripts['']
delete data.dependencies['']
delete data.devDependencies['']
Expand All @@ -139,7 +158,7 @@ module.exports = {

return actions
},
async completed () {
async completed() {
this.gitInit()

await this.npmInstall({ npmClient: this.answers.pm })
Expand All @@ -161,7 +180,9 @@ module.exports = {
const cdMsg = isNewFolder ? chalk`\t{cyan cd ${relativeOutFolder}}\n` : ''
const pmRun = this.answers.pm === 'yarn' ? 'yarn' : 'npm run'

console.log(chalk`\n🎉 {bold Successfully created project} {cyan ${this.answers.name}}\n`)
console.log(
chalk`\n🎉 {bold Successfully created project} {cyan ${this.answers.name}}\n`
)

console.log(chalk` {bold To get started:}\n`)
console.log(chalk`${cdMsg}\t{cyan ${pmRun} dev}\n`)
Expand All @@ -176,7 +197,9 @@ module.exports = {
}

if (this.answers.language.includes('ts')) {
console.log(chalk`\n {bold For TypeScript users.} \n\n See : https://typescript.nuxtjs.org/cookbook/components/`)
console.log(
chalk`\n {bold For TypeScript users.} \n\n See : https://typescript.nuxtjs.org/cookbook/components/`
)
}
}
}
5 changes: 3 additions & 2 deletions template/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"prepublish": "<%= pmRun %> build:framevuerk",
<%_ } _%>
<%_ if (eslint) { _%>
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"lint": "eslint --ext .js,.vue<%= typescript ? ",ts" : "" %> --ignore-path .gitignore .",
<%_ } _%>
<%_ if (test === 'ava') { _%>
"test": "<%= test %>",
Expand All @@ -47,7 +47,7 @@
<%_ if (lintStaged) { _%>
"lint-staged": {
<%_ if (eslint) { _%>
"*.{js,vue}": "<%= pmRun %> lint"<%= stylelint ? "," : "" %>
"*.{js,vue<%= typescript ? ",ts" : "" %>}": "<%= pmRun %> lint"<%= stylelint ? "," : "" %>
<%_ } _%>
<%_ if (stylelint) { _%>
"*.{css,vue}": "stylelint"
Expand Down Expand Up @@ -177,6 +177,7 @@
"jest": "^24.1.0",
"vue-jest": "^4.0.0-0",
<%_ if (typescript) { _%>
"@types/jest": "^24.1.0",
"ts-jest": "^25.0.0",
<%_ } _%>
<%_ } else if (test === 'ava') { _%>
Expand Down
6 changes: 2 additions & 4 deletions template/frameworks/buefy/components/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
</div>
</template>

<script>
export default {
<%- generateComponent('', `{
props: {
title: {
type: String,
Expand All @@ -38,5 +37,4 @@ export default {
required: true
}
}
}
</script>
}`) %>
6 changes: 2 additions & 4 deletions template/frameworks/buefy/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
</div>
</template>

<script>
export default {
<%- generateComponent('', `{
data () {
return {
items: [
Expand All @@ -70,5 +69,4 @@ export default {
]
}
}
}
</script>
}`) %>
9 changes: 3 additions & 6 deletions template/frameworks/buefy/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@
</section>
</template>

<script>
import Card from '~/components/Card'

export default {
<%- generateComponent(
`import Card from '~/components/Card'`, `{
name: 'HomePage',

components: {
Card
}
}
</script>
}`) %>
6 changes: 2 additions & 4 deletions template/frameworks/framevuerk/components/FramevuerkLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
</div>
</template>

<script>
export default {
<%- generateComponent('',`{
data () {
return {
isReady: false
Expand All @@ -38,8 +37,7 @@ export default {
this.isReady = true
}, 1000)
}
}
</script>
}`) %>

<style scoped>
.logo {
Expand Down
11 changes: 4 additions & 7 deletions template/frameworks/framevuerk/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@
</fvMain>
</template>

<script>
import Logo from '~/components/Logo.vue'
import FramevuerkLogo from '~/components/FramevuerkLogo.vue'

export default {
<%- generateComponent(
`import Logo from '~/components/Logo.vue'
import FramevuerkLogo from '~/components/FramevuerkLogo.vue'`, `{
components: {
Logo,
FramevuerkLogo
Expand Down Expand Up @@ -169,9 +168,7 @@ export default {
})
}
}
}
</script>

}`) %>
<style scoped>
.content {
margin: 0 auto;
Expand Down
8 changes: 3 additions & 5 deletions template/frameworks/iview/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
</div>
</template>

<script>
import Logo from '~/components/Logo.vue'
export default {
<%- generateComponent(
`import Logo from '~/components/Logo.vue'`,`{
components: {
Logo
}
}
</script>
}`) %>

<style>
.container {
Expand Down
9 changes: 9 additions & 0 deletions template/frameworks/vuesax/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
</div>
</template>

<%- generateComponent(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like the script section hasn't been removed from this file

import Logo from '~/components/Logo.vue'
import VuesaxLogo from '~/components/VuesaxLogo.vue'
`,`{
components: {
Logo,
VuesaxLogo
}
}`)%>
<script>
import Logo from '~/components/Logo.vue'
import VuesaxLogo from '~/components/VuesaxLogo.vue'
Expand Down
6 changes: 2 additions & 4 deletions template/frameworks/vuetify/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
</v-app>
</template>

<script>
export default {
<%- generateComponent(``,`{
data () {
return {
clipped: false,
Expand All @@ -113,5 +112,4 @@ export default {
title: 'Vuetify.js'
}
}
}
</script>
}`) %>
6 changes: 2 additions & 4 deletions template/frameworks/vuetify/layouts/error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
</v-app>
</template>

<script>
export default {
<%- generateComponent(``,`{
layout: 'empty',
props: {
error: {
Expand All @@ -34,8 +33,7 @@ export default {
title
}
}
}
</script>
}`) %>

<style scoped>
h1 {
Expand Down
12 changes: 5 additions & 7 deletions template/frameworks/vuetify/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@
</v-layout>
</template>

<script>
import Logo from '~/components/Logo.vue'
import VuetifyLogo from '~/components/VuetifyLogo.vue'

export default {
<%- generateComponent(`
import Logo from '~/components/Logo.vue'
import VuetifyLogo from '~/components/VuetifyLogo.vue'
`,`{
components: {
Logo,
VuetifyLogo
}
}
</script>
}`) %>
3 changes: 2 additions & 1 deletion template/nuxt/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = {
/*
** Nuxt.js dev-modules
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this carriage return is needed as it's not done for the other comments on top of properties.

Suggested change

buildModules: [
<%_ if (typescript) {_%>
'@nuxt/typescript-build',
Expand Down Expand Up @@ -180,7 +181,7 @@ module.exports = {
/*
** You can extend webpack config here
*/
extend (config, ctx) {
extend (_config, _ctx) {
}
}
}
Loading