@line/create-liff-app
Advanced tools
Comparing version 1.0.5 to 1.1.0
@@ -28,7 +28,7 @@ /* Copyright 2022 LINE Corporation | ||
export function init() { | ||
export function init(answers: Answers = {}) { | ||
console.log( | ||
`${chalk.greenBright('Welcome')} to the ${chalk.cyan('Create LIFF App')}` | ||
); | ||
prompt(questions).then(async (answers) => await createLiffApp(answers)); | ||
prompt(questions, answers).then(async (answers) => await createLiffApp(answers)); | ||
} | ||
@@ -397,1 +397,2 @@ | ||
}; | ||
export const templateNames = Object.keys(templates); |
@@ -20,3 +20,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLiffApp = exports.init = void 0; | ||
exports.templateNames = exports.createLiffApp = exports.init = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -31,5 +31,5 @@ const path_1 = __importDefault(require("path")); | ||
}; | ||
function init() { | ||
function init(answers = {}) { | ||
console.log(`${chalk_1.default.greenBright('Welcome')} to the ${chalk_1.default.cyan('Create LIFF App')}`); | ||
prompt(questions).then(async (answers) => await createLiffApp(answers)); | ||
prompt(questions, answers).then(async (answers) => await createLiffApp(answers)); | ||
} | ||
@@ -363,1 +363,2 @@ exports.init = init; | ||
}; | ||
exports.templateNames = Object.keys(templates); |
@@ -17,4 +17,47 @@ #!/usr/bin/env node | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const commander_1 = require("commander"); | ||
const package_json_1 = __importDefault(require("./package.json")); | ||
const create_liff_app_1 = require("./create-liff-app"); | ||
(0, create_liff_app_1.init)(); | ||
const answers = parseFlags(); | ||
(0, create_liff_app_1.init)(answers); | ||
function parseFlags() { | ||
const answers = {}; | ||
new commander_1.Command(package_json_1.default.name) | ||
.version(package_json_1.default.version, '-v, --version') | ||
.usage('[project name] [options]') | ||
.arguments('[projectName]') | ||
.addOption(new commander_1.Option('-t, --template <template>', 'Choose a template to bootstrap the app with').choices(create_liff_app_1.templateNames)) | ||
.option('-l, --liffid <liff id>', 'Liff id. For more information, please visit https://developers.line.biz/ja/docs/liff/getting-started/') | ||
.option('--js, --javascript', 'Initialize as a JavaScript project') | ||
.option('--ts, --typescript', 'Initialize as a TypeScript project') | ||
.option('--npm, --use-npm', 'Bootstrap the app using npm') | ||
.option('--yarn, --use-yarn', 'Bootstrap the app using yarn') | ||
.action((projectName, options) => { | ||
const { template, liffid, javascript, typescript, useNpm, useYarn } = options; | ||
// projectName | ||
if (typeof projectName === 'string') | ||
answers.projectName = projectName; | ||
// template | ||
if (typeof template === 'string') | ||
answers.template = template; | ||
// liffId | ||
if (typeof liffid === 'string') | ||
answers.liffId = liffid; | ||
// language | ||
if (javascript) | ||
answers.language = 'JavaScript'; | ||
if (typescript) | ||
answers.language = 'TypeScript'; | ||
// packageManager | ||
if (useNpm) | ||
answers.packageManager = 'npm'; | ||
if (useYarn) | ||
answers.packageManager = 'yarn'; | ||
}) | ||
.parse(process.argv); | ||
return answers; | ||
} |
@@ -33,4 +33,4 @@ "use strict"; | ||
} | ||
async function installProject(inputs) { | ||
const result = (0, execa_1.default)('node', [cliPath], { cwd: __dirname }); | ||
async function installProject({ args = [], inputs = [] }) { | ||
const result = (0, execa_1.default)('node', [cliPath, ...args], { cwd: __dirname }); | ||
result.stdout?.on('data', chunk => process.stdout.write(chunk.toString('utf8'))); | ||
@@ -49,6 +49,6 @@ for (const input of inputs) { | ||
} | ||
beforeAll(() => { | ||
beforeEach(() => { | ||
removeProject(); | ||
}); | ||
afterAll(async () => { | ||
afterEach(async () => { | ||
removeProject(); | ||
@@ -59,5 +59,8 @@ }); | ||
}; | ||
const flags = { | ||
vanilla: [projectName, '-t', 'vanilla', '-l', 'id', '--js', '--use-yarn'], | ||
}; | ||
describe('create-liff-app', () => { | ||
it('files properly created', async () => { | ||
const result = await installProject(commands.vanilla); | ||
const result = await installProject({ inputs: commands.vanilla }); | ||
const templateFiles = fs_1.default.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f); | ||
@@ -68,2 +71,9 @@ const expectedFiles = templateFiles.concat(generatedFiles); | ||
}); | ||
it('creates app using only flags', async () => { | ||
const result = await installProject({ args: flags.vanilla }); | ||
const templateFiles = fs_1.default.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f); | ||
const expectedFiles = templateFiles.concat(generatedFiles); | ||
expect(result.files.sort()).toEqual(expectedFiles.sort()); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); |
51
index.ts
@@ -17,4 +17,51 @@ #!/usr/bin/env node | ||
import { init } from './create-liff-app'; | ||
import { Command, Option } from 'commander'; | ||
import packageJson from './package.json'; | ||
import { init, templateNames } from './create-liff-app'; | ||
import type { Answers } from 'inquirer'; | ||
init(); | ||
const answers = parseFlags(); | ||
init(answers); | ||
function parseFlags() { | ||
const answers: Answers = {}; | ||
new Command(packageJson.name) | ||
.version(packageJson.version, '-v, --version') | ||
.usage('[project name] [options]') | ||
.arguments('[projectName]') | ||
.addOption( | ||
new Option('-t, --template <template>', 'Choose a template to bootstrap the app with').choices(templateNames) | ||
) | ||
.option( | ||
'-l, --liffid <liff id>', | ||
'Liff id. For more information, please visit https://developers.line.biz/ja/docs/liff/getting-started/' | ||
) | ||
.option('--js, --javascript', 'Initialize as a JavaScript project') | ||
.option('--ts, --typescript', 'Initialize as a TypeScript project') | ||
.option('--npm, --use-npm', 'Bootstrap the app using npm') | ||
.option('--yarn, --use-yarn', 'Bootstrap the app using yarn') | ||
.action((projectName, options) => { | ||
const { template, liffid, javascript, typescript, useNpm, useYarn } = options; | ||
// projectName | ||
if (typeof projectName === 'string') answers.projectName = projectName; | ||
// template | ||
if (typeof template === 'string') answers.template = template; | ||
// liffId | ||
if (typeof liffid === 'string') answers.liffId = liffid; | ||
// language | ||
if (javascript) answers.language = 'JavaScript'; | ||
if (typescript) answers.language = 'TypeScript'; | ||
// packageManager | ||
if (useNpm) answers.packageManager = 'npm'; | ||
if (useYarn) answers.packageManager = 'yarn'; | ||
}) | ||
.parse(process.argv); | ||
return answers; | ||
} |
{ | ||
"name": "@line/create-liff-app", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Start developing LIFF application with a simple CLI command.", | ||
"main": "./dist/index.js", | ||
"repository": { | ||
@@ -32,2 +31,3 @@ "type": "git", | ||
"chalk": "^4.1.2", | ||
"commander": "^9.3.0", | ||
"cross-spawn": "^7.0.3", | ||
@@ -34,0 +34,0 @@ "inquirer": "^8.1.5", |
@@ -13,2 +13,3 @@ # @line/create-liff-app | ||
- [Installation](#installation) | ||
- [Options](#options) | ||
- [License](#license) | ||
@@ -36,8 +37,25 @@ | ||
Run npm command like: | ||
Run npm command like: | ||
```bash | ||
npx @line/create-liff-app | ||
``` | ||
$ npx @line/create-liff-app | ||
To create a new app in a specific folder, you can send a name as an argument. | ||
```bash | ||
npx @line/create-liff-app my-app | ||
``` | ||
### Options | ||
`create-liff-app` comes with the following options: | ||
- **-t, --template <template>** - A template to bootstrap the app with. (available templates: "vanilla", "react", "vue", "svelte", "nextjs", "nuxtjs") | ||
- **-l, --liffid <liff id>** - Liff id. For more information, please visit <https://developers.line.biz/ja/docs/liff/getting-started/> | ||
- **--js, --javascript** - Initialize as a JavaScript project | ||
- **--ts, --typescript** - Initialize as a TypeScript project | ||
- **--npm, --use-npm** - Bootstrap the app using npm | ||
- **--yarn, --use-yarn** - Bootstrap the app using yarn | ||
- **-v, --version** - output the version number | ||
- **-h, --help** - display help for command | ||
## [License](https://github.com/line/create-liff-app/blob/master/LINCENSE.txt) | ||
@@ -44,0 +62,0 @@ |
// This function is executed before instantiating the app | ||
// only in client-side. | ||
// document: https://nuxtjs.org/docs/2.x/directory-structure/plugins | ||
// document: https://nuxtjs.org/docs/2.x/directory-structure/plugins | ||
// import NPM version LIFF JS SDK | ||
import liff from '@line/liff'; | ||
import { Plugin } from '@nuxt/types'; | ||
import liff from '@line/liff' | ||
import { Plugin } from '@nuxt/types' | ||
const liffPlugin: Plugin = (_, inject) => { | ||
// You can access liff object as this.$liff by inject() | ||
inject('liff', liff); | ||
inject('liff', liff) | ||
// execute liff.init() | ||
const initResult = liff.init({liffId: process.env.LIFF_ID!}) | ||
const initResult = liff.init({ liffId: process.env.LIFF_ID! }) | ||
.then(() => { | ||
console.log('LIFF init succeeded.'); | ||
console.log('LIFF init succeeded.') | ||
}) | ||
.catch((error: Error) => { | ||
console.log('LIFF init failed.'); | ||
return Promise.reject(error); | ||
}); | ||
console.log('LIFF init failed.') | ||
return Promise.reject(error) | ||
}) | ||
// You can access liff.init()'s return value (Promise object) | ||
// as this.$liffInit() by inject() | ||
inject('liffInit', initResult); | ||
inject('liffInit', initResult) | ||
} | ||
export default liffPlugin; | ||
export default liffPlugin |
// This function is executed before instantiating the app | ||
// only in client-side. | ||
// document: https://nuxtjs.org/docs/2.x/directory-structure/plugins | ||
// document: https://nuxtjs.org/docs/2.x/directory-structure/plugins | ||
// import NPM version LIFF JS SDK | ||
import liff from '@line/liff'; | ||
import liff from '@line/liff' | ||
export default (_, inject) => { | ||
// You can access liff object as this.$liff by inject() | ||
inject('liff', liff); | ||
inject('liff', liff) | ||
// execute liff.init() | ||
const initResult = liff.init({liffId: process.env.LIFF_ID}) | ||
const initResult = liff.init({ liffId: process.env.LIFF_ID }) | ||
.then(() => { | ||
console.log('LIFF init succeeded.'); | ||
console.log('LIFF init succeeded.') | ||
}) | ||
.catch(error => { | ||
console.log('LIFF init failed.'); | ||
return Promise.reject(error); | ||
}); | ||
.catch((error) => { | ||
console.log('LIFF init failed.') | ||
return Promise.reject(error) | ||
}) | ||
// You can access liff.init()'s return value (Promise object) | ||
// as this.$liffInit() by inject() | ||
inject('liffInit', initResult); | ||
inject('liffInit', initResult) | ||
} |
@@ -34,4 +34,4 @@ import fs from'fs'; | ||
async function installProject(inputs: string[]): Promise<{ files: string[], exitCode: number | null }>{ | ||
const result = execa('node', [cliPath], { cwd: __dirname }); | ||
async function installProject({ args = [] as string[], inputs = [] as string[] }) { | ||
const result = execa('node', [cliPath, ...args], { cwd: __dirname }); | ||
result.stdout?.on('data', chunk => | ||
@@ -53,6 +53,6 @@ process.stdout.write(chunk.toString('utf8')) | ||
beforeAll(() => { | ||
beforeEach(() => { | ||
removeProject(); | ||
}); | ||
afterAll(async () => { | ||
afterEach(async () => { | ||
removeProject(); | ||
@@ -64,6 +64,9 @@ }); | ||
}; | ||
const flags = { | ||
vanilla: [projectName, '-t', 'vanilla', '-l', 'id', '--js', '--use-yarn'], | ||
}; | ||
describe('create-liff-app', () => { | ||
it('files properly created', async () => { | ||
const result = await installProject(commands.vanilla); | ||
const result = await installProject({ inputs: commands.vanilla }); | ||
const templateFiles = fs.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f); | ||
@@ -74,2 +77,10 @@ const expectedFiles = templateFiles.concat(generatedFiles); | ||
}); | ||
it('creates app using only flags', async () => { | ||
const result = await installProject({ args: flags.vanilla }); | ||
const templateFiles = fs.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f); | ||
const expectedFiles = templateFiles.concat(generatedFiles); | ||
expect(result.files.sort()).toEqual(expectedFiles.sort()); | ||
expect(result.exitCode).toBe(0); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113342
115
1827
65
5
+ Addedcommander@^9.3.0
+ Addedcommander@9.5.0(transitive)