@shopify/slate-env
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
@@ -17,2 +17,3 @@ /* eslint-disable no-process-env */ | ||
[config.envIgnoreFilesVar]: 'config/settings_data.json', | ||
[config.envUserEmail]: 'test@email.com', | ||
}; | ||
@@ -38,3 +39,3 @@ | ||
clearVars(TEST_ENV); | ||
glob.sync(`${envPath}*`).forEach(file => fs.unlinkSync(file)); | ||
glob.sync(`${envPath}*`).forEach((file) => fs.unlinkSync(file)); | ||
}); | ||
@@ -69,13 +70,26 @@ | ||
describe('getDefaultSlateEnv', () => { | ||
test('returns an object which contains the default variables and values of an env file', () => { | ||
const emptyTestVars = { | ||
[config.envStoreVar]: '', | ||
[config.envPasswordVar]: '', | ||
[config.envThemeIdVar]: '', | ||
[config.envIgnoreFilesVar]: '', | ||
}; | ||
expect(slateEnv.getDefaultSlateEnv()).toEqual(emptyTestVars); | ||
}); | ||
}); | ||
describe('getEmptySlateEnv()', () => { | ||
test('returns object containing all env file variables with empty values', () => { | ||
const EMPTY_TEST_VARS = Object.assign({}, TEST_ENV); | ||
const emptyTestVars = Object.assign({}, TEST_ENV); | ||
for (const key in EMPTY_TEST_VARS) { | ||
if (EMPTY_TEST_VARS.hasOwnProperty(key)) { | ||
EMPTY_TEST_VARS[key] = ''; | ||
for (const key in emptyTestVars) { | ||
if (emptyTestVars.hasOwnProperty(key)) { | ||
emptyTestVars[key] = ''; | ||
} | ||
} | ||
expect(slateEnv.getEmptySlateEnv()).toEqual(EMPTY_TEST_VARS); | ||
expect(slateEnv.getEmptySlateEnv()).toEqual(emptyTestVars); | ||
}); | ||
@@ -291,3 +305,3 @@ }); | ||
['shop1.myshopify.com', 'shop1.myshopify.io', 'shop1'].forEach( | ||
value => { | ||
(value) => { | ||
setVars( | ||
@@ -294,0 +308,0 @@ Object.assign({}, TEST_ENV, { |
58
index.js
@@ -14,15 +14,14 @@ /* eslint-disable no-process-env */ | ||
config.envIgnoreFilesVar, | ||
config.envUserEmail, | ||
]; | ||
const SLATE_ENV_VARS_DESCRIPTIONS = { | ||
[config.envStoreVar]: "The myshopify.com URL to your Shopify store", | ||
[config.envPasswordVar]: "The API password generated from a Private App", | ||
[config.envThemeIdVar]: "The ID of the theme you wish to upload files too", | ||
[config.envIgnoreFilesVar]: "A list of file patterns to ignore, with each list item seperated by ':'" | ||
} | ||
const DEFAULT_ENV_VARS = [ | ||
config.envStoreVar, | ||
config.envPasswordVar, | ||
config.envThemeIdVar, | ||
config.envIgnoreFilesVar, | ||
]; | ||
// Creates a new env file with optional name and values | ||
function create({ values, name, root } = {}) { | ||
function create({values, name, root} = {}) { | ||
const envName = _getFileName(name); | ||
@@ -46,6 +45,4 @@ const envPath = path.resolve(root || config.envRootDir, envName); | ||
function _getFileContents(values) { | ||
const env = getEmptySlateEnv(); | ||
const env = getDefaultSlateEnv(); | ||
delete env[config.envNameVar]; | ||
for (const key in values) { | ||
@@ -58,4 +55,3 @@ if (values.hasOwnProperty(key) && env.hasOwnProperty(key)) { | ||
return Object.entries(env) | ||
.map(keyValues => { | ||
let descriptionKey = ''; | ||
.map((keyValues) => { | ||
const envVar = keyValues[0]; | ||
@@ -70,6 +66,10 @@ | ||
// comment. | ||
const schemaItem = config.__schema.items.find(item => item.id === key); | ||
const schemaItem = config.__schema.items.find( | ||
(item) => item.id === key, | ||
); | ||
return `# ${schemaItem.description || ''} \r\n${keyValues.join('=')}`; | ||
} | ||
} | ||
return true; | ||
}) | ||
@@ -83,3 +83,3 @@ .join('\r\n\r\n'); | ||
const envPath = path.resolve(config.envRootDir, envFileName); | ||
const result = dotenv.config({ path: envPath }); | ||
const result = dotenv.config({path: envPath}); | ||
@@ -168,3 +168,3 @@ if (typeof name !== 'undefined' && result.error) { | ||
`${ | ||
config.envThemeIdVar | ||
config.envThemeIdVar | ||
} can be set to 'live' or a valid theme ID containing only numbers`, | ||
@@ -180,4 +180,3 @@ ), | ||
function clear() { | ||
const env = getEmptySlateEnv(); | ||
SLATE_ENV_VARS.forEach(key => process.env[key] = ''); | ||
SLATE_ENV_VARS.forEach((key) => (process.env[key] = '')); | ||
} | ||
@@ -189,3 +188,3 @@ | ||
SLATE_ENV_VARS.forEach(key => { | ||
SLATE_ENV_VARS.forEach((key) => { | ||
env[key] = process.env[key]; | ||
@@ -201,3 +200,3 @@ }); | ||
SLATE_ENV_VARS.forEach(key => { | ||
SLATE_ENV_VARS.forEach((key) => { | ||
env[key] = ''; | ||
@@ -209,2 +208,12 @@ }); | ||
function getDefaultSlateEnv() { | ||
const env = {}; | ||
DEFAULT_ENV_VARS.forEach((key) => { | ||
env[key] = ''; | ||
}); | ||
return env; | ||
} | ||
function getEnvNameValue() { | ||
@@ -235,2 +244,7 @@ return process.env[config.envNameVar]; | ||
function getUserEmail() { | ||
const value = process.env[config.envUserEmail]; | ||
return typeof value === 'undefined' ? '' : value; | ||
} | ||
module.exports = { | ||
@@ -242,2 +256,3 @@ create, | ||
getSlateEnv, | ||
getDefaultSlateEnv, | ||
getEmptySlateEnv, | ||
@@ -249,2 +264,3 @@ getEnvNameValue, | ||
getIgnoreFilesValue, | ||
getUserEmail, | ||
}; |
{ | ||
"name": "@shopify/slate-env", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "Manages the environment variables which are needed by Slate to interact with Shopify servers.", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@shopify/slate-config": "^1.0.0-beta.1", | ||
"@shopify/slate-config": "1.0.0-beta.2", | ||
"dotenv": "^4.0.0" | ||
@@ -17,0 +17,0 @@ }, |
@@ -27,3 +27,3 @@ # @shopify/slate-env | ||
# A list of file patterns to ignore, with each list item seperated by ':' | ||
# A list of file patterns to ignore, with each list item separated by ':' | ||
SLATE_IGNORE_FILES= | ||
@@ -42,6 +42,6 @@ ``` | ||
\_**warning:** some commands ([`start`](https://github.com/Shopify/slate-cli#start), [`deploy`](https://github.com/Shopify/slate-cli#deploy)) will overwrite the existing code on this `SLATE_THEME_ID` with your local project's content. | ||
To avoid losing work, we suggest you go to [/admin/themes](https://my-store.myshopify.com/admin/themes) and duplicate | ||
To avoid losing work, we suggest you go to [/admin/themes](//www.shopify.com/admin/themes) and duplicate | ||
an existing theme to work from. | ||
Go to your store's [/admin/themes.xml](https://my-store.myshopify.com/admin/themes.xml), | ||
Go to your store's [/admin/themes.xml](//www.shopify.com/admin/themes.xml), | ||
and copy the `id` for the theme you would like to update: | ||
@@ -57,3 +57,3 @@ | ||
Navigate to your store's private apps page ([/admin/apps/private](https://my-store.myshopify.com/admin/apps/private)). | ||
Navigate to your store's private apps page ([/admin/apps/private](//www.shopify.com/admin/apps/private)). | ||
@@ -60,0 +60,0 @@ ![https://screenshot.click/17-06-j9e9m-n2jxa.png](https://screenshot.click/17-06-j9e9m-n2jxa.png) |
@@ -59,6 +59,12 @@ const slateConfig = require('@shopify/slate-config'); | ||
description: | ||
"A list of file patterns to ignore, with each list item seperated by ':'", | ||
"A list of file patterns to ignore, with each list item separated by ':'", | ||
type: 'string', | ||
}, | ||
{ | ||
id: 'envUserEmail', | ||
default: 'SLATE_USER_EMAIL', | ||
description: 'The email of the user to register for Slate analytics', | ||
type: 'string', | ||
}, | ||
], | ||
}); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
22289
575
23
+ Added@shopify/slate-config@1.0.0-beta.2(transitive)
- Removed@shopify/slate-config@1.0.0-beta.14(transitive)