From 7e037c528f1d2650a9d418a043322bb06d4bf474 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 11 Aug 2020 19:10:15 +0530 Subject: [PATCH] chore: remove stale templates --- .travis.yml | 3 ++ src/commands/deploy/heroku.js | 31 +++++++++----- src/commands/deploy/surge.js | 12 ++++-- src/templates/routes/FacebookRoutes.js | 36 ---------------- src/templates/routes/GoogleRoutes.js | 39 ------------------ src/templates/routes/TwitterRoutes.js | 36 ---------------- src/templates/routes/index_with_passport.js | 25 ----------- .../routes/index_with_social_media_auth.js | 41 ------------------- 8 files changed, 32 insertions(+), 191 deletions(-) delete mode 100644 src/templates/routes/FacebookRoutes.js delete mode 100644 src/templates/routes/GoogleRoutes.js delete mode 100644 src/templates/routes/TwitterRoutes.js delete mode 100644 src/templates/routes/index_with_passport.js delete mode 100644 src/templates/routes/index_with_social_media_auth.js diff --git a/.travis.yml b/.travis.yml index 9ef528d5e..23cd2af5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: node_js +os: + - linux + - osx node_js: - 13 - 12 diff --git a/src/commands/deploy/heroku.js b/src/commands/deploy/heroku.js index 7645ee25e..5bafeabd8 100644 --- a/src/commands/deploy/heroku.js +++ b/src/commands/deploy/heroku.js @@ -4,6 +4,7 @@ import chalk from 'chalk'; import execa from 'execa'; import fs from 'fs'; import inquirer from 'inquirer'; +import path from 'path'; import appData from '../../utils/projectConfig'; import { validateInput } from '../../utils/validate'; @@ -92,12 +93,12 @@ const deployToHeroku = async (templateDir) => { const projectConfig = appData(); const { template } = projectConfig; - if (!fs.existsSync(`./${templateDir}/.git`)) { + if (!fs.existsSync(path.join(templateDir, '.git'))) { await execa.shell('git init', { cwd: templateDir }); - const fileContent = fs.existsSync('./server/.env') + const fileContent = fs.existsSync(path.join('server', '.env')) ? 'node_modules\n.env' : 'node_modules'; - fs.writeFileSync(`./${templateDir}/.gitignore`, fileContent); + fs.writeFileSync(path.join(templateDir, '.gitignore'), fileContent); } else { const { stdout } = await execa.shell('git status', { cwd: templateDir }); if (stdout.includes('nothing to commit')) { @@ -117,7 +118,10 @@ const deployToHeroku = async (templateDir) => { } // It depends on a DBAAS - if (templateDir === 'server' && fs.existsSync('./server/models')) { + if ( + templateDir === 'server' && + fs.existsSync(path.join('server', 'models')) + ) { await setConfigVar('DB_URL', templateDir); } @@ -130,8 +134,9 @@ const deployToHeroku = async (templateDir) => { await setConfigVar('NODE_ENV', templateDir, 'production'); // Create Procfile - if (!fs.existsSync('./client/Procfile')) { - fs.writeFileSync('./client/Procfile', 'web: nuxt start'); + const procFilePath = path.join('client', 'Procfile'); + if (!fs.existsSync(procFilePath)) { + fs.writeFileSync(procFilePath, 'web: nuxt start'); } } else { const staticConfig = { @@ -142,9 +147,10 @@ const deployToHeroku = async (templateDir) => { }, }; - if (!fs.existsSync('./client/static.json')) { + const staticConfigPath = path.join('client', 'static.json'); + if (!fs.existsSync(staticConfigPath)) { fs.writeFileSync( - './client/static.json', + staticConfigPath, JSON.stringify(staticConfig, null, 2), ); } @@ -159,7 +165,9 @@ const deployToHeroku = async (templateDir) => { 'app.listen(port);', ]; - let pkgJson = JSON.parse(fs.readFileSync('./client/package.json')); + let pkgJson = JSON.parse( + fs.readFileSync(path.join('client', 'package.json')), + ); const buildCmd = 'npm run build'; const postInstallScript = `if test \"$NODE_ENV\" = \"production\" ; then ${buildCmd} ; fi `; // eslint-disable-line pkgJson = { @@ -171,8 +179,9 @@ const deployToHeroku = async (templateDir) => { }, }; - if (!fs.existsSync('./client/server.js')) { - fs.writeFileSync('./client/server.js', starterSource.join('\n')); + const serverFilePath = path.join('client', 'server.js'); + if (!fs.existsSync(serverFilePath)) { + fs.writeFileSync(serverFilePath, starterSource.join('\n')); pkgJson.scripts['preinstall'] = 'npm install --save express serve-static'; fs.writeFileSync( diff --git a/src/commands/deploy/surge.js b/src/commands/deploy/surge.js index b793e784c..161f42393 100644 --- a/src/commands/deploy/surge.js +++ b/src/commands/deploy/surge.js @@ -2,6 +2,7 @@ import execa from 'execa'; import fs from 'fs'; +import path from 'path'; import appData from '../../utils/projectConfig'; import exec from '../../utils/exec'; @@ -16,10 +17,11 @@ const deployToSurge = async () => { await validateInstallation('surge --help'); console.log(); - const { template } = appData(); + const projectConfig = appData(); + const { template, isConfigured } = projectConfig; const cmd = template === 'Nuxt.js' ? 'generate' : 'build'; - if (!fs.existsSync('./client/node_modules')) { + if (!isConfigured.client) { await exec( `npm install`, 'Installing dependencies', @@ -28,6 +30,10 @@ const deployToSurge = async () => { cwd: 'client', }, ); + + // Update .mevnrc + projectConfig.isConfigured.client = true; + fs.writeFileSync('.mevnrc', JSON.stringify(projectConfig, null, 2)); } // Create a production build with npm run build @@ -36,7 +42,7 @@ const deployToSurge = async () => { }); // Fire up the surge CLI - await execa('surge', { cwd: 'client/dist', stdio: 'inherit' }); + await execa('surge', { cwd: path.join('client', 'dist'), stdio: 'inherit' }); }; module.exports = deployToSurge; diff --git a/src/templates/routes/FacebookRoutes.js b/src/templates/routes/FacebookRoutes.js deleted file mode 100644 index 383ac04ce..000000000 --- a/src/templates/routes/FacebookRoutes.js +++ /dev/null @@ -1,36 +0,0 @@ -import passport from 'passport'; -import { Strategy as FacebookStrategy } from 'passport-facebook'; -import UserAuth from '../models/user_schema'; - -passport.use( - new FacebookStrategy( - { - clientID: 'FACEBOOK_APP_ID', - clientSecret: 'FACEBOOK_APP_SECRET', - callbackURL: 'http://www.example.com/auth/facebook/callback', - }, - (accessToken, refreshToken, profile, done) => { - UserAuth.findOrCreate({ facebookId: profile.id }, (err, user) => { - if (err) { - return done(err); - } - done(null, user); - }); - }, - ), -); - -let FacebookRoutes = { - authenticate: () => { - return passport.authenticate('facebook'); - }, - - callback: () => { - return passport.authenticate('facebook', { - successRedirect: '/', - failureRedirect: '/auth/failed', - }); - }, -}; - -export default FacebookRoutes; diff --git a/src/templates/routes/GoogleRoutes.js b/src/templates/routes/GoogleRoutes.js deleted file mode 100644 index ab2d63e5c..000000000 --- a/src/templates/routes/GoogleRoutes.js +++ /dev/null @@ -1,39 +0,0 @@ -import passport from 'passport'; -import { OAuthStrategy as GoogleStrategy } from 'passport-google-oauth'; -import UserAuth from '../models/user_schema'; - -// Use the GoogleStrategy within Passport. -// Strategies in passport require a `verify` function, which accept -// credentials (in this case, a token, tokenSecret, and Google profile), and -// invoke a callback with a user object. -passport.use( - new GoogleStrategy( - { - consumerKey: 'GOOGLE_CONSUMER_KEY', - consumerSecret: 'GOOGLE_CONSUMER_SECRET', - callbackURL: 'http://www.example.com/auth/google/callback', - }, - (token, tokenSecret, profile, done) => { - UserAuth.findOrCreate({ googleId: profile.id }, (err, user) => { - return done(err, user); - }); - }, - ), -); - -let GoogleRoutes = { - authenticate: () => { - return passport.authenticate('google', { - scope: 'https://www.google.com/m8/feeds', - }); - }, - - callback: () => { - return passport.authenticate('google', { - successRedirect: '/', - failureRedirect: '/auth/failed', - }); - }, -}; - -export default GoogleRoutes; diff --git a/src/templates/routes/TwitterRoutes.js b/src/templates/routes/TwitterRoutes.js deleted file mode 100644 index 192784e24..000000000 --- a/src/templates/routes/TwitterRoutes.js +++ /dev/null @@ -1,36 +0,0 @@ -import passport from 'passport'; -import { Strategy as TwitterStrategy } from 'passport-twitter'; -import UserAuth from '../models/user_schema'; - -passport.use( - new TwitterStrategy( - { - consumerKey: 'TWITTER_CONSUMER_KEY', - consumerSecret: 'TWITTER_CONSUMER_SECRET', - callbackURL: 'http://www.example.com/auth/twitter/callback', - }, - (token, tokenSecret, profile, done) => { - UserAuth.findOrCreate({ twitterId: profile.id }, (err, user) => { - if (err) { - return done(err); - } - done(null, user); - }); - }, - ), -); - -let TwitterRoutes = { - authenticate: () => { - return passport.authenticate('twitter'); - }, - - callback: () => { - return passport.authenticate('twitter', { - successRedirect: '/', - failureRedirect: '/auth/failed', - }); - }, -}; - -export default TwitterRoutes; diff --git a/src/templates/routes/index_with_passport.js b/src/templates/routes/index_with_passport.js deleted file mode 100644 index db4877fca..000000000 --- a/src/templates/routes/index_with_passport.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -import express from 'express'; -import passport from 'passport'; - -import { - createData, - readData, - updateData, - deleteData, -} from '../controllers/user_controller'; - -const router = express.Router(); - -router.configure(() => { - router.use(passport.initialize()); -}); - -router.post('/login', passport.authenticate('local'), createData); - -router.get('/enter_api', readData); -router.put('/enter_api/:id', updateData); -router.delete('/enter_api/:id', deleteData); - -module.exports = router; diff --git a/src/templates/routes/index_with_social_media_auth.js b/src/templates/routes/index_with_social_media_auth.js deleted file mode 100644 index 8ff65f757..000000000 --- a/src/templates/routes/index_with_social_media_auth.js +++ /dev/null @@ -1,41 +0,0 @@ -import express from 'express'; -import passport from 'passport'; -import FacebookRoutes from './FacebookRoutes'; -import TwitterRoutes from './TwitterRoutes'; -import GoogleRoutes from './GoogleRoutes'; - -import { - createData, - readData, - updateData, - deleteData, -} from '../controllers/user_controller'; - -const router = express.Router(); - -router.configure(() => { - router.use(passport.initialize()); -}); - -router.post('/login', passport.authenticate('local'), createData); - -router.get('/enter_api', readData); -router.put('/enter_api/:id', updateData); -router.delete('/enter_api/:id', deleteData); - -// Facebook authentication -// For more info check out http://www.passportjs.org/docs/facebook/ -router.get('/auth/facebook', FacebookRoutes.authenticate()); -router.get('/auth/facebook/callback', FacebookRoutes.callback()); - -// Twitter authentication -// For more info check out http://www.passportjs.org/docs/twitter/ -router.get('/auth/twitter', TwitterRoutes.authenticate()); -router.get('/auth/twitter/callback', TwitterRoutes.callback()); - -// Google authentication -// For more info check out http://www.passportjs.org/docs/google/ -router.get('auth/google', GoogleRoutes.authenticate()); -router.get('auth/google/callback', GoogleRoutes.callback()); - -module.exports = router;