Merge pull request #37 from transitive-bullshit/feature/typescript-support-v2
add typescript support v2
This commit is contained in:
parent
faba0e5f9e
commit
c0769c2743
45 changed files with 2544 additions and 6662 deletions
|
@ -14,6 +14,7 @@ const pkg = require('../package')
|
|||
module.exports = async (info) => {
|
||||
const {
|
||||
manager,
|
||||
template,
|
||||
name
|
||||
} = info
|
||||
|
||||
|
@ -25,7 +26,7 @@ module.exports = async (info) => {
|
|||
info.dest = dest
|
||||
await mkdirp(dest)
|
||||
|
||||
const source = path.join(__dirname, '../template')
|
||||
const source = path.join(__dirname, '..', 'template', template)
|
||||
const files = await globby(source, {
|
||||
dot: true
|
||||
})
|
||||
|
@ -39,7 +40,7 @@ module.exports = async (info) => {
|
|||
info
|
||||
})
|
||||
})
|
||||
ora.promise(promise, `Copying template to ${dest}`)
|
||||
ora.promise(promise, `Copying ${template} template to ${dest}`)
|
||||
await promise
|
||||
}
|
||||
|
||||
|
@ -98,14 +99,12 @@ module.exports.initPackageManager = async (opts) => {
|
|||
{
|
||||
cmd: `${info.manager} link`,
|
||||
cwd: dest
|
||||
}
|
||||
].concat(info.manager === 'yarn' ? [
|
||||
},
|
||||
{
|
||||
cmd: `${info.manager}`,
|
||||
cmd: `${info.manager} install`,
|
||||
cwd: example
|
||||
}
|
||||
] : [ ]
|
||||
)
|
||||
]
|
||||
|
||||
return pEachSeries(commands, async ({ cmd, cwd }) => {
|
||||
return execa.shell(cmd, { cwd })
|
||||
|
|
|
@ -14,7 +14,17 @@ const tests = [
|
|||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'nala/my-test-library',
|
||||
license: 'MIT',
|
||||
manager: 'yarn'
|
||||
manager: 'yarn',
|
||||
template: 'default'
|
||||
},
|
||||
{
|
||||
name: 'my-test-typescript-library',
|
||||
author: 'nala',
|
||||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'nala/my-test-library',
|
||||
license: 'MIT',
|
||||
manager: 'yarn',
|
||||
template: 'typescript'
|
||||
},
|
||||
{
|
||||
name: 'my-test-library',
|
||||
|
@ -22,7 +32,17 @@ const tests = [
|
|||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'nala/my-test-library',
|
||||
license: 'MIT',
|
||||
manager: 'npm'
|
||||
manager: 'npm',
|
||||
template: 'default'
|
||||
},
|
||||
{
|
||||
name: 'my-test-library',
|
||||
author: 'nala',
|
||||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'nala/my-test-typescript-library',
|
||||
license: 'MIT',
|
||||
manager: 'npm',
|
||||
template: 'typescript'
|
||||
},
|
||||
{
|
||||
name: '@automagical/nala',
|
||||
|
@ -30,32 +50,36 @@ const tests = [
|
|||
description: 'this is a auto-generated test module. please ignore.',
|
||||
repo: 'superstar-cats/nala',
|
||||
license: 'GPL',
|
||||
manager: 'yarn'
|
||||
manager: 'yarn',
|
||||
template: 'default'
|
||||
}
|
||||
]
|
||||
|
||||
tests.forEach((info) => {
|
||||
test.serial(`creating "${info.name}" using ${info.manager}`, async (t) => {
|
||||
console.log(`creating "${info.name}" using ${info.manager}...`)
|
||||
tests.forEach((opts) => {
|
||||
test.serial(`creating "${opts.name}" using ${opts.manager}`, async (t) => {
|
||||
console.log(`creating "${opts.name}" using ${opts.manager}...`)
|
||||
let ret
|
||||
|
||||
// ensure library is created successfully
|
||||
const root = await createLibrary(info)
|
||||
t.truthy(root.indexOf(info.shortName) >= 0)
|
||||
const root = await createLibrary(opts)
|
||||
const example = path.join(root, 'example')
|
||||
t.truthy(root.indexOf(opts.shortName) >= 0)
|
||||
|
||||
// ensure yarn runs successfully in src/
|
||||
ret = await execa.shell('yarn', { cwd: root })
|
||||
// ensure deps install successfully in root
|
||||
ret = await execa.shell(`${opts.manager} install`, { cwd: root })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
// ensure jest tests pass
|
||||
ret = await execa.shell('yarn test', { cwd: root })
|
||||
// ensure root tests pass
|
||||
ret = await execa.shell(`${opts.manager} test`, { cwd: root })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
if (info.manager === 'yarn') {
|
||||
// ensure yarn runs successfully in example/
|
||||
ret = await execa.shell('yarn install', { cwd: path.join(root, 'example') })
|
||||
t.is(ret.code, 0)
|
||||
}
|
||||
// ensure deps install successfully in example
|
||||
ret = await execa.shell(`${opts.manager} install`, { cwd: example })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
// ensure bundle builds successfully in example
|
||||
ret = await execa.shell(`${opts.manager} build`, { cwd: example })
|
||||
t.is(ret.code, 0)
|
||||
|
||||
// ensure git is initialized properly
|
||||
ret = await execa.shell('git status', { cwd: root })
|
||||
|
|
|
@ -14,7 +14,8 @@ module.exports = async () => {
|
|||
author: config.get('author'),
|
||||
repo: (info) => `${info.author}/${info.name}`,
|
||||
license: config.get('license', 'MIT'),
|
||||
manager: config.get('manager', 'npm')
|
||||
manager: config.get('manager', 'npm'),
|
||||
template: config.get('template', 'default')
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -41,7 +42,11 @@ module.exports = async () => {
|
|||
defaults.manager = 'yarn'
|
||||
}
|
||||
|
||||
config.set('manager', defaults.manager || 'npm')
|
||||
config.set('manager', defaults.manager)
|
||||
}
|
||||
|
||||
if (!config.get('template')) {
|
||||
config.set('template', defaults.template)
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const program = require('commander')
|
||||
const { version } = require('../package')
|
||||
|
||||
|
@ -20,6 +21,7 @@ module.exports = async () => {
|
|||
.option('-l, --license <string>', 'package license', defaults.license)
|
||||
.option('-r, --repo <string>', 'package repo path')
|
||||
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
|
||||
.option('-t, --template <default|typescript>', 'package template to use', /^(default|typescript)$/, defaults.template)
|
||||
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
|
||||
.parse(process.argv)
|
||||
|
||||
|
@ -29,6 +31,7 @@ module.exports = async () => {
|
|||
license: program.license,
|
||||
repo: program.repo,
|
||||
manager: program.manager,
|
||||
template: program.template,
|
||||
skipPrompts: program.skipPrompts
|
||||
}
|
||||
|
||||
|
@ -47,20 +50,20 @@ module.exports = async () => {
|
|||
}
|
||||
|
||||
const params = await promptLibraryParams(opts)
|
||||
const lib = await createLibrary(params)
|
||||
const dest = await createLibrary(params)
|
||||
|
||||
console.log(`
|
||||
|
||||
Your module has been created at ${opts.dest}.
|
||||
|
||||
To get started, in one tab, run:
|
||||
$ cd ${opts.name} && ${opts.manager} start
|
||||
$ cd ${params.shortName} && ${params.manager} start
|
||||
|
||||
And in another tab, run the create-react-app devserver:
|
||||
$ cd ${opts.name}/example && ${opts.manager} start
|
||||
$ cd ${path.join(params.shortName, 'example')} && ${params.manager} start
|
||||
`)
|
||||
|
||||
return lib
|
||||
return dest
|
||||
}
|
||||
|
||||
module.exports()
|
||||
|
|
|
@ -64,12 +64,20 @@ module.exports = async (opts) => {
|
|||
message: 'Package Manager',
|
||||
choices: [ 'npm', 'yarn' ],
|
||||
default: opts.manager
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'template',
|
||||
message: 'Template',
|
||||
choices: [ 'default', 'typescript' ],
|
||||
default: opts.template
|
||||
}
|
||||
])
|
||||
|
||||
config.set('author', info.author)
|
||||
config.set('license', info.license)
|
||||
config.set('manager', info.manager)
|
||||
config.set('template', info.template)
|
||||
|
||||
return info
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue