Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@line/create-liff-app

Package Overview
Dependencies
Maintainers
5
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@line/create-liff-app - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

.github/CODEOWNERS

1

.eslintrc.js

@@ -16,3 +16,2 @@ module.exports = {

indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],

@@ -19,0 +18,0 @@ semi: ['error', 'always'],

@@ -24,20 +24,2 @@ /* Copyright 2022 LINE Corporation

const envPrefix: Record<string, string> = {
vanilla: 'VITE_',
'vanilla-ts': 'VITE_',
react: 'VITE_',
'react-ts': 'VITE_',
vue: 'VITE_',
'vue-ts': 'VITE_',
svelte: 'VITE_',
'svelte-ts': 'VITE_',
nextjs: 'NEXT_PUBLIC_',
'nextjs-ts': 'NEXT_PUBLIC_',
nuxtjs: '',
'nuxtjs-ts': ''
};
const envFileNameVariant: Record<string, string> = {
nextjs: '.env.local',
'nextjs-ts': '.env.local',
};
const rename: Record<string, string> = {

@@ -51,3 +33,3 @@ '.gitignore.default': '.gitignore'

);
prompt(questions).then(async (answers) => await createLiffApp(answers));
prompt(questions).then(async (answers) => await createLiffApp(answers));
}

@@ -58,30 +40,26 @@

export async function createLiffApp(answers: Answers) {
const { projectName, template, language, installNow, liffId } = answers;
const packageManager: PackageManager = installNow ? await inquirer.prompt({
type: 'list',
name: 'packageManager',
message: 'Which package manager do you want to use?',
choices: [
{
key: 'yarn',
value: 'yarn',
checked: true,
},
{
key: 'npm',
value: 'npm',
checked: false,
},
],
}).then(({ packageManager }) => packageManager as PackageManager) : 'npm';
const templateName = `${template}${language === 'JavaScript' ? '' : '-ts'}`;
const { projectName, template, language, liffId } = answers;
const templateConfig = templates[template] as TemplateOptions | undefined;
if (!templateConfig) {
throw new Error(`Invalid template name: ${template}`);
}
const isTypescript = language === 'TypeScript';
const cwd = process.cwd();
const root = path.join(cwd, projectName);
const packageManager = answers.packageManager as PackageManager;
const isYarn = packageManager === 'yarn';
try {
// create directory
fs.mkdirSync(root, { recursive: true });
if (templateConfig?.getCreateAppScript) {
// generate project using `create-app`
const script = templateConfig.getCreateAppScript({ isTypescript, isYarn, projectName });
console.log('\nGenerating liff app using `create-app`, this might take a while.\n');
await executeCreateAppScript(script);
} else {
// create directory
fs.mkdirSync(root, { recursive: true });
}
// copy files
const templateName = `${template}${isTypescript ? '-ts' : ''}`;
const templateDir = path.join(__dirname, '../templates', templateName);

@@ -95,21 +73,33 @@ const files = fs.readdirSync(templateDir);

// create package.json
const packageName = isValidPackageName(projectName) ? projectName : toValidPackageName(projectName);
const pkg = require(path.join(templateDir, 'package.json'));
pkg.name = packageName;
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(pkg, null, 2));
if (!templateConfig?.getCreateAppScript) {
// create package.json
const packageName = isValidPackageName(projectName) ? projectName : toValidPackageName(projectName);
const pkg = require(path.join(templateDir, 'package.json'));
pkg.name = packageName;
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(pkg, null, 2));
}
// create .env file
const content = `${envPrefix[templateName]}LIFF_ID=${liffId}`;
const envFileName = envFileNameVariant[templateName] || '.env';
const content = `${templateConfig.envPrefix}LIFF_ID=${liffId}`;
const envFileName = templateConfig?.envFileNameVariant || '.env';
fs.writeFileSync(path.join(root, envFileName), content);
// install
const isYarn = packageManager === 'yarn';
if (installNow) {
await install(root, isYarn);
const { dependencies, devDependencies, tsDevDependencies } = templateConfig;
if (isTypescript) devDependencies.push(...tsDevDependencies);
console.log('\nInstalling dependencies:');
dependencies.forEach((dependency) => console.log(`- ${chalk.blue(dependency)}`));
console.log();
await install({ root, isYarn, dependencies, isDev: false });
if (devDependencies.length) {
console.log('\nInstalling devDependencies:');
devDependencies.forEach((dependency) => console.log(`- ${chalk.blue(dependency)}`));
console.log();
await install({ root, isYarn, dependencies: devDependencies, isDev: true });
}
// Done
showDoneComments({ projectName, installNow, isYarn });
showDoneComments({ projectName, isYarn });
} catch(error) {

@@ -155,7 +145,47 @@ console.error(error);

function install(root: string, isYarn: boolean) {
function executeCreateAppScript(script: string[]) {
return new Promise<void>((resolve, reject) => {
try {
const [command, ...args] = script;
const child = spawn(command, args, {
stdio: 'inherit',
env: { ...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1' },
});
child.on('close', (code) => {
if (code !== 0) {
reject({ command: `${command} ${args.join(' ')}` });
return;
}
resolve();
});
} catch (error) {
reject(`Error occurred during installation: ${error}`);
}
});
}
function install({
root,
dependencies,
isYarn,
isDev,
}: {
root: string;
dependencies: string[];
isYarn: boolean;
isDev: boolean;
}) {
return new Promise<void>((resolve, reject) => {
try {
const command = isYarn ? 'yarnpkg' : 'npm';
const args = ['install', isYarn ? '--cwd' : '--prefix', root];
const args: string[] = [];
if (isYarn) {
args.push('add', '--exact', '--cwd', root);
if (isDev) args.push('--dev');
} else {
args.push('install', '--save-exact', '--prefix', root);
if (isDev) args.push('--save-dev');
}
args.push(...dependencies);
const child = spawn(command, args, {

@@ -178,12 +208,5 @@ stdio: 'inherit',

function showDoneComments({projectName, installNow, isYarn}: {projectName: string, installNow: boolean, isYarn: boolean}){
function showDoneComments({ projectName, isYarn }: { projectName: string; isYarn: boolean }) {
console.log('\n\nDone! Now run: \n');
console.log(` cd ${chalk.blue(projectName)}`);
if (!installNow) {
if (isYarn) {
console.log(' yarn');
} else {
console.log(' npm install');
}
}
if (isYarn) {

@@ -279,6 +302,101 @@ console.log(' yarn dev\n\n');

{
type: 'confirm',
name: 'installNow',
message: 'Do you want to install it now with package manager?'
type: 'list',
name: 'packageManager',
message: 'Which package manager do you want to use?',
choices: [
{
key: 'yarn',
value: 'yarn',
checked: true,
},
{
key: 'npm',
value: 'npm',
checked: false,
},
],
}
];
type TemplateOptions = {
envPrefix: string;
envFileNameVariant?: string;
dependencies: string[];
devDependencies: string[];
tsDevDependencies: string[];
getCreateAppScript?: (args: CreateAppScriptOptions) => string[];
};
type CreateAppScriptOptions = {
isTypescript: boolean;
isYarn: boolean;
projectName: string;
};
const templates: Record<string, TemplateOptions> = {
vanilla: {
envPrefix: 'VITE_',
dependencies: ['@line/liff'],
devDependencies: ['vite'],
tsDevDependencies: ['typescript'],
},
react: {
envPrefix: 'VITE_',
dependencies: ['@line/liff', 'react', 'react-dom'],
devDependencies: ['@vitejs/plugin-react', 'vite'],
tsDevDependencies: ['@types/react', '@types/react-dom', 'typescript'],
},
vue: {
envPrefix: 'VITE_',
dependencies: ['@line/liff', 'vue'],
devDependencies: ['@vitejs/plugin-vue', 'vite'],
tsDevDependencies: ['typescript', 'vue-tsc'],
},
svelte: {
envPrefix: 'VITE_',
dependencies: ['@line/liff'],
devDependencies: ['@sveltejs/vite-plugin-svelte', 'svelte', 'vite'],
tsDevDependencies: ['@tsconfig/svelte', 'svelte-check', 'svelte-preprocess', 'tslib', 'typescript'],
},
nextjs: {
envPrefix: 'NEXT_PUBLIC_',
envFileNameVariant: '.env.local',
dependencies: ['@line/liff'],
devDependencies: [],
tsDevDependencies: [],
getCreateAppScript: ({ isTypescript, isYarn, projectName }) => {
const script = [];
if (isYarn) {
script.push('yarnpkg', 'create', 'next-app');
} else {
script.push('npx', 'create-next-app', '--use-npm');
}
script.push(projectName);
if (isTypescript) script.push('--ts');
return script;
},
},
nuxtjs: {
envPrefix: '',
dependencies: ['@line/liff'],
devDependencies: [],
tsDevDependencies: [],
getCreateAppScript: ({ isTypescript, isYarn, projectName }) => {
const answers = {
name: projectName,
pm: isYarn ? 'yarn' : 'npm',
language: isTypescript ? 'ts' : 'js',
features: ['axios'],
linter: ['eslint'],
ui: 'none',
test: 'none',
mode: 'universal',
target: 'server',
devTools: 'none',
vcs: 'none',
};
const script = ['npx', 'create-nuxt-app', projectName, '--answers', JSON.stringify(answers)];
return script;
},
},
};

@@ -27,16 +27,2 @@ "use strict";

const inquirer_1 = __importDefault(require("inquirer"));
const envPrefix = {
vanilla: 'VITE_',
'vanilla-ts': 'VITE_',
react: 'VITE_',
'react-ts': 'VITE_',
vue: 'VITE_',
'vue-ts': 'VITE_',
svelte: 'VITE_',
'svelte-ts': 'VITE_',
nextjs: 'NEXT_PUBLIC_',
'nextjs-ts': 'NEXT_PUBLIC_',
nuxtjs: '',
'nuxtjs-ts': ''
};
const rename = {

@@ -51,27 +37,25 @@ '.gitignore.default': '.gitignore'

async function createLiffApp(answers) {
const { projectName, template, language, installNow, liffId } = answers;
const packageManager = installNow ? await inquirer_1.default.prompt({
type: 'list',
name: 'packageManager',
message: 'Which package manager do you want to use?',
choices: [
{
key: 'yarn',
value: 'yarn',
checked: true,
},
{
key: 'npm',
value: 'npm',
checked: false,
},
],
}).then(({ packageManager }) => packageManager) : 'npm';
const templateName = `${template}${language === 'JavaScript' ? '' : '-ts'}`;
const { projectName, template, language, liffId } = answers;
const templateConfig = templates[template];
if (!templateConfig) {
throw new Error(`Invalid template name: ${template}`);
}
const isTypescript = language === 'TypeScript';
const cwd = process.cwd();
const root = path_1.default.join(cwd, projectName);
const packageManager = answers.packageManager;
const isYarn = packageManager === 'yarn';
try {
// create directory
fs_1.default.mkdirSync(root, { recursive: true });
if (templateConfig?.getCreateAppScript) {
// generate project using `create-app`
const script = templateConfig.getCreateAppScript({ isTypescript, isYarn, projectName });
console.log('\nGenerating liff app using `create-app`, this might take a while.\n');
await executeCreateAppScript(script);
}
else {
// create directory
fs_1.default.mkdirSync(root, { recursive: true });
}
// copy files
const templateName = `${template}${isTypescript ? '-ts' : ''}`;
const templateDir = path_1.default.join(__dirname, '../templates', templateName);

@@ -84,17 +68,29 @@ const files = fs_1.default.readdirSync(templateDir);

}
// create package.json
const packageName = isValidPackageName(projectName) ? projectName : toValidPackageName(projectName);
const pkg = require(path_1.default.join(templateDir, 'package.json'));
pkg.name = packageName;
fs_1.default.writeFileSync(path_1.default.join(root, 'package.json'), JSON.stringify(pkg, null, 2));
if (!templateConfig?.getCreateAppScript) {
// create package.json
const packageName = isValidPackageName(projectName) ? projectName : toValidPackageName(projectName);
const pkg = require(path_1.default.join(templateDir, 'package.json'));
pkg.name = packageName;
fs_1.default.writeFileSync(path_1.default.join(root, 'package.json'), JSON.stringify(pkg, null, 2));
}
// create .env file
const content = `${envPrefix[templateName]}LIFF_ID=${liffId}`;
fs_1.default.writeFileSync(path_1.default.join(root, '.env'), content);
const content = `${templateConfig.envPrefix}LIFF_ID=${liffId}`;
const envFileName = templateConfig?.envFileNameVariant || '.env';
fs_1.default.writeFileSync(path_1.default.join(root, envFileName), content);
// install
const isYarn = packageManager === 'yarn';
if (installNow) {
await install(root, isYarn);
const { dependencies, devDependencies, tsDevDependencies } = templateConfig;
if (isTypescript)
devDependencies.push(...tsDevDependencies);
console.log('\nInstalling dependencies:');
dependencies.forEach((dependency) => console.log(`- ${chalk_1.default.blue(dependency)}`));
console.log();
await install({ root, isYarn, dependencies, isDev: false });
if (devDependencies.length) {
console.log('\nInstalling devDependencies:');
devDependencies.forEach((dependency) => console.log(`- ${chalk_1.default.blue(dependency)}`));
console.log();
await install({ root, isYarn, dependencies: devDependencies, isDev: true });
}
// Done
showDoneComments({ projectName, installNow, isYarn });
showDoneComments({ projectName, isYarn });
}

@@ -136,7 +132,39 @@ catch (error) {

}
function install(root, isYarn) {
function executeCreateAppScript(script) {
return new Promise((resolve, reject) => {
try {
const [command, ...args] = script;
const child = (0, cross_spawn_1.default)(command, args, {
stdio: 'inherit',
env: { ...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1' },
});
child.on('close', (code) => {
if (code !== 0) {
reject({ command: `${command} ${args.join(' ')}` });
return;
}
resolve();
});
}
catch (error) {
reject(`Error occurred during installation: ${error}`);
}
});
}
function install({ root, dependencies, isYarn, isDev, }) {
return new Promise((resolve, reject) => {
try {
const command = isYarn ? 'yarnpkg' : 'npm';
const args = ['install', isYarn ? '--cwd' : '--prefix', root];
const args = [];
if (isYarn) {
args.push('add', '--exact', '--cwd', root);
if (isDev)
args.push('--dev');
}
else {
args.push('install', '--save-exact', '--prefix', root);
if (isDev)
args.push('--save-dev');
}
args.push(...dependencies);
const child = (0, cross_spawn_1.default)(command, args, {

@@ -159,13 +187,5 @@ stdio: 'inherit',

}
function showDoneComments({ projectName, installNow, isYarn }) {
function showDoneComments({ projectName, isYarn }) {
console.log('\n\nDone! Now run: \n');
console.log(` cd ${chalk_1.default.blue(projectName)}`);
if (!installNow) {
if (isYarn) {
console.log(' yarn');
}
else {
console.log(' npm install');
}
}
if (isYarn) {

@@ -260,6 +280,87 @@ console.log(' yarn dev\n\n');

{
type: 'confirm',
name: 'installNow',
message: 'Do you want to install it now with package manager?'
type: 'list',
name: 'packageManager',
message: 'Which package manager do you want to use?',
choices: [
{
key: 'yarn',
value: 'yarn',
checked: true,
},
{
key: 'npm',
value: 'npm',
checked: false,
},
],
}
];
const templates = {
vanilla: {
envPrefix: 'VITE_',
dependencies: ['@line/liff'],
devDependencies: ['vite'],
tsDevDependencies: ['typescript'],
},
react: {
envPrefix: 'VITE_',
dependencies: ['@line/liff', 'react', 'react-dom'],
devDependencies: ['@vitejs/plugin-react', 'vite'],
tsDevDependencies: ['@types/react', '@types/react-dom', 'typescript'],
},
vue: {
envPrefix: 'VITE_',
dependencies: ['@line/liff', 'vue'],
devDependencies: ['@vitejs/plugin-vue', 'vite'],
tsDevDependencies: ['typescript', 'vue-tsc'],
},
svelte: {
envPrefix: 'VITE_',
dependencies: ['@line/liff'],
devDependencies: ['@sveltejs/vite-plugin-svelte', 'svelte', 'vite'],
tsDevDependencies: ['@tsconfig/svelte', 'svelte-check', 'svelte-preprocess', 'tslib', 'typescript'],
},
nextjs: {
envPrefix: 'NEXT_PUBLIC_',
envFileNameVariant: '.env.local',
dependencies: ['@line/liff'],
devDependencies: [],
tsDevDependencies: [],
getCreateAppScript: ({ isTypescript, isYarn, projectName }) => {
const script = [];
if (isYarn) {
script.push('yarnpkg', 'create', 'next-app');
}
else {
script.push('npx', 'create-next-app', '--use-npm');
}
script.push(projectName);
if (isTypescript)
script.push('--ts');
return script;
},
},
nuxtjs: {
envPrefix: '',
dependencies: ['@line/liff'],
devDependencies: [],
tsDevDependencies: [],
getCreateAppScript: ({ isTypescript, isYarn, projectName }) => {
const answers = {
name: projectName,
pm: isYarn ? 'yarn' : 'npm',
language: isTypescript ? 'ts' : 'js',
features: ['axios'],
linter: ['eslint'],
ui: 'none',
test: 'none',
mode: 'universal',
target: 'server',
devTools: 'none',
vcs: 'none',
};
const script = ['npx', 'create-nuxt-app', projectName, '--answers', JSON.stringify(answers)];
return script;
},
},
};

@@ -14,2 +14,4 @@ "use strict";

const ENTER = '\x0D';
// Increase timeout
jest.setTimeout(1000 * 60 * (process.env.RUNNER_OS === 'macOS' ? 10 : 5));
const rename = {

@@ -19,3 +21,5 @@ '.gitignore.default': '.gitignore'

const generatedFiles = [
'.env'
'.env',
'node_modules',
'yarn.lock'
];

@@ -52,12 +56,8 @@ function removeProject() {

});
const commands = {
vanilla: [projectName, ENTER, ENTER, ENTER, ENTER, ENTER],
};
describe('create-liff-app', () => {
it('files properly created', async () => {
const result = await installProject([
projectName,
ENTER,
ENTER,
ENTER,
ENTER,
'n'
]);
const result = await installProject(commands.vanilla);
const templateFiles = fs_1.default.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f);

@@ -64,0 +64,0 @@ const expectedFiles = templateFiles.concat(generatedFiles);

{
"name": "@line/create-liff-app",
"version": "1.0.4",
"version": "1.0.5",
"description": "Start developing LIFF application with a simple CLI command.",

@@ -16,4 +16,3 @@ "main": "./dist/index.js",

"lint:eslint": "eslint '**/*.{ts,js}'",
"fix:eslint": "yarn lint:eslint --fix",
"update:liff-versions": "node scripts/updateLiffVersions.js"
"fix:eslint": "yarn lint:eslint --fix"
},

@@ -20,0 +19,0 @@ "keywords": [

@@ -8,15 +8,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@vitejs/plugin-react": "^1.0.7",
"typescript": "^4.4.4",
"vite": "^2.7.2"
}
}

@@ -8,12 +8,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.7",
"vite": "^2.7.2"
}
}

@@ -10,16 +10,3 @@ {

"check": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@line/liff": "2.20.1"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"@tsconfig/svelte": "^2.0.1",
"svelte": "^3.44.0",
"svelte-check": "^2.2.7",
"svelte-preprocess": "^4.9.8",
"tslib": "^2.3.1",
"typescript": "^4.4.4",
"vite": "^2.7.2"
}
}

@@ -9,11 +9,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"svelte": "^3.44.0",
"vite": "^2.7.2"
}
}

@@ -8,10 +8,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1"
},
"devDependencies": {
"typescript": "^4.4.4",
"vite": "^2.7.2"
}
}

@@ -8,9 +8,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1"
},
"devDependencies": {
"vite": "^2.7.2"
}
}

@@ -8,13 +8,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1",
"vue": "^3.2.25"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.0",
"typescript": "^4.4.4",
"vite": "^2.7.2",
"vue-tsc": "^0.29.8"
}
}

@@ -8,11 +8,3 @@ {

"preview": "vite preview"
},
"dependencies": {
"@line/liff": "2.20.1",
"vue": "^3.2.25"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.0",
"vite": "^2.7.2"
}
}

@@ -11,2 +11,5 @@ import fs from'fs';

// Increase timeout
jest.setTimeout(1000 * 60 * (process.env.RUNNER_OS === 'macOS' ? 10 : 5));
const rename: Record<string, string> = {

@@ -16,3 +19,5 @@ '.gitignore.default': '.gitignore'

const generatedFiles = [
'.env'
'.env',
'node_modules',
'yarn.lock'
];

@@ -56,13 +61,9 @@

const commands = {
vanilla: [projectName, ENTER, ENTER, ENTER, ENTER, ENTER],
};
describe('create-liff-app', () => {
it('files properly created', async () => {
const result = await installProject([
projectName,
ENTER,
ENTER,
ENTER,
ENTER,
'n'
]);
const result = await installProject(commands.vanilla);
const templateFiles = fs.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f);

@@ -69,0 +70,0 @@ const expectedFiles = templateFiles.concat(generatedFiles);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc